Advertisement
Kawsar_Hossain

UML109

Feb 22nd, 2020
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.51 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,int a)
  15.     {
  16.        
  17.         System.out.println("Sticker ID: "+a);
  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.     public int getSID()
  33.     {
  34.         return sID;
  35.     }
  36. }
  37.  
  38.  
  39. public class Apple extends Fruit {
  40.     private static double price;
  41.     private static int pYear;
  42.     private static int quantity;
  43.      Sticker o2;
  44.     public Apple(double pr,int py,int quan)
  45.     {
  46.         super("Green",3);
  47.         price=pr;
  48.         pYear=py;
  49.         quantity=quan;
  50.     }
  51.     public void eat()
  52.     {
  53.         System.out.println("Eat fresh fruits");
  54.     }
  55.     public void clean()
  56.     {
  57.         System.out.println("Wash your fruit before you eat");
  58.     }
  59.     public static void main(String[] args) {
  60.         Apple o1 = new Apple(410.50,2020,2);
  61.         Sticker o2 = new Sticker(150);
  62.         int a=o2.getSID();
  63.         o1.buyFruit(price);
  64.         o1.checkFruit(pYear,quantity,a);
  65.         o1.clean();
  66.         o1.eat();
  67.        
  68.     }
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement