1)Create two Java classes, Desktop and Laptop that both are subclasses of Computer. a) A Desktop has additional instance variables: width and height (data encapsulation is expected) b) A Laptop has an additional instance variable, weight (data encapsulation is expected). c) Write constructors for both classes that require input for all their instance variables (including Manufacturing Date, Disk size, Number of cores and Color) and no-args constructors. d) Create getters and setters for all instance variables for both Child classes. e) Create toString() methods in Desktop and Laptop.

EBK JAVA PROGRAMMING
9th Edition
ISBN:9781337671385
Author:FARRELL
Publisher:FARRELL
Chapter14: Introduction To Swing Components
Section: Chapter Questions
Problem 3RQ
icon
Related questions
Question
please do both parts 
1)Create two Java classes, Desktop and Laptop that both are subclasses of Computer.
a) A Desktop has additional instance variables: width and height (data encapsulation is
expected)
b) A Laptop has an additional instance variable, weight (data encapsulation is expected).
c) Write constructors for both classes that require input for all their instance variables
(including Manufacturing Date, Disk size, Number of cores and Color) and no-args
constructors.
d) Create getters and setters for all instance variables for both Child classes.
e) Create toString() methods in Desktop and Laptop.
 
2) Test Two Child Classes
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).

 
➡ 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
凰
@
Transcribed Image Text:➡ 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 凰 @
◆ eclipse-workspace - project2/src/project2/Computer.java - Eclipse IDE
File Edit Source Refactor Navigate Search Project Run Window Help
- 2
#C
Difference.java
2
95.
TestPrintPri...
1 package project2;
2
3
4
6
8
9
10C
11
12
13
14
15
16
17
Č===================
19
$20
21
22
23
24
25
26
$27
$28
29
830
31
32
33
36
38Ⓒ
39
40
41
42
class Computer
0
private String Manufacturer;
private String DiskSize/
private String ManufacturingDate;
private int NumberOfCores/
//no-arg constructor
public Computer ()
{
1
[
1
project.java
//parameterised constructor
public Computer (String Manufacturer, String DiskSize, String ManufacturingDate, int NumberOfCores)
Manufacturer - ManufacturingDate "";
DiskSize = "";
NumberOfCores - 0;
//Catter methods
this.Manufacturer - Manufacturer;
this.ManufacturingDate - ManufacturingDate;
this.DiskSize - DiskSize;
this.NumberOfCores NumberOfCores;
public String getManufacturer() { return Manufacturer; 1
//Setter methods
public String getManufacturingDate() { return ManufacturingDate: 1
public String getDiskSize() { return DiskSize: 1
public int get NumberOfCores () { return NumberOfCores; 1
1
49°F
Clear
public void setManufacturer (String x) [ Manufacturer - x; 1
public void setManufacturingDate (String x) [ ManufacturingDate - x; }
public void setDiskSize(String x) [DiskSize - x: 1
public void setNumberOfCores (int x) [NumberOfCores - x: 1
Table.java
▬▬
▬▬▬
↓
MoreArith.java
public String tostring()
{
return "Manufacturer: " + Manufacturer + "\nManufacturing Date: " + ManufacturingDate + "\nDisk Size: " + DiskSize + "bytes" + "\nNumber of Cores: " + NumberOfCores;
Q Search
♡ ♡
Herjames_Pr...
Writable
Computer.java X TestCompute...
a
Smart Insert
42:2:1474
Desktop.java
Laptop.java
89
a
8:03 PM
4/3/2023
X
* * * + @ 隐旦
8
%
鼎
2
@
@
Transcribed Image Text:◆ eclipse-workspace - project2/src/project2/Computer.java - Eclipse IDE File Edit Source Refactor Navigate Search Project Run Window Help - 2 #C Difference.java 2 95. TestPrintPri... 1 package project2; 2 3 4 6 8 9 10C 11 12 13 14 15 16 17 Č=================== 19 $20 21 22 23 24 25 26 $27 $28 29 830 31 32 33 36 38Ⓒ 39 40 41 42 class Computer 0 private String Manufacturer; private String DiskSize/ private String ManufacturingDate; private int NumberOfCores/ //no-arg constructor public Computer () { 1 [ 1 project.java //parameterised constructor public Computer (String Manufacturer, String DiskSize, String ManufacturingDate, int NumberOfCores) Manufacturer - ManufacturingDate ""; DiskSize = ""; NumberOfCores - 0; //Catter methods this.Manufacturer - Manufacturer; this.ManufacturingDate - ManufacturingDate; this.DiskSize - DiskSize; this.NumberOfCores NumberOfCores; public String getManufacturer() { return Manufacturer; 1 //Setter methods public String getManufacturingDate() { return ManufacturingDate: 1 public String getDiskSize() { return DiskSize: 1 public int get NumberOfCores () { return NumberOfCores; 1 1 49°F Clear public void setManufacturer (String x) [ Manufacturer - x; 1 public void setManufacturingDate (String x) [ ManufacturingDate - x; } public void setDiskSize(String x) [DiskSize - x: 1 public void setNumberOfCores (int x) [NumberOfCores - x: 1 Table.java ▬▬ ▬▬▬ ↓ MoreArith.java public String tostring() { return "Manufacturer: " + Manufacturer + "\nManufacturing Date: " + ManufacturingDate + "\nDisk Size: " + DiskSize + "bytes" + "\nNumber of Cores: " + NumberOfCores; Q Search ♡ ♡ Herjames_Pr... Writable Computer.java X TestCompute... a Smart Insert 42:2:1474 Desktop.java Laptop.java 89 a 8:03 PM 4/3/2023 X * * * + @ 隐旦 8 % 鼎 2 @ @
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps with 5 images

Blurred answer
Knowledge Booster
Class
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT