Question: In java programming, create a viewer, population classes to add names to the array list and then see the names. For population class please use:

In java programming, create a viewer, population classes to add names to the array list and then see the names.

For population class please use:

private ArrayList people int order

public Population() (This constructor should create n array list of person and sets the private variable order by zero)

public addperson(person person):void

public increaseorder():void

public getorder():int

public getpersonbyorder(int order):person

public getpersonbyname(string name):person

public sortbyname():void

For viewer class please modify the code below:

import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPanel;

public class Viewer { private static final int FRAME_WIDTH = 500; private static final int FRAME_HEIGHT = 200; public void viewNames(Population population) { JFrame frame = new JFrame(); JButton button = new JButton("Show persons in the population"); final JLabel label = new JLabel("Person name: " + population.getOrder()); JPanel panel = new JPanel(); panel.add(button); panel.add(label); frame.add(panel); class IncreaseOrderOfPersonListener implements ActionListener { } ActionListener listener = new IncreaseOrderOfPersonListener(); button.addActionListener(listener); frame.setSize(FRAME_WIDTH, FRAME_HEIGHT); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true); } }

Sample output should be as follows:

Is there anyone to add? (Y/N)

Y

Enter the name

abcd

Is there anyone to add? (Y/N)

Y

Enter the name

efg

Is there anyone to add? (Y/N)

Y

Enter the name

asdf

Is there anyone to add? (Y/N)

N

show persons in the population(This is button) Person name:0

show persons in the population Person name:abcd

show persons in the population Person name:efg

show persons in the population Person name:asdf

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!