Question

Complete the CashRegister class by implementing the methods and adding the correct attributes (characteristics) as discussed...

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

}

0 0
Add a comment Improve this question Transcribed image text
Answer #1

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

*/

class CashRegister

{

/**

* Constructs a cash register with cleared item count and total

*/
//declare variables

int itemCount = 0;

double totalPrice = 0;

public CashRegister() // A constructor

{
itemCount = 0;
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

{

//method body

itemCount++;
totalPrice = totalPrice + price;

}//addItem

/**

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

* @return the total price

*/

public double getTotal()

{

return totalPrice;

}//getTotal

//class CashRegister


public int getCount()
{

return itemCount;
}
}

output:

run:
3
6.00
BUILD SUCCESSFUL (total time: 2 seconds)

Add a comment
Know the answer?
Add Answer to:
Complete the CashRegister class by implementing the methods and adding the correct attributes (characteristics) as discussed...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • in java PART ONE ======================================= Below is the "RetailItem" class definition that we used in Chapter 6. Write a "CashRegister" class that leverages this "Ret...

    in java PART ONE ======================================= Below is the "RetailItem" class definition that we used in Chapter 6. Write a "CashRegister" class that leverages this "RetailItem" class which simulates the sale of a retail item. It should have a constructor that accepts a "RetailItem" object as an argument. The constructor should also accept an integer that represents the quantity of items being purchased. Your class should have these methods: getSubtotal: returns the subtotal of the sale, which is quantity times price....

  • In C++ Write a header cashRegister.h and source cashRegister.cpp files for the a CashRegister class. The...

    In C++ Write a header cashRegister.h and source cashRegister.cpp files for the a CashRegister class. The class a CashRegister class has the following data members: 1) an array of 100 Item objects. 2) Cash Register Name and 3) Count of Item objects purchased. 4) Item Cash Total 5) State Tax Rate. The Item is represented as a class in an item.h file. The Item class has the following data members: 1) Name of the item 2) Cost of the item....

  • The following class StatCalc defines a series of methods for computing statistics for a group of...

    The following class StatCalc defines a series of methods for computing statistics for a group of numbers. /* * An object of class StatCalc can be used to compute several simple statistics * for a set of numbers. Numbers are entered into the dataset using * the enter(double) method. Methods are provided to return the following * statistics for the set of numbers that have been entered: The number * of items, the sum of the items, the average, and...

  • The following class StatCalc defines a series of methods for computing statistics for a group of...

    The following class StatCalc defines a series of methods for computing statistics for a group of numbers. /* * An object of class StatCalc can be used to compute several simple statistics * for a set of numbers. Numbers are entered into the dataset using * the enter(double) method. Methods are provided to return the following * statistics for the set of numbers that have been entered: The number * of items, the sum of the items, the average, and...

  • According to this cord use LongFifoWait Notify thread methord in CircularArrayLongFifo class. According to this cord...

    According to this cord use LongFifoWait Notify thread methord in CircularArrayLongFifo class. According to this cord use LongFifoWait Notify thread methord in CircularArrayLongFifo class. public class CandidateGenerator { private final LongFifo outputFifo; public CandidateGenerator(LongFifo outputFifo) { this.outputFifo = outputFifo; Runnable r = new Runnable() { @Override public void run() { runWork();}}; Thread t = new Thread(r, "CandidateGenerator"); t.start() } private void runWork() { try { outputFifo.add(2); long number = 3; while ( true ) { outputFifo.add(number); number += 2;} }...

  • Java 1. Write a getCount method in the IntArrayWorker class that returns the count of the...

    Java 1. Write a getCount method in the IntArrayWorker class that returns the count of the number of times a passed integer value is found in the matrix. There is already a method to test this in IntArrayWorkerTester. Just uncomment the method testGetCount() and the call to it in the main method of IntArrayWorkerTester. 2. Write a getLargest method in the IntArrayWorker class that returns the largest value in the matrix. There is already a method to test this in...

  • DESCRIPTION You have to design an e-commerce shopping cart. These require classes Item, Electronics, Food, Dress,...

    DESCRIPTION You have to design an e-commerce shopping cart. These require classes Item, Electronics, Food, Dress, Cart and Main. ITEM CLASS Your Item class should contain: Attributes (protected) String name - name of the Item double price - price of the item Methods (public) void setName(String n) - sets the name of Item void setPrice(double p) - sets the price of Item String getName() - retrieves name double getPrice() - retrieves price String formattedOutput() returns a string containing detail of...

  • Write a CashRegiste class that can be used with the Retntailtem class that you wrote in...

    Write a CashRegiste class that can be used with the Retntailtem class that you wrote in the module4. The cashRegister class should simulate the sale of a retail item. It should have a constructor that accepts a Retilltem objectject The constructor should also accept an integer that represents the quantity of item being purchased. In addition, the class should have the following properties and methods: as an argument. private final double TAX RATE private double retail; private int quantity; 0.06;...

  • Design a blueprint class that records the payment and purchase made in a CashRegister. (Write the...

    Design a blueprint class that records the payment and purchase made in a CashRegister. (Write the code for CashRegister - JAVA) The requirements are as follows: A) The class/object model will keep track of payments and purchases, both of which can be of type double. To do this, have the two instance variables called payment and purchase. B) The class/object model will provide the values of the payments and purchases to the client program. To do this, have proper getters...

  • (9 marks) Complete the following methods in the class MyLinkedList based the description provided. b. on...

    (9 marks) Complete the following methods in the class MyLinkedList based the description provided. b. on i. (3 marks) size() return the number of items in the list. i. (3 marks) count Positives (): return the number of positive values in the list ii. (3 marks) (Advanced) reverse the order of the items in reverse ( the list. If the list is 10 90, then after calling the - 70 - 20 -> method, it should become 90 - 70...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT