Answer to Question #318569 in Java | JSP | JSF for superBoy

Question #318569

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.


1
Expert's answer
2022-03-26T06:42:49-0400
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());
        }
    }
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS