Question: Create a class Item which has - instance variables: itemName, itemCost - class variable: numberItems ( gets increased every time a new Item is created
Create a class Item which has
instance variables: itemName, itemCost
class variable: numberItems gets increased every time a new Item is created
a default constructor that allows the user to set itemName and itemCost
the default constructor sets itemName"apple" itemCost if the user does not specify them
function to show the item name and cost
function to get and set the item name and cost
Create a list named groceryBag to store the objects:
Fill the list with several Item's such as eggs, milk, carrots, bread, apples, each with different price.
use Item.numberItems to show how many items you have created.
use a loop to calculate and show the totalCost for all the items in the bag
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
