Note that there are some explanatory texts on larger screens.

plurals
  1. POHow would I save items in my class with description and price? Or how would I go about it? with the addItem method?
    text
    copied!<p>all of the methods where blank, my hw told to follow the comments and fill them in. Just having trouble putting the array items and description together.</p> <pre><code>public class CashRegisterItemList { private ArrayList&lt;Item&gt; items = new ArrayList&lt;Item&gt;(); private double taxRate; /** * Constructs a cash register with with no items. * Sets the tax rate to the default of 7.25%. * */ public CashRegisterItemList() { items=0; double taxRate= 7.25; } /** * Constructs a cash register with no items. * Sets the tax rate to the given tax rate. * @param taxRate tax rate for taxable items */ public CashRegisterItemList(double taxRate) { items= 0; double taxRate= taxRate; } /** * Adds an item to this cash register. * @param description the description of this item * @param price the price of this item * @param isTaxable the taxability of this item */ public void addItem(String description, double price, boolean isTaxable) { itemCount++; totalPrice = totalPrice + price; if(description isTaxable) totalTax = price*taxRate; } /** * Gets the total price of all items in the current sale, * not including the tax. * @return the total amount */ public double getTotal() { return totalPrice; } /** * Gets the total tax of all the taxable items in the current sale, * @return the total tax */ public double getTotalTax() { return totalTax; } /** * Gets the number of items in the current sale. * @return the item count */ public int getCount() { return items; } /** * Removes all items from current sale */ public void clear() { int items= 0; } /** * Prints a receipt, in the form shown on the assignment page. */ public void printReceipt() { for(int i=0; i&lt; items.length; i++){ if } } </code></pre> <p>Would create a separate variable to solely keep track of items? What do i do to make this work. this class is supposed to create the output of a cash register like </p> <pre><code>Cash Register 1 has 6 items Cash Register 1 total = 30.10 Cash Register 1 Receipt 6 items Bread 0.90 Paper 1.95 T Bananas 0.90 Milk 1.95 Turkey 21.50 Bowl + 2.90 T -------- 30.10 0.35T -------- 30.45 Cash Register 1 Receipt 6 items Bread 0.90 Paper 1.95 T Bananas 0.90 Milk 1.95 Turkey 21.50 Bowl + After clearing Cash Register 1 0 items -------- 0.00 0.00T -------- 0.00 </code></pre> <p>here is the item.java</p> <pre><code>public class Item { private String description; private double price; private boolean isTaxable; /** * Constructs an Item with a given description, price and taxability. * @param description the description of item * @param price the price of item * @param isTaxable whether the item is taxable or not */ public Item(String description, double price, boolean isTaxable) { this.description = description; this.price = price; this.isTaxable = isTaxable; } /** * Returns the description of the item. * @return the description of the item */ public String getDescription() { return description; } /** * Returns the price of the item. * @return the price of the item */ public double getPrice() { return price; } /** * Returns true if item is taxable, false otherwise * @return true if item is taxable, false otherwise */ public boolean isTaxable() { return isTaxable; } } </code></pre> <p>and the item tester </p> <pre><code>public class CashRegisterItemListTester { public static void main(String[] args) { CashRegisterItemList register1 = new CashRegisterItemList(); register1.addItem("Bread", 0.90, false); register1.addItem("Paper", 1.95, true); register1.addItem("Bananas", 0.90, false); register1.addItem("Milk", 1.95, false); register1.addItem("Turkey", 21.50, false); register1.addItem("Bowl", 2.90, true); System.out.printf("Cash Register 1 has %d items\n", register1.getCount()); System.out.printf("Cash Register 1 total = %.2f\n", register1.getTotal()); System.out.println(); System.out.println("Cash Register 1 Receipt"); register1.printReceipt(); register1 = new CashRegisterItemList(0.085); register1.addItem("Bread", 0.90, false); register1.addItem("Paper", 1.95, true); register1.addItem("Bananas", 0.90, false); register1.addItem("Milk", 1.95, false); register1.addItem("Turkey", 21.50, false); register1.addItem("Bowl", 2.90, true); System.out.println(); System.out.println("Cash Register 1 Receipt"); register1.printReceipt(); register1.clear(); System.out.println("\nAfter clearing"); System.out.println("Cash Register 1"); register1.printReceipt(); } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload