Java Programming Worksheet Essay Paper
1) Book Class
Write a class named Book that has fields to hold the following data:
Title
Author
Year published
ISBN number
In the Book class, also include
A mutator method for each field to set the value for the field
An accessor method for each field to get the value for the field
Write a separate demo program that Utilizies the class by creating three instances of the class.
2) ShoppingCartItem class
Write a class named ShoppingCartItem that has fields to hold the following data:
Name
Quantity
Price
In the ShoppingCartItem class, also include
A constructor that accepts arguments for the name and ID number and assigns them to their respective fields. Initialize the quantity and price fields as well.
A mutator method for each field to set the value for the field
An accessor method for each field to get the value for the field
A method that returns the total price of the item calculated as quantity times price
Write a separate demo program that Utilizies the class bycreating a ShoppingCartItem object and asking the user to enter the data for each of the objects fields.
The program should display the total price at the end with a label.
3) GroceryItem Class
Write a class named GroceryItem that holds data on an item in a grocery store. Include the following fields:
description – a String that holds the description of the item
brand – a String that holds the brand of the item
inventory – an int that holds the number of units in the inventory
price – a double that holds the items price
Also implement:
A constructor that accepts an argument for each field and assigns them to their respective fields
A default constructor that set the description to an empty string ( ), inventory to 0, and price to 0.0
A mutator method for each field to set the value for the field
An accessor method for each field to get the value for the field
Once the class is complete, Write a separate demo program that utilizes the GroceryItem class.
The program should create two GroceryItem objects with the following data:
Description
Inventory
Price
Item