Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I have a example and I'm course how approach this problem. Logically how would approach this problem. ? Exercise 04 Write a class, called ShoppingList,

I have a example and I'm course how approach this problem. Logically how would approach this problem.

?

image text in transcribed
Exercise 04 Write a class, called ShoppingList, which encapsulates a shopping list. The attributes for this class are: the owner's name String an array of items, list String - size TBD an integer, count int - to keep track of the # of items on the list The constructor should take a String and an int as the parameters this is the person's name and the maximum size of the list. Use the max size to instantiate the list (new String [size] ). count should be set to 0. In addition to the constructor, there should be an accessor for the size {list . length], for the count of items on the list, and for the list owner's name. There should also be a method public void addI tern (String item) which adds one item to the list. This should also increment the count. If the count is == size when addI tem is called, the list is full. Print an error message and terminate the program. Finally, we need a public String toString() method that returns a string with all of the items on the list, one per line. Use the same technique used with toString for MonthlyRain, above. Also, write a class, TestList, that tests this shopping list out. Have TestList manage a dialog with the user, such as: Enter your name: Martha Enter an icem for the list: Tomatoes Enter an icem for the list: Bread Enter an item for the list: Milk Enter an i:em for the list: Martha's shopping list is: Tomatoes Bread Milk In the above, the usel's input is represented in hold to differentiate it from the program's output. When the name (Martha) is read in, the ShoppingList is instantiated. Use 10 as the maximum size of the list. Also, the sentinel for "no more items\" is an item that is the empty string {just press Enter when prompted for an item for the list]. This is a String, read in with the nextLine {) method of the Scanner. Test for it to be equal to the empty string with if (item. equals ("")) { // remember, do NOT use =2 with Strings where 'item' is the String that was read in. Remember, do NOT use '==' with Strings

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_2

Step: 3

blur-text-image_3

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

Financial management theory and practice

Authors: Eugene F. Brigham and Michael C. Ehrhardt

12th Edition

978-0030243998, 30243998, 324422695, 978-0324422696

Students also viewed these Programming questions

Question

On what date was the declaration of independence signed?

Answered: 1 week ago

Question

What achievement is Amelia ear heart best known for?

Answered: 1 week ago

Question

The structure of liberty was a gift from what European country?

Answered: 1 week ago

Question

What was the first US state admitted to the union?

Answered: 1 week ago

Question

What was the last currency to be used in the US before the dollar?

Answered: 1 week ago