Online-Academy

Look, Read, Understand, Apply

Menu

OOAD - Object Oriented Analysis and Design

Class_to_code

import java.util.*;
class customer{
    int cid;
    String cname;
    public void set(int cid,String cname){
        this.cid = cid;
        this.cname = cname;
    }
    public void show(){
        System.out.println("Cid: "+cid+ " Name: "+cname);
    }
    public int getId(){ return cid;}
    public String getName(){ return cname;}
}
class product{
    int pid;
    String pname;
    int qty;
    double price;
    public void set(int pid, String pname,int qty,double price){
        this.pid = pid;
        this.pname = pname;
        this.qty = qty;
        this.price = price; 
    }
}
class purchase{
    int pid;
    int cid;
    String date;
    public purchase(int pid,int cid,String date){
        this.pid = pid;
        this.cid = cid;
        this.date = date; 
    }
    public void show(){
        System.out.println("PID: "+pid+" CDI: "+cid+" Date: "+date);
    }
}
class purchase_demo{
    public static void main(String[] arggg){
        customer [] c = new customer[3];   
        product [] p = new product[4];
        int i=0;
        for(i=0;i<3;i++)
            c[i] = new customer();
        for(i=0;i<4;i++)
            p[i] = new product();

        c[0].set(100,"Jeena");
        c[1].set(101,"Krish");
        c[2].set(103,"TereBina");
        p[0].set(1,"Bara",100,60);
        p[1].set(2,"Chatamari",90,80);
        p[2].set(3,"Gworamari",1000,10);
        p[3].set(4,"Wo",100,70);
        Scanner sc = new Scanner(System.in);
        ArrayList<purchase> arr = new ArrayList<purchase>();
        purchase pp ;
        while(true){
            System.out.println("ID: ");
            int pid = sc.nextInt();
            System.out.println("CID: ");
            int cid = sc.nextInt();
            pp = new purchase(pid, cid, "2/2/2021");
            arr.add(pp);
            System.out.print("Continue: ");
            String choice = sc.next();
            if(choice.equals("n")){
                break; 
            }
        }
        for(i=0;i<arr.size();i++){
            arr.get(i).show();           
        }
    }
    
}