Assignment #14

Instructions

  1. Write a Java application as described in assignment #12.
  2. For assignment #14, add the following code to assignment #12:
    1. In the GroceryItem.java file, write an amount() method definition, which multiplies the price by the count, and returns the result.
    2. You do NOT need to write an amount data field (instance variable). The amount() method call will call the amount() method definition, which will multiply price by count (price * count), and return the result.
    3. In the toString() method definition, call the amount() method, so that it displays the amount for each item.
      1. For example: display = ... + "\t\t" + count + "\t\t$" + this.amount() + ...
      2. "this" is a variable that stores a reference to the object. In other words, a variable that you can use to call the methods of the class, in the class definition.
    4. Change the name of the client program from LastNameFirstName12.java to LastNameFirstName14.java.
    5. In the LastNameFirstName14.java file, display the five items, including the amount.
    6. Add up and display the total, using the five grocery item variables and the amount() method to do this.
      1. For example: total = item1.amount() + item2.amount() + ...
      2. Where "item1", "item2", etc. are GroceryItem variables.

Example Output

item		price		count		amount
bananas		$0.99		22		$21.78
oranges		$2.99		4		$11.96
garlic		$3.99		8		$31.92
grapes		$9.99		2		$19.98
papayas		$4.99		6		$29.94

				        TOTAL: $115.58

Click to validate the HTML code

Click to validate the CSS code