brainfrz

Untitled

Mar 10th, 2016
264
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.92 KB | None | 0 0
  1. public class PezDispenser {
  2.     public static void main(String[] args) {
  3.         Stack dispenser = new Stack();
  4.         Candy[] candies = new Candy[15];
  5.        
  6.         candies = buyCandy();
  7.        
  8.         for (Candy piece : candies) {
  9.             dispenser.push(piece);
  10.         }
  11.        
  12.         System.out.println("You've filled your PEZ dispenser!");
  13.        
  14.         for (Candy piece : candies) {
  15.             dispenser.pop();
  16.         }
  17.         //This is the same as:
  18.         /*
  19.         for (int i = 0; i < candies.length; i++) {
  20.             dispenser.pop();
  21.         }
  22.         */
  23.        
  24.         System.out.println("You've now eaten all your candies! Don't you feel sick?");
  25.     }
  26.    
  27.     private static Candy[] buyCandy() {
  28.         Candy[] candies = new Candy[15];
  29.        
  30.         /* Snippet of code that "buys" 15 pieces of candy (setting the array) */
  31.        
  32.         return candies;
  33.     }
  34. }
Advertisement
Add Comment
Please, Sign In to add comment