Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- import java.util.InputMismatchException;
- public class Gadget
- {
- private int itemNumber;
- private String description;
- private double price;
- private Scanner input = new Scanner(System.in);
- //A single Gadget created by the company that contains
- //1.item number, integer
- //2.Description, string
- //3.a price, double positive
- //must be set by a constructor
- //all methods are read only
- public Gadget()throws InputMismatchException, NumberFormatException
- {
- boolean good=true;
- System.out.println("What is the Item Number?");
- while (good)
- {
- try
- {
- good = true;
- itemNumber= Integer.parseInt(input.nextLine());
- }
- catch(NumberFormatException ex)
- {
- good = false;
- System.out.println(ex.getMessage()+" -The following value must be an integer-");
- }
- }
- description = input.nextLine();
- price = Double.parseDouble(input.nextLine());
- }
- public int getItemNumber()
- {
- return itemNumber;
- }
- public String getDescription()
- {
- return description;
- }
- public double getPrice()
- {
- return price;
- }
- }
Add Comment
Please, Sign In to add comment