Create a class called computers and two classes MyComputer and YourComputer which inherits computer class. Define appropriate fields for the three classes. Create another class processor as a composite class of computer. Write a method which prints the differences between the processors of two computers.
class Computer{
String proc;
int generation;
public String getProc() {
return proc;
}
}
class MyComputer extends Computer{
MyComputer(){
generation = 7;
}
@Override
public String getProc() {
return "Intel® Core™ i7 processor";
}
}
class YourComputer extends Computer{
YourComputer(){
generation = 5;
}
@Override
public String getProc() {
return "Intel® Core™ i5 processor";
}
}
public class Main {
public static void main(String[] args) {
Computer myComp = new MyComputer();
Computer yourComp = new YourComputer();
if(myComp.generation > yourComp.generation){
System.out.print(myComp.getProc() + ">" + yourComp.getProc());
} else {
System.out.print(yourComp.getProc() + ">" + myComp.getProc());
}
}
}
Comments
Leave a comment