8000 Composition In Java · aasys12/learningJava@a16cdab · GitHub
[go: up one dir, main page]

Skip to content

Commit a16cdab

Browse files
committed
Composition In Java
1 parent 7ec29fc commit a16cdab

File tree

7 files changed

+183
-0
lines changed

7 files changed

+183
-0
lines changed

src/Case.java

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
public class Case {
2+
private String model;
3+
private String manufacturer;
4+
private String powersupply;
5+
private Dimenssion dimenssion;
6+
7+
public Case(String model, String manufacturer, String powersupply, Dimenssion dimenssion) {
8+
this.model = model;
9+
this.manufacturer = manufacturer;
10+
this.powersupply = powersupply;
11+
this.dimenssion = dimenssion;
12+
}
13+
public void Presspowebutton(){
14+
System.out.println(" Power Button Pressed ");
15+
}
16+
17+
public String getModel() {
18+
return model;
19+
}
20+
21+
public String getManufacturer() {
22+
return manufacturer;
23+
}
24+
25+
public String getPowersupply() {
26+
return powersupply;
27+
}
28+
29+
public Dimenssion getDimenssion() {
30+
return dimenssion;
31+
}
32+
}

src/Dimenssion.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
public class Dimenssion {
2+
private int width;
3+
private int depth;
4+
private int height;
5+
6+
public Dimenssion(int width, int depth, int height) {
7+
this.width = width;
8+
this.depth = depth;
9+
this.height = height;
10+
}
11+
12+
public int getWidth() {
13+
return width;
14+
}
15+
16+
public int getDepth() {
17+
return depth;
18+
}
19+
20+
public int getHeight() {
21+
return height;
22+
}
23+
}

src/Monitor.java

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
public class Monitor {
2+
private String model;
3+
private String manufacturer;
4+
private int size;
5+
private Resolution nativeResolution;
6+
7+
public Monitor(String model, String manufacturer, int size, Resolution nativeResolution) {
8+
this.model = model;
9+
this.manufacturer = manufacturer;
10+
this.size = size;
11+
this.nativeResolution = nativeResolution;
12+
}
13+
14+
public String getModel() {
15+
return model;
16+
}
17+
18+
public String getManufacturer() {
19+
return manufacturer;
20+
}
21+
22+
public int getSize() {
23+
return size;
24+
}
25+
26+
public Resolution getNativeResolution() {
27+
return nativeResolution;
28+
}
29+
30+
public void drawPixelAt(int x, int y, String color){
31+
System.out.println("Drawing pixel at "+ x+ y +" int color "+ color );
32+
33+
34+
}
35+
}

src/Motherboard.java

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
public class Motherboard {
2+
private String model;
3+
private String manufacturer;
4+
private int ramSlots;
5+
private int cardSlots;
6+
private String bios;
7+
8+
public Motherboard(String model, String manufacturer, int ramSlots, int cardSlots, String bios) {
9+
this.model = model;
10+
this.manufacturer = manufacturer;
11+
this.ramSlots = ramSlots;
12+
this.cardSlots = cardSlots;
13+
this.bios = bios;
14+
15+
}
16+
public void loadProgram(String programName){
17+
System.out.println("Program "+programName +" is now loading");
18+
19+
}
20+
21+
public String getModel() {
22+
return model;
23+
}
24+
25+
public String getManufacturer() {
26+
return manufacturer;
27+
}
28+
29+
public int getRamSlots() {
30+
return ramSlots;
31+
}
32+
33+
public int getCardSlots() {
34+
return cardSlots;
35+
}
36+
37+
public String getBios() {
38+
return bios;
39+
}
40+
}

src/PersonalComputer.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
public class PersonalComputer {
2+
private Case theCase;
3+
private Monitor monitor;
4+
private Motherboard motherboard;
5+
6+
public PersonalComputer(Case theCase, Monitor monitor, Motherboard motherboard) {
7+
this.theCase = theCase;
8+
this.monitor = monitor;
9+
this.motherboard = motherboard;
10+
}
11+
12+
public Case getTheCase() {
13+
return theCase;
14+
}
15+
16+
public Monitor getMonitor() {
17+
return monitor;
18+
}
19+
20+
public Motherboard getMotherboard() {
21+
return motherboard;
22+
}
23+
}

src/Resolution.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
public class Resolution {
2+
private int height;
3+
private int width;
4+
5+
public Resolution(int height, int width) {
6+
this.height = height;
7+
this.width = width;
8+
}
9+
10+
public int getHeight() {
11+
return height;
12+
}
13+
14+
public int getWidth() {
15+
return width;
16+
}
17+
}

src/pcMain.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
public class pcMain {
2+
public static void main(String[] args) {
3+
Dimenssion dimenssion =new Dimenssion(10,20,30);
4+
Case theCase=new Case("3000","DEll","2",dimenssion);
5+
Monitor monitor=new Monitor("rtx200","HP",20,new Resolution(40,50));
6+
Motherboard motherboard=new Motherboard("Asus","Dell",5,3,"v2.0");
7+
PersonalComputer personalComputer=new PersonalComputer(theCase,monitor,motherboard);
8+
personalComputer.getMonitor().drawPixelAt(2,3,"Red");
9+
personalComputer.getMotherboard().loadProgram("Windows 1.0");
10+
personalComputer.getTheCase().Presspowebutton();
11+
12+
}
13+
}

0 commit comments

Comments
 (0)
0