diff --git a/lesson_07/objects/objects_app/src/main/java/com/codedifferently/lesson7/MohamedObjects/Main/CPU.java b/lesson_07/objects/objects_app/src/main/java/com/codedifferently/lesson7/MohamedObjects/Main/CPU.java index 94d13d60..33c7ba80 100644 --- a/lesson_07/objects/objects_app/src/main/java/com/codedifferently/lesson7/MohamedObjects/Main/CPU.java +++ b/lesson_07/objects/objects_app/src/main/java/com/codedifferently/lesson7/MohamedObjects/Main/CPU.java @@ -1,12 +1,14 @@ -package com.codedifferently.lesson7.MohamedObjects.Main; +package com.codedifferently.lesson7.mohamedobjects.main; -public class CPU extends Parts { +public class CPU extends Part { double clockSpeed; int cores; - public CPU() {} + public CPU(cpuBrand brand) { + this.brand = brand.toString(); + } - public CPU(String name, int releaseYear, cpuBrands brand, double clockSpeed) { + public CPU(String name, int releaseYear, cpuBrand brand, double clockSpeed) { this.name = name; checkValidYear(releaseYear); this.releaseYear = releaseYear; @@ -14,7 +16,7 @@ public CPU(String name, int releaseYear, cpuBrands brand, double clockSpeed) { this.clockSpeed = clockSpeed; } - public CPU(String name, int releaseYear, cpuBrands brand, double clockSpeed, int cores) { + public CPU(String name, int releaseYear, cpuBrand brand, double clockSpeed, int cores) { this.name = name; checkValidYear(releaseYear); this.releaseYear = releaseYear; diff --git a/lesson_07/objects/objects_app/src/main/java/com/codedifferently/lesson7/MohamedObjects/Main/GPU.java b/lesson_07/objects/objects_app/src/main/java/com/codedifferently/lesson7/MohamedObjects/Main/GPU.java index 66b49612..9288c2f5 100644 --- a/lesson_07/objects/objects_app/src/main/java/com/codedifferently/lesson7/MohamedObjects/Main/GPU.java +++ b/lesson_07/objects/objects_app/src/main/java/com/codedifferently/lesson7/MohamedObjects/Main/GPU.java @@ -1,17 +1,15 @@ -package com.codedifferently.lesson7.MohamedObjects.Main; +package com.codedifferently.lesson7.mohamedobjects.main; import java.util.HashSet; import java.util.Set; -enum empty {} +public class GPU extends Part { -public class GPU extends Parts { + private Set ports = new HashSet(); - Set ports = new HashSet(); + private int vRam; - int vRam; - - boolean hasRayTracing; + private boolean hasRayTracing; public GPU() {} @@ -43,19 +41,16 @@ public int getvRam() { return vRam; } - public Set getPorts() { + public Set getPorts() { return ports; } - public void addPorts(portTypes port) { + public void addPorts(portType port) { this.ports.add(port); } - public int printNumPorts() { - int i = 0; - for (portTypes a : ports) { - i++; - } - return i; + public int calculateNumPorts() { + // this was set to a loop to meet project reqirements + return ports.size(); } } diff --git a/lesson_07/objects/objects_app/src/main/java/com/codedifferently/lesson7/MohamedObjects/Main/IllegalYearExeption.java b/lesson_07/objects/objects_app/src/main/java/com/codedifferently/lesson7/MohamedObjects/Main/IllegalYearExeption.java index e5f876a4..250212ad 100644 --- a/lesson_07/objects/objects_app/src/main/java/com/codedifferently/lesson7/MohamedObjects/Main/IllegalYearExeption.java +++ b/lesson_07/objects/objects_app/src/main/java/com/codedifferently/lesson7/MohamedObjects/Main/IllegalYearExeption.java @@ -1,4 +1,4 @@ -package com.codedifferently.lesson7.MohamedObjects.Main; +package com.codedifferently.lesson7.mohamedobjects.main; public class IllegalYearExeption extends RuntimeException { IllegalYearExeption(String error) { diff --git a/lesson_07/objects/objects_app/src/main/java/com/codedifferently/lesson7/MohamedObjects/Main/Parts.java b/lesson_07/objects/objects_app/src/main/java/com/codedifferently/lesson7/MohamedObjects/Main/Parts.java deleted file mode 100644 index 5a651f7a..00000000 --- a/lesson_07/objects/objects_app/src/main/java/com/codedifferently/lesson7/MohamedObjects/Main/Parts.java +++ /dev/null @@ -1,49 +0,0 @@ -package com.codedifferently.lesson7.MohamedObjects.Main; - -public class Parts { - String name; - int releaseYear; - String brand; - - public Parts() {} - - public Parts(String name, int releaseYear, String brand) { - this.name = name; - checkValidYear(releaseYear); - this.releaseYear = releaseYear; - this.brand = brand; - } - - public void setBrand(String brand) { - this.brand = brand; - } - - public void setName(String name) { - this.name = name; - } - - public void setReleaseYear(int releaseYear) { - checkValidYear(releaseYear); - this.releaseYear = releaseYear; - } - - public String getBrand() { - return brand; - } - - public String getName() { - return name; - } - - public int getReleaseYear() { - return releaseYear; - } - - public boolean checkValidYear(int year) { - if (year <= 2024 && year >= 2000) { - return true; - } else { - throw new IllegalYearExeption("Year is out of expected range. 2000 - 2024"); - } - } -} diff --git a/lesson_07/objects/objects_app/src/main/java/com/codedifferently/lesson7/MohamedObjects/Main/cpuBrands.java b/lesson_07/objects/objects_app/src/main/java/com/codedifferently/lesson7/MohamedObjects/Main/cpuBrands.java deleted file mode 100644 index 4a00f15f..00000000 --- a/lesson_07/objects/objects_app/src/main/java/com/codedifferently/lesson7/MohamedObjects/Main/cpuBrands.java +++ /dev/null @@ -1,7 +0,0 @@ -package com.codedifferently.lesson7.MohamedObjects.Main; - -public enum cpuBrands { - AMD, - INTEL, - APPLE -} diff --git a/lesson_07/objects/objects_app/src/main/java/com/codedifferently/lesson7/MohamedObjects/Main/portTypes.java b/lesson_07/objects/objects_app/src/main/java/com/codedifferently/lesson7/MohamedObjects/Main/portTypes.java deleted file mode 100644 index e2acc402..00000000 --- a/lesson_07/objects/objects_app/src/main/java/com/codedifferently/lesson7/MohamedObjects/Main/portTypes.java +++ /dev/null @@ -1,8 +0,0 @@ -package com.codedifferently.lesson7.MohamedObjects.Main; - -public enum portTypes { - VGA, - DVI, - HDMI, - DP -} diff --git a/lesson_07/objects/objects_app/src/test/java/com/codedifferently/lesson7/MohamedTest.java b/lesson_07/objects/objects_app/src/test/java/com/codedifferently/lesson7/MohamedTest.java deleted file mode 100644 index 644eb16d..00000000 --- a/lesson_07/objects/objects_app/src/test/java/com/codedifferently/lesson7/MohamedTest.java +++ /dev/null @@ -1,60 +0,0 @@ -package com.codedifferently.lesson7; - -// import java.lang.reflect.Method; - -import static org.junit.jupiter.api.Assertions.*; - -import com.codedifferently.lesson7.MohamedObjects.Main.CPU; -import com.codedifferently.lesson7.MohamedObjects.Main.GPU; -import com.codedifferently.lesson7.MohamedObjects.Main.IllegalYearExeption; -import com.codedifferently.lesson7.MohamedObjects.Main.cpuBrands; -import com.codedifferently.lesson7.MohamedObjects.Main.portTypes; -import java.util.*; -import org.junit.jupiter.api.Test; - -class MohamedTest { - - @Test - public void setClockSpeed() { - CPU cpu = new CPU("cpu1", 2000, cpuBrands.INTEL, 23.32); - assertEquals(23.32, cpu.getClockSpeed()); - } - - @Test - void gpuReleaseYear() throws IllegalYearExeption { - GPU aGpu = new GPU(); - try { - aGpu.setReleaseYear(1999); - fail("Expected IllegalYearExeption"); - } catch (IllegalYearExeption e) { - assertEquals("Year is out of expected range. 2000 - 2024", e.getMessage()); - } - } - - @Test - void testGpuPorts() { - - Set porty = Set.of(portTypes.DP, portTypes.HDMI, portTypes.VGA); - GPU bGpu = new GPU("Radion 560 xt", 2015, "AMD", 8); - bGpu.addPorts(portTypes.DP); - bGpu.addPorts(portTypes.HDMI); - bGpu.addPorts(portTypes.VGA); - assertEquals(bGpu.getPorts(), porty); - } - - @Test - void testSize() { - GPU bGpu = new GPU("GTX 1050", 2015, "Navidia", 8); - bGpu.addPorts(portTypes.DP); - bGpu.addPorts(portTypes.HDMI); - bGpu.addPorts(portTypes.VGA); - assertEquals(bGpu.printNumPorts(), 3); - } - - @Test - void testCores() { - CPU m1 = new CPU("M1", 2020, cpuBrands.APPLE, 4.0, 8); - assertEquals(m1.getCores(), 8); - ; - } -} diff --git a/lesson_07/objects/objects_app/src/test/java/com/codedifferently/lesson7/mohamedobjects/main/ComputerPartsTest.java b/lesson_07/objects/objects_app/src/test/java/com/codedifferently/lesson7/mohamedobjects/main/ComputerPartsTest.java new file mode 100644 index 00000000..0dfc92f7 --- /dev/null +++ b/lesson_07/objects/objects_app/src/test/java/com/codedifferently/lesson7/mohamedobjects/main/ComputerPartsTest.java @@ -0,0 +1,65 @@ +package com.codedifferently.lesson7.mohamedobjects.main; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; + +import java.util.Set; +import org.junit.jupiter.api.Test; + +class ComputerPartsTest { + CPU cpu = new CPU("M1", 2020, cpuBrand.INTEL, 23.32); + GPU bGpu = new GPU("Radion 560 xt", 2015, "AMD", 8); + Part apart = new Part(); + + @Test + public void testCpuConstruction() { + assertEquals(23.32, cpu.getClockSpeed()); + + assertNotEquals(8, cpu.getCores()); + + cpu.setCores(8); + + assertEquals(8, cpu.getCores()); + + assertEquals(2020, cpu.getReleaseYear()); + + assertNotEquals("M2", cpu.getName()); + } + + @Test + void testGpuConstruction() { + + Set porty = Set.of(portType.DP, portType.HDMI, portType.VGA); + bGpu.addPorts(portType.DP); + bGpu.addPorts(portType.HDMI); + bGpu.addPorts(portType.VGA); + assertEquals(porty, bGpu.getPorts()); + + assertEquals(3, bGpu.calculateNumPorts()); + } + + @Test + void testYearValadation() { + assertThrows( + IllegalYearExeption.class, + () -> { + bGpu.checkValidYear(1999); + }); + assertThrows( + IllegalYearExeption.class, + () -> { + bGpu.checkValidYear(3000); + }); + } + + @Test + void testPartConstruction() { + apart.setBrand("A Brand"); + apart.setName("A Part"); + apart.setReleaseYear(2011); + assertEquals("A Brand", apart.getBrand()); + assertEquals("A Part", apart.getName()); + assertEquals(2011, apart.getReleaseYear()); + } +}