Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Read all the instructions carefully and write this program in java. I am a very begineer in java and i have just started learning of

Read all the instructions carefully and write this program in java. I am a very begineer in java and i have just started learning of creating my own classes.Please donot use break statements in this program and write comments so i can understand.

Lets assume that you are running a small candy store and would like to keep an inventory of items in your store. Each different item could be placed into your program as an individual object. For this lab I would like you to create a class called Item that contains the following:

instance variables/data members (make these private):

description (a String)

quantity (a integer)

price (a double)

Constructors (3):

One that has no parameters and sets description to Empty, quantity to

-1, and price to 0.0. (0 parameters)

One that sets description and price only, putting quantity to 0 (2

parameters)

One that sets all three items based on values sent in (3 parameters)

Accessors and Modifiers (6 total):

Make all three for each

Once the class is created make a program in another file that creates a five element array of Item objects. Fill the array up with the following: three Item objects using the third constructor (3 parameters): (You can do these one line at a time, loop is not required)

Chocolate Bars Gobstoppers Gummy Bears

qty 200 qty 350 qty 125

$1.00 $1.50 $1.99

Two more objects using the second constructor (2 parameters):

Lollipops Kinder Egg

$.50 $4.99

Using the modifier methods change the price of a Chocolate Bar to $1.25, and make the quantity of Lollipops to be 425 and Kinder Eggs to be 75. Change the name of Gummy Bears to be Gummy Worms. Do all of this using setters.

Then, using a loop and an output message, for every Item object output to the screen (in one line) all the values stored for that object (using accessor methods, NOT a toString method). For example: We have 200 Chocolate Bar(s) at a price of $1.25 each

What I should see when the program runs. (Wording/format may vary.)

We have 200 Chocolate Bar(s) at a price of $1.25 each.

We have 350 Gobstoppers(s) at a price of $1.50 each.

We have 125 Gummy Worm(s) at a price of $1.99 each.

We have 425 Lollipop(s) at a price of $.50 each.

We have 75 Kinder Eggs(s) at a price of $4.99 each.

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

Advances In Databases And Information Systems 22nd European Conference Adbis 2018 Budapest Hungary September 2 5 2018 Proceedings Lncs 11019

Authors: Andras Benczur ,Bernhard Thalheim ,Tomas Horvath

1st Edition

3319983970, 978-3319983974

More Books

Students also viewed these Databases questions

Question

Describe your ideal working day.

Answered: 1 week ago

Question

=+ Is secondary industrial action common and/or legal?

Answered: 1 week ago

Question

=+What sanctions are available to employers

Answered: 1 week ago

Question

=+ If strikes occur, are they legally regulated?

Answered: 1 week ago