Question: This can be done in one file. There is no need to create a utility and main class. Write a program that uses the ArrayList

This can be done in one file. There is no need to create a utility and main class.

Write a program that uses the ArrayList (covered in 11.11 page 432-chapter 11) class to store objects. Do NOT use static arrays that we used in earlier chapters. Write a program to store the full name (foo bar), the number of items a user wishes to purchase (say 10), and the unit cost of the item ($20). Were assuming that all items have the same cost. So, you dont need another array for the cost of each item.

a) Prompt the user to enter some data.

b) Create a new arraylist to hold the total cost of items purchased by a user. For example, using the above data, the total cost will be $200 (20 * 10) for the user.

c) Display the size of the arraylists. Make sure to be very descriptive in your output.

d) Ask the user to enter the name of a person and check if the person exists in the array list. Your search must be case insensitive. Display the message USER found, if the name is found in the list and display the users corresponding number of items purchased, the unit cost and the total cost. Otherwise, display USER NOT found. USER is the name of the person. So, if the input for name is Foo Bar, well display something like 10 20 200. If the input for name is joe, well display something like joe NOT found. Create a continuous loop that keeps asking the user for more names to search quitting when a sentinel value has been entered. e) Allow the user to add more names.

f) Allow the user to remove names. If the name to be removed cannot be found, display an error message.

g) Display the contents of the array lists using its toString method.

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!