Skip to content

Commit 3c47acf

Browse files
committed
feat:Adds Dasia's SmartPhone Object and Test to Lesson_16
1 parent 2bff2f9 commit 3c47acf

File tree

4 files changed

+168
-0
lines changed

4 files changed

+168
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
public class BatteryPercentageCustomException extends Exception{
2+
public BatteryPercentageCustomException (String message){
3+
super (message);
4+
}
5+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package com.codedifferently.lesson16.SmartPhone;
2+
3+
public enum Name {
4+
APPLE,
5+
SAMSUNG,
6+
ANDROID
7+
}
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
package com.codedifferently.lesson16.SmartPhone;
2+
3+
import java.util.ArrayList;
4+
5+
public class SmartPhone {
6+
7+
private Name brandName;
8+
private String model;
9+
private int batteryPercentage;
10+
private boolean power;
11+
private ArrayList<String> apps;
12+
13+
public SmartPhone(
14+
Name brandName, String model, int batteryPercentage, boolean power, ArrayList<String> apps) {
15+
this.brandName = brandName;
16+
this.batteryPercentage = batteryPercentage;
17+
this.power = power;
18+
this.apps = apps;
19+
}
20+
21+
public void setSmartPhonePowerbattery(int currentBatteryPercentage) {
22+
if (currentBatteryPercentage < 0 || currentBatteryPercentage > 100) {
23+
throw new IllegalArgumentException("Battery percentage must be in between 0 and 100.");
24+
}
25+
this.batteryPercentage = currentBatteryPercentage;
26+
}
27+
28+
public int getBatteryPercentage() {
29+
return batteryPercentage;
30+
}
31+
32+
public void setSmartPhoneBatteryIncrease(int chargeBatteryAmount) {
33+
// loop
34+
}
35+
36+
public void chargeSmartPhone() {}
37+
38+
public void setSmartPhonePower() {}
39+
40+
public void setSmartPhoneBatteryPercentage(int currentBatteryPercentage) {
41+
if (currentBatteryPercentage < 0 || currentBatteryPercentage > 100) {
42+
throw new IllegalArgumentException("Battery percentage must be in between 0 and 100.");
43+
}
44+
this.batteryPercentage = currentBatteryPercentage;
45+
}
46+
47+
public void addSmartPhoneApps(String App) {}
48+
49+
public String getSmartPhoneApps() {
50+
var smartPhoneApps = "";
51+
for (String s : apps) {
52+
smartPhoneApps += s;
53+
}
54+
return smartPhoneApps;
55+
}
56+
57+
public void removeSmartPhoneApps(String App) {
58+
apps.remove(App);
59+
}
60+
61+
public void currentSmartPhoneVolume() {}
62+
63+
public void addSmartPhoneVolume() {}
64+
65+
public int getSmartPhoneVolume() {
66+
return 5;
67+
}
68+
69+
public boolean isPowerOn() {
70+
return true;
71+
}
72+
}
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
import static org.junit.jupiter.api.Assertions.assertEquals;
2+
import static org.junit.jupiter.api.Assertions.assertNotEquals;
3+
import static org.junit.jupiter.api.Assertions.assertTrue;
4+
5+
import com.codedifferently.lesson16.SmartPhone.Name;
6+
import com.codedifferently.lesson16.SmartPhone.SmartPhone;
7+
import java.util.ArrayList;
8+
import java.util.Arrays;
9+
import org.junit.jupiter.api.BeforeEach;
10+
import org.junit.jupiter.api.Test;
11+
12+
public class SmartPhoneTest {
13+
private SmartPhone smartPhone;
14+
15+
@BeforeEach
16+
void BeforeTest() {
17+
smartPhone =
18+
new SmartPhone(
19+
Name.APPLE,
20+
"Iphone14",
21+
50,
22+
true,
23+
new ArrayList<>(Arrays.asList("Phone,Contacts,Photos,Settings,Calender")));
24+
// Turn phone on
25+
}
26+
27+
@Test
28+
void testSmartPhoneCharge() {
29+
// Arrange
30+
31+
// Act
32+
smartPhone.chargeSmartPhone(); // Method with a loop to increase the battery percentage
33+
// Assert
34+
assertEquals(smartPhone.getBatteryPercentage(), 50);
35+
}
36+
37+
@Test
38+
void testSmartPhoneApps() {
39+
// Arrange
40+
var smartPhoneApps = "Instagram";
41+
// Act
42+
smartPhone.addSmartPhoneApps("Instagram"); // Method Add an app to my phone
43+
// Assert
44+
assertEquals(smartPhone.getSmartPhoneApps(), "Phone,Contacts,Photos,Settings,Calender");
45+
}
46+
47+
@Test
48+
void testSmartPhoneRemoveApps() {
49+
// Arrange
50+
smartPhone.addSmartPhoneApps("Instagram");
51+
// Act
52+
smartPhone.removeSmartPhoneApps("Instagram"); // Method that removes the app from my phone
53+
// Assert
54+
assertEquals(
55+
smartPhone.getSmartPhoneApps(),
56+
"Phone,Contacts,Photos,Settings,Calender"); // Method that gets the apps on my phone
57+
}
58+
59+
@Test
60+
void testSmartPhoneVolume() {
61+
// Arrange
62+
var smartPhoneOldVolume = 2;
63+
smartPhone.getSmartPhoneVolume(); // Method current/Old Volume of phone
64+
65+
// Act
66+
smartPhone.addSmartPhoneVolume(); // Method add Volume to smart phone
67+
68+
// Assert
69+
assertNotEquals(smartPhone.getSmartPhoneVolume(), smartPhoneOldVolume);
70+
}
71+
72+
private void getSmartPhonePercentage() {
73+
throw new UnsupportedOperationException("Not supported yet.");
74+
}
75+
76+
@Test
77+
void testSmartPhonePowerStatus() {
78+
// Act
79+
boolean isPhoneOn = smartPhone.isPowerOn(); // Method to check if the phone is on
80+
81+
// Assert
82+
assertTrue(isPhoneOn); // Checks that the phone is indeed on
83+
}
84+
}

0 commit comments

Comments
 (0)