Test your newly created subclasses inside the same TestComputer program you previously created: create two new Laptops and two new Desktops with the data of your choice. Use toString() method to show all data fields (including the data fields in the super class and sub class)Hint: Make sure to avoid redundancy in your code – no fields implemented in the Parent Class should be repeated/reimplemented/redefined in children. package project2; class Desktop extends Computer { private int width; private int height; public Desktop() { super(); width = height = 0; } public Desktop(String manufacturer, String diskSize, String manufacturingDate, int numberOfCores, int width, int height) { super(manufacturer, diskSize, manufacturingDate, numberOfCores); this.width = width; this.height = height; } public int getWidth() { return width; } public int getHeight() { return height; } public void setWidth(int width) { this.width = width; } public void setHeight(int height) { this.height = height; } @Override public String toString() { return super.toString() + "\nWidth: " + width + " cm" + "\nHeight: " + height + " cm"; } } package project2; class Laptop extends Computer { private double weight; public Laptop() { super(); weight = 0.0; } public Laptop(String manufacturer, String diskSize, String manufacturingDate, int numberOfCores, double weight) { super(manufacturer, diskSize, manufacturingDate, numberOfCores); this.weight = weight; } public double getWeight() { return weight; } public void setWeight(double weight) { this.weight = weight; } @Override public String toString() { return super.toString() + "\nWeight: " + weight + " kg"; } }
OOPs
In today's technology-driven world, computer programming skills are in high demand. The object-oriented programming (OOP) approach is very much useful while designing and maintaining software programs. Object-oriented programming (OOP) is a basic programming paradigm that almost every developer has used at some stage in their career.
Constructor
The easiest way to think of a constructor in object-oriented programming (OOP) languages is:
Test your newly created subclasses inside the same TestComputer program you previously
created: create two new Laptops and two new Desktops with the data of your choice. Use
toString() method to show all data fields (including the data fields in the super class and sub class)Hint: Make sure to avoid redundancy in your code – no fields implemented in the Parent Class
should be repeated/reimplemented/redefined in children.
package project2;
class Desktop extends Computer {
private int width;
private int height;
public Desktop() {
super();
width = height = 0;
}
public Desktop(String manufacturer, String diskSize, String manufacturingDate, int numberOfCores, int width, int height) {
super(manufacturer, diskSize, manufacturingDate, numberOfCores);
this.width = width;
this.height = height;
}
public int getWidth() {
return width;
}
public int getHeight() {
return height;
}
public void setWidth(int width) {
this.width = width;
}
public void setHeight(int height) {
this.height = height;
}
@Override
public String toString() {
return super.toString() + "\nWidth: " + width + " cm" + "\nHeight: " + height + " cm";
}
}
package project2;
class Laptop extends Computer {
private double weight;
public Laptop() {
super();
weight = 0.0;
}
public Laptop(String manufacturer, String diskSize, String manufacturingDate, int numberOfCores, double weight) {
super(manufacturer, diskSize, manufacturingDate, numberOfCores);
this.weight = weight;
}
public double getWeight() {
return weight;
}
public void setWeight(double weight) {
this.weight = weight;
}
@Override
public String toString() {
return super.toString() + "\nWeight: " + weight + " kg";
}
}

![➡ eclipse-workspace - project2/src/project2/TestComputer.java - Eclipse IDE
File Edit Source Refactor Navigate Search Project Run Window Help
Q
- 2
C
음...
TestPrintPri...
1 package project2;
2 public class TestComputer
3 {
{
project.java
4 public static void main(String[] args)
5
6
7
8
9
10
11
12 System.out.println (cl);
13 System.out.println();
14 System.out.println (c2);
}
49°F
Clear
15 System.out.println();
16
System.out.println (c3);
17
18
19 }
20
21
#
Difference.java
//Printing the information
▬▬
▬▬▬
Table.java
//Creating 3 objects.
Computer cl = new Computer ("Dell", "1189160321024", "April 1, 2020", 2);
Computer c2 = new Computer ("Apple Inc", "269283712040", "March 31, 2020", 4);
Computer c3 = new Computer ("Microsoft", "267950430223", "june 30, 2021", 6);
Q Search
↓➡
MoreArith.java
Herjames_Pr...
Writable
a
Computer.java
Smart Insert
TestCompute... XDesktop.java
16:26: 537
Laptop.java
89
a
8:02 PM
4/3/2023
X
* * * + @ 隐旦
8
%
鼎
2
凰
@](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F467946bb-e41e-4beb-a6a7-a7fc7a246d66%2Fe9f149b3-0305-48f8-9b84-b431f791f6d3%2Fd892pza_processed.png&w=3840&q=75)

Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 1 images









