Advertisement
rafid_shad

Customer

Feb 13th, 2019 (edited)
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.43 KB | None | 0 0
  1. package ClassTheory;
  2.  
  3. import java.util.ArrayList;
  4.  
  5. public class Customer {
  6.    private String id,name;
  7.    private ArrayList<Iteam> iteamList=new ArrayList<>();
  8.    private Adress adress;
  9.    
  10.    public void setAdress(Adress ad){
  11.        this.adress=ad;
  12.    }
  13.    public void getAdress(){
  14.        adress.display();
  15.    }
  16.    
  17.    public Customer(String i,String n){
  18.        this.id=i;
  19.        this.name=n;
  20.    }
  21.    public void buy(Iteam i){
  22.        iteamList.add(i);  
  23.    }
  24.    public void display(){
  25.        System.out.println("Name of customer is "+name);
  26.        for(Iteam i: iteamList){
  27.            i.display();
  28.        }
  29.    }
  30. }
  31. package ClassTheory;
  32.  
  33. public class Iteam {
  34.     private String iteamId,iteamName;
  35.     private double price;
  36.     public Iteam(String id,String name){
  37.         this.iteamId=id;
  38.         this.iteamName=name;
  39.     }
  40.     public void setPrice(double d){
  41.         this.price=d;
  42.     }
  43.      void display(){
  44.         System.out.println("Iteam name is "+iteamName);
  45.         System.out.println("Iteam Id is "+iteamId);
  46.         System.out.println("Iteam price is "+price);
  47.        
  48.     }
  49. }
  50. package ClassTheory;
  51.  
  52. public class Adress {
  53.     private int houseNo,roadNo;
  54.     private String area,city;
  55.    
  56.     public Adress(int h,int r,String a,String c){
  57.         this.houseNo=h;
  58.         this.roadNo=r;
  59.         this.area=a;
  60.         this.city=c;
  61.     }
  62.    
  63.     public void display(){
  64.         System.out.println("House no of customer is "+houseNo);
  65.         System.out.println("Road no of customer is "+roadNo);
  66.         System.out.println("Area of customer is "+area);
  67.         System.out.println("City of customer is "+city);
  68.         System.out.println("");
  69.     }
  70. }
  71. package ClassTheory;
  72.  
  73. public class Test {
  74.  
  75.     public static void main(String[] args) {
  76.         Iteam choklate = new Iteam("IC_1", "Kitkat");
  77.         choklate.setPrice(65);
  78.         Iteam atta = new Iteam("IA_1", "shaad");
  79.         atta.setPrice(30);
  80.  
  81.         Adress a1 = new Adress(132, 20, "Mirpur", "Dhaka");
  82.         Adress a2 = new Adress(132, 20, "Dhanmondi", "Dhaka");
  83.  
  84.         Customer c1 = new Customer("Agor_C11", "Abdul");
  85.         Customer c2 = new Customer("Agor_C11", "Rahim");
  86.         c1.buy(atta);
  87.         c1.buy(choklate);
  88.  
  89.         c1.display();
  90.         c1.setAdress(a1);
  91.         c1.getAdress();
  92.  
  93.         c2.buy(choklate);
  94.         c2.buy(atta);
  95.         c2.display();
  96.         c2.setAdress(a2);
  97.         c2.getAdress();
  98.  
  99.     }
  100. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement