12.0k views
2 votes
Rearrange the following lines of code to construct a cash register, process a sale of three items under $10, print the count, and then the total. Then process another sale of two items over $10 in the same way.

public class RegisterDemo {
public static void main(String[] args) {
CashRegister regi = new CashRegister();

regi.addItem(5.95);
regi.addItem(1.95);
regi.addItem(12.95);

System.out.println(regi.getCount());
System.out.println(regi.getTotal());

regi.clear(); // Assuming regi.clear() is part of the CashRegister class

regi.addItem(19.95);
regi.addItem(2.95);

System.out.println(regi.getCount());
System.out.println(regi.getTotal());
}
}

User Evan Sharp
by
7.4k points

1 Answer

5 votes

Final answer:

To construct a cash register and process sales of items, you can rearrange the given lines of code in a specific order. By following the correct arrangement, you will be able to add items to the register, print the count and total for a sale, and then clear the register for the next sale.

Step-by-step explanation:

The given lines of code need to be rearranged in order to construct a cash register and process sales of items. Here is the correct arrangement:

  1. Create an instance of the CashRegister class: CashRegister regi = new CashRegister();
  2. Add the items to the register: regi.addItem(5.95); regi.addItem(1.95); regi.addItem(12.95);
  3. Print the count of items: System.out.println(regi.getCount());
  4. Print the total cost: System.out.println(regi.getTotal());
  5. Clear the register: regi.clear();
  6. Add new items to the register: regi.addItem(19.95); regi.addItem(2.95);
  7. Print the new count of items: System.out.println(regi.getCount());
  8. Print the new total cost: System.out.println(regi.getTotal());

By following this order, you will be able to construct a cash register, process two sales, and print the count and total cost for each sale.

User Kisha
by
8.3k points

No related questions found