fork(5) download
  1. import java.util.Scanner;
  2. public class CupDispenser
  3. {
  4. private String location;
  5. private int numberCups;
  6.  
  7. public CupDispenser()
  8. {
  9. location = "unknown";
  10. numberCups = 0;
  11. } //end default constructor
  12.  
  13. public CupDispenser(String theLocation,int theNumberCups)
  14. {
  15. location = theLocation;
  16. numberCups = theNumberCups;
  17. }//end constructors
  18.  
  19. // methods
  20. public int getNumberCups()
  21. {
  22. return numberCups;
  23. }
  24.  
  25. public void getOneCup()
  26. {
  27. numberCups = numberCups - 1;
  28. }
  29. public void takeCupsFrom(int numberCups) //CANT FIGURE THIS OUT!!!!
  30. {
  31. numberCups = numberCups + d1.getNumberCups();
  32. }
  33.  
  34. public String getLocation()
  35. {
  36. return location;
  37. }
  38.  
  39. public void setLocation(String theLocation)
  40. {
  41. location = theLocation;
  42. }
  43.  
  44. public String toString()
  45. {
  46. return "There are " + numberCups + " cups in the " + location + " cup dispenser.";
  47. }
  48.  
  49. } //end class
  50.  
  51.  
  52. public class CupDispenserDemo
  53. {
  54. public static void main(String[] args)
  55. {
  56. Scanner keyboard = new Scanner(System.in);
  57. System.out.println("What is the location of this cup dispenser? ");
  58. String location1 = keyboard.next();
  59.  
  60. CupDispenser d1 = new CupDispenser(location1,50);
  61.  
  62. System.out.println("Would you like to take one cup? Yes or no?");
  63. String input = keyboard.next ();
  64. char getOne = 'y';
  65. getOne = input.charAt(0);
  66.  
  67. if (getOne == 'Y' || getOne == 'y')
  68. {d1.getOneCup();}
  69.  
  70. System.out.println(d1.toString()); //end first dispenser
  71. System.out.print("\n");
  72.  
  73. int cd1 = 1;
  74. cd1 = d1.getNumberCups();
  75.  
  76. System.out.println("What is the location of the second cup dispenser? ");
  77. String location2 = keyboard.next();
  78.  
  79. CupDispenser d2 = new CupDispenser(location2, 50);
  80.  
  81. System.out.println("Would you like to take all the cups from the "+location1+ " cup dispenser "
  82. System.out.println("and put them into the "+location2+" cup dispenser? Yes or no?");
  83. String input2 = keyboard.next();
  84. char response = 'y';
  85. response = input2.charAt(0);
  86.  
  87. if (response == 'Y' || response 'y')
  88. {
  89. cd1.takeCupsFrom(d2);}
  90.  
  91. System.out.println(d2.toString());
  92.  
  93. }
  94. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
Main.java:81: error: ')' expected
      System.out.println("Would you like to take all the cups from the "+location1+ " cup dispenser "
                                                                                                     ^
Main.java:82: error: illegal start of expression
      System.out.println("and put them into the "+location2+" cup dispenser? Yes or no?");
            ^
Main.java:82: error: ';' expected
      System.out.println("and put them into the "+location2+" cup dispenser? Yes or no?");
                ^
Main.java:87: error: ')' expected
      if (response == 'Y' || response 'y')
                                     ^
Main.java:87: error: not a statement
      if (response == 'Y' || response 'y')
                                      ^
Main.java:87: error: ';' expected
      if (response == 'Y' || response 'y')
                                         ^
6 errors
stdout
Standard output is empty