Advertisement
AlphaPenguino

itlog

Mar 9th, 2023 (edited)
201
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.58 KB | None | 0 0
  1.  
  2. public class egg {
  3.    
  4.     String color;
  5.     int quantity;
  6.     String size;
  7.     int picked;
  8.    
  9.     public egg(String color, int quantity, String size) {
  10.         this.color = color;
  11.         this.quantity = quantity;
  12.         this.size = size;
  13.  
  14.     }
  15.     void showEgg() {
  16.         System.out.println("You have " + picked + " " + color + " eggs picked!");
  17.     }
  18.     void getEgg() {
  19.         if (quantity>0) {
  20.            quantity = quantity - 1;
  21.         System.out.println("You picked 1 " + color + " egg!, only " + quantity + " are remaining!");
  22.         picked++;  
  23.         }
  24.         else {
  25.             System.out.println("You've ran out of eggs!");
  26.         }
  27.     }
  28.     void crack() {
  29.         System.out.println("You crack the " + picked + " " + this.size + " sized " + color + " " + "egg(s)!");
  30.     }
  31.     void cook() {
  32.         System.out.println("You cooked the " + picked + " " + this.size + " sized " + color + " " + "egg(s)!");
  33.     }
  34.     void eat() {
  35.         System.out.println("You ate the " + picked + " " + this.size + " sized " + color + " " + "egg(s)!");
  36.     }
  37.    
  38.    
  39.    public static void main(String[] args) {
  40.     egg itlog1 = new egg("white", 12, "small");
  41.     egg itlog2 = new egg("brown", 25, "large");
  42.    
  43.     System.out.println(itlog1.quantity);
  44.    
  45.     itlog1.getEgg();
  46.     itlog1.getEgg();
  47.     itlog2.getEgg();
  48.     itlog2.getEgg();
  49.     itlog1.getEgg();
  50.     itlog2.getEgg();
  51.     itlog2.getEgg();
  52.    
  53.     itlog1.showEgg();
  54.    
  55.     itlog1.doThis();
  56.    
  57. }
  58. public void doThis() {
  59.         crack();
  60.         cook();
  61.         eat();
  62.        
  63. }
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement