import java.util.Scanner; import java.util.InputMismatchException; /** In this Item class, we'll have a default constructor that * asks the user to enter a name and a price. If there is an * input format error, we handle the exception in the * place where the constructor is called. */ public class Item { private String name; private double price; /** Default constructor: ask user for input. * Note that we simply "declare" the exception, rather than handle it. */ public Item() throws InputMismatchException { Scanner kbd = new Scanner(System.in); System.out.printf("Please enter a name and price: "); name = kbd.next(); price = kbd.nextDouble(); } public String toString() { return name + " $ " + price; } }