Advertisement
Guest User

Main class

a guest
Mar 29th, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.29 KB | None | 0 0
  1. public class HotDogStand
  2. {
  3. // Add a static variable that tracks the total number of hot dogs sold by all hot dog stands and a static method that returns the value in this variable.
  4. private static int totalSold = 0;
  5.  
  6. public static int getTotalSold()
  7. {
  8. return totalSold;
  9. }
  10.  
  11. // *Name of each hot dog stand
  12. private String name;
  13. // *Stand's ID number
  14. private int id;
  15. // *How many hot dogs the stand has sold that day.
  16. private int numSold;
  17.  
  18. // Create a constructor that allows a user of the class to initialize values.
  19. public HotDogStand(String name, int id)
  20. {
  21. this.name = name;
  22. this.id = id;
  23. }
  24.  
  25. //Also create a method named SetJustSold()(Hint ++) that increments the number of hot dogs the stand has sold by one and should also increase the TotalSold by one.
  26. public void justSold()
  27. {
  28. numSold++;
  29. totalSold++;
  30. }
  31.  
  32. // Add another method that returns the number of hot dogs sold.
  33. public int getNumSoldToday()
  34. {
  35. return numSold;
  36. }
  37.  
  38.  
  39. public int getID()
  40. {
  41. return id;
  42. }
  43.  
  44.  
  45. public String getName()
  46. {
  47. return name;
  48. }
  49.  
  50. // Create a toString() method and a copy constructor.
  51. public String toString()
  52. {
  53. return name+" ("+id+") - "+numSold;
  54. }
  55.  
  56. public HotDogStand(HotDogStand rhs)
  57. {
  58. id = rhs.id;
  59. name = ""+rhs.name;
  60. numSold = rhs.numSold;
  61. }
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement