Skip to content

Commit a28e5c8

Browse files
Merge branch 'code-differently:main' into feat/lesson_17
2 parents 0e0ec62 + a51414e commit a28e5c8

File tree

5 files changed

+260
-0
lines changed

5 files changed

+260
-0
lines changed
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
package com.codedifferently.lesson16.personcomputer;
2+
3+
import java.util.ArrayList;
4+
import java.util.List;
5+
6+
public class Computer {
7+
public enum ComputerStatus {
8+
OFFLINE,
9+
ONLINE,
10+
SLEEP,
11+
SHUTDOWN
12+
}
13+
14+
private String brand;
15+
private String model;
16+
private String cpu;
17+
private int ramGB;
18+
private int storageGB;
19+
private boolean isPoweredOn;
20+
private List<String> installedPrograms;
21+
private ComputerStatus status; // use the enum here
22+
23+
public Computer(
24+
String brand, String model, String cpu, int ramGB, int storageGB, String installedPrograms) {
25+
this.brand = brand;
26+
this.model = model;
27+
this.cpu = cpu;
28+
this.ramGB = ramGB;
29+
this.storageGB = storageGB;
30+
this.isPoweredOn = false;
31+
this.installedPrograms = new ArrayList<>();
32+
this.status = ComputerStatus.OFFLINE;
33+
}
34+
35+
public class ComputerAlreadyOnException extends Exception {
36+
public ComputerAlreadyOnException(String message) {
37+
super(message);
38+
}
39+
}
40+
41+
public void powerOn() throws ComputerAlreadyOnException {
42+
if (!isPoweredOn) {
43+
isPoweredOn = true;
44+
status = ComputerStatus.ONLINE;
45+
} else {
46+
throw new ComputerAlreadyOnException("Computer is already powered on.");
47+
}
48+
}
49+
50+
public String getBrand() {
51+
return brand;
52+
}
53+
54+
public String getModel() {
55+
return model;
56+
}
57+
58+
public String getCPU() {
59+
return cpu;
60+
}
61+
62+
public int getRAMGB() {
63+
return ramGB;
64+
}
65+
66+
public int getSTORAGEGB() {
67+
return storageGB;
68+
}
69+
70+
public boolean isPoweredOn() {
71+
return isPoweredOn;
72+
}
73+
74+
public ComputerStatus getStatus() {
75+
return status;
76+
}
77+
78+
public void listPrograms() {
79+
System.out.println("Installed Programs:");
80+
for (String program : installedPrograms) {
81+
System.out.println("- " + program);
82+
}
83+
}
84+
85+
public void installProgram(String programName) {
86+
if (!installedPrograms.contains(programName)) {
87+
installedPrograms.add(programName);
88+
}
89+
}
90+
91+
public List<String> getInstalledPrograms() {
92+
return installedPrograms;
93+
}
94+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package com.codedifferently.lesson16.personcomputer;
2+
3+
import static org.junit.jupiter.api.Assertions.*;
4+
5+
import org.junit.jupiter.api.Test;
6+
7+
class ComputerAlreadyOnExceptionTest {
8+
9+
@Test
10+
void testExceptionMessage() {
11+
String message = "Computer is already powered on.";
12+
Computer.ComputerAlreadyOnException exception =
13+
new Computer(message, message, message, 0, 0, message)
14+
.new ComputerAlreadyOnException(message);
15+
assertEquals(message, exception.getMessage());
16+
}
17+
18+
@Test
19+
void testPowerOnThrowsException() throws Exception {
20+
Computer computer = new Computer("Dell", "XPS", "Intel", 8, 256, "");
21+
computer.powerOn();
22+
23+
Exception exception =
24+
assertThrows(Computer.ComputerAlreadyOnException.class, computer::powerOn);
25+
26+
assertEquals("Computer is already powered on.", exception.getMessage());
27+
}
28+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package com.codedifferently.lesson16.personcomputer;
2+
3+
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
4+
import static org.junit.jupiter.api.Assertions.assertEquals;
5+
6+
import org.junit.jupiter.api.Test;
7+
8+
class ComputerStatusTest {
9+
10+
@Test
11+
void testEnumValues() {
12+
Computer.ComputerStatus[] statuses = Computer.ComputerStatus.values();
13+
assertEquals(4, statuses.length);
14+
assertArrayEquals(
15+
new Computer.ComputerStatus[] {
16+
Computer.ComputerStatus.OFFLINE,
17+
Computer.ComputerStatus.ONLINE,
18+
Computer.ComputerStatus.SLEEP,
19+
Computer.ComputerStatus.SHUTDOWN
20+
},
21+
statuses);
22+
}
23+
24+
@Test
25+
void testValueOf() {
26+
assertEquals(Computer.ComputerStatus.ONLINE, Computer.ComputerStatus.valueOf("ONLINE"));
27+
}
28+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
package com.codedifferently.lesson16.personcomputer;
2+
3+
import static org.junit.jupiter.api.Assertions.assertEquals;
4+
import static org.junit.jupiter.api.Assertions.assertFalse;
5+
import static org.junit.jupiter.api.Assertions.assertTrue;
6+
7+
import org.junit.jupiter.api.BeforeEach;
8+
import org.junit.jupiter.api.Test;
9+
10+
public class ComputerTest {
11+
12+
private Computer computer;
13+
14+
@BeforeEach
15+
public void setUp() {
16+
computer = new Computer("Dell", "Inspiron 15", "Intel Core i7", 16, 512, "Windows 11");
17+
}
18+
19+
@Test
20+
public void testPowerOn() throws Computer.ComputerAlreadyOnException {
21+
assertFalse(computer.isPoweredOn());
22+
23+
computer.powerOn();
24+
25+
assertTrue(computer.isPoweredOn());
26+
assertEquals(Computer.ComputerStatus.ONLINE, computer.getStatus());
27+
}
28+
29+
@Test
30+
public void testInstallProgram() {
31+
// Install a new program
32+
computer.installProgram("Windows 11");
33+
34+
assertTrue(computer.getInstalledPrograms().contains("Windows 11"));
35+
}
36+
37+
@Test
38+
public void testDuplicateProgramNotInstalledTwice() {
39+
// Install a program
40+
computer.installProgram("Google Chrome");
41+
42+
// Try installing the same program again
43+
computer.installProgram("Google Chrome");
44+
45+
// Verify the program is only installed once
46+
assertEquals(1, computer.getInstalledPrograms().size());
47+
}
48+
49+
@Test
50+
public void testGetters() {
51+
// Verify that the getters return correct values
52+
assertEquals("Dell", computer.getBrand());
53+
assertEquals("Inspiron 15", computer.getModel());
54+
assertEquals("Intel Core i7", computer.getCPU());
55+
assertEquals(16, computer.getRAMGB());
56+
assertEquals(512, computer.getSTORAGEGB());
57+
}
58+
}

project_oop/README.md

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# Project OOP
2+
*You down with OOP? (Yeah you know me!)*
3+
4+
## Introduction
5+
6+
For this project, you and your teammates are tasked with modeling a solution to a real-world problem using object-oriented and SOLID design principles, from ideation to implementation.
7+
8+
## Prerequisites
9+
10+
Before starting work on your project, you will need to submit three user stories as feature requests in your assigned GitHub repo. These will need to be approved by the instructor before you can begin coding. Your final project submission must enable the functionality described by your user stories.
11+
12+
## Project Requirements
13+
14+
* All work must be submitted in your team's assigned GitHub repository.
15+
* The assignment can be completed in TypeScript or in Java.
16+
* Must include at least 5 types of objects with meaningful relattionships to each other.
17+
* One of your objects must be a custom data structure that provides for adding, removing, and updating items in a collection.
18+
* Implement at least two custom exceptions.
19+
* Write unit tests achieving 90% code coverage (using JaCoCo for Java or Jest for Typescript).
20+
* Must include an integration test for each user story that demonstrates how your code implements the desired feature.
21+
* Your solution must illustrate each of the SOLID principles.
22+
* Each team member must contribute *at least one* submitted pull request containing working code and tests.
23+
* Include a README for your repo describing the problem you're solving, the solution, and how you would improve your solution.
24+
25+
# Presentation Requirements
26+
27+
* Your presentation should be no more than 10 minutes with a maximum of 10 slides.
28+
* Each member of the team must speak during the presentation.
29+
* Your presentation must address the following questions:
30+
* What problem were you attempting to solve?
31+
* How does your design address the solution?
32+
* How did you address each of the SOLID principles?
33+
* How would you improve on your solution?
34+
35+
## Extra Credit
36+
37+
Design a CLI that allows users to interact with your application. Check out the code in [lesson_10](/lesson_10/libraries/src/cli/) for an example in TypeScript, or [this file](/lib/java/codedifferently-instructional/instructional-lib/src/main/java/com/codedifferently/instructional/quiz/QuizProctor.java) for an example in Java.
38+
39+
## Timeline
40+
41+
* Submit three user stories (Monday, 4/14, 5PM ET)
42+
* Receive approval for your user stories (Tuesday, 4/15, 1PM ET)
43+
* Finish code commits (Friday, 4/18, 1PM ET)
44+
* Give presentation (Monday, 4/21, 1PM ET)
45+
46+
## Grading
47+
48+
Your grade for this project will amount to 25% of your final grade in the course.
49+
50+
* 50% of your project grade will be composed of a team score. Your final solution and presentation will be assessed on how well it meets the described functional and technical requirements. Work submitted after the assigned deadline will result in a deduction of points.
51+
* Completing the extra credit will enable up to an additional 50% increase to the team score component.
52+
* The remaining 50% of your grade will be composed of an individual score. The individual score will be computed based on survey feedback from your teammates and the instructors/TAs regarding your technical ability, communication skills, and teamwork contributions.

0 commit comments

Comments
 (0)