/* Item.java for the shopping list class. * Here, we define what one item is, just a name and price. * But for the sake of the shopping list class, we need a way * to return the price of an item, and a string representation. */ public class Item { private String name; private double price; // constructor public Item(String name, double price) { this.name = name; this.price = price; } /* getPrice - since the shopping list needs to be able to * add up all the prices on the list, we need to provide each price. */ public double getPrice() { return price; } /* toString - an attractive way to format the information as text. * Let's make the width of the string 30 characters, and assume the * name is no more than 20 characters long. Don't put \n at end. */ public String toString() { return String.format("%-20s%10.2f", name, price); } }