Advertisement
Mr_Linnenburger

vending1

Oct 12th, 2018
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.01 KB | None | 0 0
  1. public int vendingMachineOne(double money, double cost, boolean hasChips){
  2. //variable names and meanings
  3. //money: the amount of money the person enters into machine (positive value)
  4. //cost: how much the bag of chips cost
  5. //hasChips: boolean that is true if the vending machine has the chips
  6. //giveChips: true if the vending machine dispenses chips to the person
  7. //giveRefund: true if the vending machine returns any money to the person.
  8.  
  9.   boolean giveChips, giveRefund;    //declare the variables to assign
  10.  
  11. //WRITE YOUR CODE IN THE SPACE BELOW
  12. //-------------------------------------------------------------------  
  13.  
  14.  
  15.  
  16.  
  17. //-------------------------------------------------------------------
  18. //DO NOT CHANGE THE CODE BELOW THIS COMMENT
  19.  
  20.   if(giveChips){
  21.      if(giveRefund){ return 1; } //chips and refund
  22.      else { return 2; }          //chips and no refund
  23.   }
  24.   else{
  25.      if(giveRefund){ return 3; } //no chips and refund
  26.      else{ return 4; }           //no chips and no refund (will not happen)
  27.   }
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement