Create a class called CashRegister based on the information given (Create appropriate constructors, accessors and mutator methods). Then write a program that tests the class. Your driver program must do the required actions.

Provided with this assignment is the class definition for a class named RetailItem. I have provided the interface for this class. You MUST use the class I have provided and not create your own.

Q1 Create a class called CashRegister based on the information given below. Create appropriate constructors, accessors and mutator methods.

The class has the following attributes:
item – this is an object of the RetailItem class
qty – quantity of items being purchased and is an integer value
discRate – This is a double value and represents the discount rate this sale is eligible for. Assume that the user will enter the discount as a rate and not a percentage. That is, 5.25% will be entered as 0.0525
totalRegisterSales – This is a double value that represents the total sales for all CashRegister objects together.
Note that the last attribute will be a static variable while the first two will be instance variables.

In addition to the accessor and mutator methods, the class has the following additional methods: getSubTotal – returns the subtotal of the sale, which is the quantity times the retail price minus the discount amount. This method must get the retail price from the RetailItem object. Note that this method will be called by other methods within the class only.

getTax – returns the amount of sales tax on the purchase. The sales tax rate is 6% of a retail sale and should be stored as a named constant in your program. Note that this method will be called by other methods within the class only.
getTotal – returns the total of the sale, which is the subtotal plus sales tax.

toString - a methods that prints out the total of the sale together with the item description, item price, discount rate and number items purchased.

Finally write a program that tests the class. Your driver program must do the following:

  1. Allow the user to provide input (retail item description, retail item price, quantity, discount rate) for four CashRegister objects. 


  2. After each CashRegister object is created, the program must print the CashRegister object dataandalsodisplaythetotalRegistarSalesvalue. Donotworryaboutcurrency formatting. 


  •   Submit a zipped folder containing ONLY the .java files for this assignment. The zip file should be named using your name and the chars “hw3”. You will be penalized 15% of the grade if your submission does not follow these requirements.

  •   You will get zero points if your program does not compile.

  •   Submit a zipped folder containing ONLY the .java files for this assignment. The zip file should be named using your name and the chars “hw3.

  •   Make sure that your program executes and compiles correctly before submission.

  •   If you used an IDE to write your programs, check to ensure that your program compiles as an independent program using a text editor, before submitting

  • You will get zero points if your program does not compile. DO NOT write your own RetailItem.java. Just put the RetailItem.class file that I have provided in the same folder as the CashRegister.java as well as your driver file.

An example similar to this homework is enclosed with this

document. Studying that example will give you some idea

about how best to deal with this assignment. Also refer to

the video recording that is provided with this assignment

for additional help.

Here is a sample interaction with the driver program

Create a class called CashRegister based on the information given (Create appropriate constructors, accessors and mutator methods). Then write a program that tests the class. Your driver program must do the required actions. 1


Your program should exhibit all the functionality shown in the sample interaction

Additional Help / Instructions

1. Write a class definition for the class called CashRegister. should be as follows:

The class definition

  1. The instance variables and the static variable as described above. 


  2. A constructor method 


  3. Accessor and mutator methods for the instance variables. 


  4. The four additional methods as specified above. In addition, you may write 
other methods as needed by you to complete the assignment 


  1. You SHOULD NOT write a class definition for the RetailItem class. The text 
document that is given to you gives you details (i.e., the return type of the method and the parameter list of the method) of all the methods in the RetailItem class. This information is enough for you to know how to call/invoke each method in the RetailItem class. For example, to call the RetailItem() constructor, you need to provide one String value and one double value as input to the constructor call. 


  2. Write a tester/driver class to test out your application. This program will contain a main method. Look at the sample output to see the flow of execution. This will help you the details of the driver program. 


  3. Once the CashRegister.java and the driver class .java are written, put the files together with the RetailItem.class (note the .class extension) file in the same folder. You are now ready to compile and test your program. 


  4. The role of LibraryDemo is similar to the driver class you will need to write. The LibraryBook's role is similar to the CashRegister class and the Author class's role is similar to the RetailItem class. 


  5. The structure of how the three different classes in your homework will work together is therefore exactly like how the three classes in the Library app will work together. 


Homework Three

Checklist for Grading

Category

Description

Points You Got

Total Points

Question 1

 

 

 

 

Program compiles

10

 

For each cash register that is created, the program asks for and accepts the correct input

10

 

Both of the requirements in the assignment have been correctly implemented and the results are correct for each object that is created

80