Guest User

Untitled

a guest
Jul 17th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.12 KB | None | 0 0
  1. import java.util.Scanner;
  2. import java.util.InputMismatchException;
  3.  
  4. public class Gadget
  5. {
  6. private int itemNumber;
  7. private String description;
  8. private double price;
  9. private Scanner input = new Scanner(System.in);
  10. //A single Gadget created by the company that contains
  11. //1.item number, integer
  12. //2.Description, string
  13. //3.a price, double positive
  14. //must be set by a constructor
  15. //all methods are read only
  16.  
  17. public Gadget()throws InputMismatchException, NumberFormatException
  18. {
  19. boolean good=true;
  20. System.out.println("What is the Item Number?");
  21. while (good)
  22. {
  23. try
  24. {
  25. good = true;
  26. itemNumber= Integer.parseInt(input.nextLine());
  27.  
  28. }
  29. catch(NumberFormatException ex)
  30. {
  31. good = false;
  32. System.out.println(ex.getMessage()+" -The following value must be an integer-");
  33.  
  34. }
  35. }
  36. description = input.nextLine();
  37.  
  38. price = Double.parseDouble(input.nextLine());
  39. }
  40.  
  41.  
  42. public int getItemNumber()
  43. {
  44. return itemNumber;
  45. }
  46. public String getDescription()
  47. {
  48. return description;
  49. }
  50. public double getPrice()
  51. {
  52. return price;
  53. }
  54.  
  55. }
Add Comment
Please, Sign In to add comment