Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

How Do I Use A Database Research Tools You Can Use

Authors: Laura La Bella

1st Edition

1622753763, 978-1622753765

More Books

Students also viewed these Databases questions