Knowee
Questions
Features
Study Tools

/** A simulated cash register that tracks the item count and the total amount due.*/public class CashRegister{ // private data--see the "Designing the Data Representation" section /** Adds an item to this cash register. @param price the price of this item */ public void addItem(double price) { // implementation--see the "Implementing Instance Methods" section } /** Gets the price of all items in the current sale. @return the total amount */ public double getTotal() { // implementation--see the "Implementing Instance Methods" section } /** Gets the number of items in the current sale. @return the item count */ public int getCount() { // implementation--see the "Implementing Instance Methods" section } /** Clears the item count and the total. */ public void clear() { // implementation--see the "Implementing Instance Methods" section }}

Question

/** A simulated cash register that tracks the item count and the total amount due.*/public class CashRegister{ // private data--see the "Designing the Data Representation" section /** Adds an item to this cash register. @param price the price of this item / public void addItem(double price) { // implementation--see the "Implementing Instance Methods" section } /* Gets the price of all items in the current sale. @return the total amount / public double getTotal() { // implementation--see the "Implementing Instance Methods" section } /* Gets the number of items in the current sale. @return the item count / public int getCount() { // implementation--see the "Implementing Instance Methods" section } /* Clears the item count and the total. */ public void clear() { // implementation--see the "Implementing Instance Methods" section }}

...expand
🧐 Not the exact question you are looking for?Go ask a question

Solution

This is a Java class named CashRegister. It simulates a cash register that tracks the item count and the total amount due. The class has four methods:

  1. addItem(double price): This method is used to add an item to the cash register. The price of the item is passed as a parameter.

  2. getTotal(): This method is used to get the total price of all items in the current sale. It returns the total amount.

  3. getCount(): This method is used to get the number of items in the current sale. It returns the item count.

  4. clear(): This method is used to clear the item count and the total.

The actual implementation of these methods is not provided in the given code.

This problem has been solved

Similar Questions

write a java program to define a class Item having item namepricequantityfind the total cost of the itemuse accept method to get the data from the user and toString method to display the detailscreate two objects and display the name of the item which is ordered more quantitydisplay total amount of items purchased.edited 10:37 AM

In the last lesson, you created a class called DiscountedItem as part of a Shopping Cart application. Please copy your solutions from the last lesson into the Active Code window below (or in repl or another IDE) before completing this challenge.The ShoppingCart contains a polymorphic ArrayList called order that you can use to add Items or DiscountedItems to the shopping cart. The Item class keeps track of the name and the price of each Item. The DiscountedItem class you wrote in the last lesson adds on a discount amount.In this challenge, you will write a method called int countDiscountedItems() in the ShoppingCart class.This method will use a loop to traverse the ArrayList of Items called order.In the loop, you will test if each Item is a DiscountedItem by using the instanceof keyword (object instanceof Class returns true or false) similar to its use in the add(Item) method.If it is a DiscountedItem, then you will count it.At the end of the loop, the method will return the count.Make sure you print out the number of discounted items in the main method or in printOrder(), so that you can test your method. Add more items to the order to test it.Copy in your code for DiscountedItem below and then write a method called countDiscountedItems which traverses the polymorphic ArrayList<Item>. Use instanceof to test each item to see if it is a DiscountedItem.Save & Run2024/3/18 13:34:41 - 2 of 2Show CodeLensReformat1import java.util.*;2​3/**4 * The ShoppingCart class has an ArrayList of Items. You will write a new class5 * DiscountedItem that extends Item. This code is adapted6 * https://practiceit.cs.washington.edu/problem/view/bjp4/chapter9/e10-DiscountBill7 */8public class Tester9{10 public static void main(String[] args)11 {12 ShoppingCart cart = new ShoppingCart();13 cart.add(new Item("bread", 3.25));14 cart.add(new Item("milk", 2.50));15 // cart.add(new DiscountedItem("ice cream", 4.50, 1.50));16 // cart.add(new DiscountedItem("apples", 1.35, 0.25));17​18 cart.printOrder();19 }20}21​22class DiscountedItem extends Item23{24 // Copy your code from the last lesson's challenge here!25 // add an instance variable for the discount26 private double discount;27​28 // Add constructors that call the super constructor29 public DiscountedItem(String name, double price1, double discount1)30 {31 super(name,price1);32 discount = discount1;33 }34​35 // Add get/set methods for discount36 public double getDiscount()37 {38 return 9.5; // return discount here instead of 039 }40 public void setDiscount(double discountNew)41 {42 discount = discountNew;43 }44​45 // Add a toString() method that returns a call to the super toString46 public String toString()47 {48 return super.toString() + super.valueToString(discount); 49 }50 // and then the discount in parentheses using the super.valueToString() method51​52}53​54// Add a method called countDiscountedItems()55class ShoppingCart56{57 private ArrayList<Item> order;58 private double total;59 private double internalDiscount;60​61 public ShoppingCart()62 {63 order = new ArrayList<Item>();64 total = 0.0;65 internalDiscount = 0.0;66 }67​68 public void add(Item i)

Ramesh went to a general Store and picked two items of x and y prices.Write a java program to calculate the total amount for Ramesh to pay.Sample Test Case:Enter x value: 10Enter y value: 20Sum: 30Sample Test Cases

Dinesh is working in a supermarket and he is developing a program to calculate the cost of different types of items. Help him write the program that does the following:a) Create a base class, ItemType, with one virtual function double calculateAmount()b) Create a class called wooden that extends ItemType class with a number of items and cost as its private attributes. Obtain the data members and override the virtual function and calculate the total amount.c) Create a class called electronics that extends ItemType class with cost as its private attribute. Obtain the data member and override the virtual function and calculate the amount with 20% discount.Note: This question helps in clearing Infosys tests.Input format :The first line consists of an integer choice (1 or 2) representing the choice of item type.If the choice is 1 (wooden items), the next line consists of two space-separated integers: noOfItems and cost, representing the number of wooden items and their individual cost, respectively.If the choice is 2 (electronics), the next line consists of a single floating-point number cost, representing the cost of the electronic item.Output format :The output prints a floating-point number representing the calculated total cost of the chosen item type rounded off to two decimal places.Code constraints :10 < cost < 1060 < noOfItems < 20Sample test cases :Input 1 :15 840.5Output 1 :4202.50Input 2 :21800.56Output 2 :1440.45Note :

Write a program in Java using a method Discount( ), to calculate a single discount or a successive discount. Use overload methods Discount(int), Discount(int,int) and Discount(int,int,int) to calculate single discount and successive discount respectively. Calculate and display the amount to be paid by the customer after getting discounts on the printed price of an article.

1/2

Upgrade your grade with Knowee

Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.