1. Engineering
  2. Computer Science
  3. complete the cashregister class by implementing the methods and adding...

Question: complete the cashregister class by implementing the methods and adding...

Question details

Complete the CashRegister class by implementing the methods and adding the correct attributes (characteristics) as discussed in class. Once complete, test the class using the CashRegisterTester class. Make sure you have 3 total items in the cash register.

I have two classes, the first is CashRegisterTester below:

public class CashRegisterTester

{

public static void main(String[] args)

{

//Initialize all variables

//Construct a CashRegister object

CashRegister register1 = new CashRegister();

//Invole a non-static method of the object

//since it is non-static, you must have an object

register1.addItem(1.95);

register1.addItem(2.00);

register1.addItem(2.05);

System.out.println(register1.getCount());

System.out.printf("%.2f\n", register1.getTotal());

}//main

//

}

The second class is CashRegister, which is what needs to be edited, here is the code that I have

/**

* CashRegister - A stimulated cash register that tracks the item count and the total amount due

*

* @author rhiannondore

*

*Start with the user interface

*What tasks will this class perform?

*What methods will you need?

*What parameters will the methods need to receive?

*What will the methods return?

*Task - Method - Return - Data Needed

*

*

*

* Add the price of an item - addItem(double) - void - total, count

* Get the total amount owed - getTotal() - double - total

* Get the count of items purchased - getCount() - int - count

* Clear the cash register for a new sale - clear() - void - total, count

*/

public class CashRegister

{

/**

* Constructs a cash register with cleared item count and total

*/

public CashRegister() // A constructor

{ //declare variables

int itemCount = 0;

int totalPrice = 0;

}//default

/**

* Method addItem: Adds an item to this cash register.

* @param price: the price of this item

* @return none

*/

public void addItem(double price) //price is an explicit parameter

{

int itemCount;

//method body

itemCount++;

double totalPrice = totalPrice + price;

}//addItem

/**

* Method getTotal() - Gets the price of all items in the current

* @return the total price

*/

public double getTotal()

{

return 0.0;

}//getTotal

}//class CashRegister

}

Solution by an expert tutor
Blurred Solution
This question has been solved
Subscribe to see this solution