Need some help with this java problem with inheritance. -Write a class with two
ID: 3890428 • Letter: N
Question
Need some help with this java problem with inheritance.
-Write a class with two superclasses and give them the appropriate methods and fields. All methods and fields are instance based and should have proper access protection. (all methods should be public.
First class: Pc
- Field of type String named pcu ... Method named setPcu which has a single String parameter that it uses to set the value of the pcu field..... Method named getPcu which has no parameters and returns the value of the processor field.
Second class: Apple
-Make it a subclass of Pc...
Field of type String named pcu... Method named setPcu which has a single String parameter that it uses to set the value of the pcu field..... Method named setPcu which has a single String parameter that it uses to set the value of the pcu field......Method named getOSVersion which has no parameters and returns the value of the osVersion field......Method named upgrade which has a parameter of type double and sets the value of the osVersion field to value of the parameter.....Method named description which has no parameters and returns a String equal to the value of the processor field, followed by a single space, followed by the value of the osVersion field.
-Make a second subclass of Pc called Windows...
Field of type String named pcu... Method named setPcu which has a single String parameter that it uses to set the value of the pcu field..... Method named setPcu which has a single String parameter that it uses to set the value of the pcu field......Method named setVersion which has a single String parameter that it uses to set the value of the version field.....Method named description which has no parameters and returns a String equal to the value of the processor field, followed by " Windows: ", followed by the value of the version field.
Explanation / Answer
Note: Just I developed the three classes.Do u want me to develop the drier class ..??? Just give me message.If u want be to develop..Thank you.
_____________________
Pc.java
public class Pc {
// Declaring instance variables
private String pcu;
// Parameterized constructor
public Pc(String pcu) {
this.pcu = pcu;
}
// getters and setters
public String getPcu() {
return pcu;
}
public void setPcu(String pcu) {
this.pcu = pcu;
}
}
________________
Apple.java
public class Apple extends Pc {
// Declaring instance variables
private double osVersion;
// Parameterized constructor
public Apple(String pcu, double osVersion) {
super(pcu);
this.osVersion = osVersion;
}
// getters and setters
public double getOSVersion() {
return osVersion;
}
public void upgrade(double osversion) {
this.osVersion = osversion;
}
// Method which will return the Processor and OsVersion
public String description() {
return "Processor :" + getPcu() + " OSVersion:" + osVersion;
}
}
___________________
Windows.java
public class Windows extends Pc {
// Declaring instance variables
private String version;
// Parameterized constructor
public Windows(String pcu, String version) {
super(pcu);
this.version = version;
}
// getters and setters
public String getVersion() {
return version;
}
public void setVersion(String version) {
this.version = version;
}
// Method which will return the Processor and windows Version
public String description() {
return "Processor :" + getPcu() + " Windows:" + version;
}
}
___________________
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.