Advertisement
Kawsar_Hossain

UML109

Feb 22nd, 2020
175
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.37 KB | None | 0 0
  1. public class Fruit {
  2.     private String color;
  3.     private double weight;
  4.     public Fruit(String c,double w)
  5.     {
  6.         color=c;
  7.         weight=w;
  8.     }
  9.     public void buyFruit(double p)
  10.     {
  11.         System.out.println("Price: "+p);
  12.         System.out.println("Weight: "+weight);
  13.     }
  14.     public void checkFruit(int py,int quan)
  15.     {
  16.        
  17.        
  18.         System.out.println("Color: "+color);
  19.         System.out.println("Production Year: "+py);
  20.         System.out.println("Quantity: "+quan);
  21.     }
  22. }
  23.  
  24. public class Sticker {
  25.     private int sID;
  26.     public Sticker(int s)
  27.     {
  28.        
  29.         sID=s;
  30.        
  31.     }
  32. }
  33.  
  34. public class Apple extends Fruit {
  35.     private static double price;
  36.     private static int pYear;
  37.     private static int quantity;
  38.     public Apple(double pr,int py,int quan)
  39.     {
  40.         super("Green",3);
  41.         price=pr;
  42.         pYear=py;
  43.         quantity=quan;
  44.     }
  45.     public void eat()
  46.     {
  47.         System.out.println("Eat fresh fruits");
  48.     }
  49.     public void clean()
  50.     {
  51.         System.out.println("Wash your fruit before you eat");
  52.     }
  53.     public static void main(String[] args) {
  54.         Apple o1 = new Apple(410.50,2020,2);
  55.         Sticker o2 = new Sticker(150);
  56.         o1.buyFruit(price);
  57.        
  58.         o1.checkFruit(pYear,quantity);
  59.         o1.clean();
  60.         o1.eat();
  61.        
  62.     }
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement