Online-Academy

Look, Read, Understand, Apply

Menu

OOAD - Object Oriented Analysis and Design

Adapter_new

interface resultmaker{
    public void showResult();
}
class percentage implements resultmaker{
    double percent;
    public void setMarks(double obt,double total){
        percent = obt/total * 100;
    }
    public void showResult(){
        System.out.println("Percentage: "+percent);
    }
}

class grade{
    double obt;
    public grade(double obt){
        this.obt = obt; 
    }
    public void gradeMarks(){
        if(obt>=3.0 && obt <4.0)
            System.out.println("Grade: A");
        else if(obt >=2.5 && obt<3.0)
            System.out.println("Grade: B");
        else if(obt >=2.0 && obt<2.5)
            System.out.println("Grade: C");
    }
}
class resultmakerAdapter implements resultmaker{
    grade g;
    public resultmakerAdapter(grade g){
        this.g = g;
    }
    public void showResult(){
        g.gradeMarks();
    }
}

class resultmakerAdapterDemo{
    public static void main(String[] ar){
        percentage p = new percentage();
        p.setMarks(18, 50);
        p.showResult();
        grade g = new grade(2.9);
    //g.gradeMarks();
        resultmakerAdapter rma = new resultmakerAdapter(g);
        rma.showResult();
    }
}