Question
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
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started