-
Notifications
You must be signed in to change notification settings - Fork 25
feat:Adds Dasia's SmartPhone Object and Test to Lesson_16 #523
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
3c47acf
feat:Adds Dasia's SmartPhone Object and Test to Lesson_16
Dasiame ac08b37
fix: deleted methods that I was not using in my test
Dasiame 57e371b
fix: test that I was not using
Dasiame ab1508b
Merge branch 'code-differently:main' into lesson_16
Dasiame e923c25
Merge branch 'code-differently:main' into lesson_16
Dasiame 05b60f2
Merge branch 'code-differently:main' into lesson_16
Dasiame File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
5 changes: 5 additions & 0 deletions
5
...c/main/java/com/codedifferently/lesson16/SmartPhone/BatteryPercentageCustomException.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
public class BatteryPercentageCustomException extends Exception { | ||
public BatteryPercentageCustomException(String message) { | ||
super(message); | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
...on_16/objects/objects_app/src/main/java/com/codedifferently/lesson16/SmartPhone/Name.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package com.codedifferently.lesson16.SmartPhone; | ||
|
||
public enum Name { | ||
APPLE, | ||
SAMSUNG, | ||
ANDROID | ||
} |
61 changes: 61 additions & 0 deletions
61
...objects/objects_app/src/main/java/com/codedifferently/lesson16/SmartPhone/SmartPhone.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package com.codedifferently.lesson16.SmartPhone; | ||
|
||
import java.util.ArrayList; | ||
|
||
public class SmartPhone { | ||
|
||
private Name brandName; | ||
private String model; | ||
private int batteryPercentage; | ||
private boolean power; | ||
private ArrayList<String> apps; | ||
private int volume; | ||
|
||
public SmartPhone( | ||
Name brandName, String model, int batteryPercentage, boolean power, ArrayList<String> apps) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should be |
||
this.brandName = brandName; | ||
this.batteryPercentage = batteryPercentage; | ||
this.power = power; | ||
this.apps = apps; | ||
this.volume = volume; | ||
} | ||
|
||
public void setSmartPhonePowerbattery(int currentBatteryPercentage) { | ||
if (currentBatteryPercentage < 0 || currentBatteryPercentage > 100) { | ||
throw new IllegalArgumentException("Battery percentage must be in between 0 and 100."); | ||
} | ||
this.batteryPercentage = currentBatteryPercentage; | ||
} | ||
|
||
public int getBatteryPercentage() { | ||
return batteryPercentage; | ||
} | ||
|
||
public String getSmartPhoneApps() { | ||
var smartPhoneApps = ""; | ||
for (String s : apps) { | ||
smartPhoneApps += s; | ||
} | ||
return smartPhoneApps; | ||
} | ||
|
||
public void removeSmartPhoneApps(String App) { | ||
apps.remove(App); | ||
} | ||
|
||
public int getSmartPhoneVolume() { | ||
return 5; | ||
} | ||
|
||
public boolean isPowerOn() { | ||
return true; | ||
} | ||
|
||
public void addSmartPhoneApps(String instagram) { | ||
apps.add("," + instagram); | ||
} | ||
|
||
public void addSmartPhoneVolume() { | ||
volume++; | ||
} | ||
} |
83 changes: 83 additions & 0 deletions
83
lesson_16/objects/objects_app/src/test/java/com/codedifferently/lesson16/SmartPhoneTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertNotEquals; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
import com.codedifferently.lesson16.SmartPhone.Name; | ||
import com.codedifferently.lesson16.SmartPhone.SmartPhone; | ||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
|
||
public class SmartPhoneTest { | ||
private SmartPhone smartPhone; | ||
|
||
@BeforeEach | ||
void BeforeTest() { | ||
smartPhone = | ||
new SmartPhone( | ||
Name.APPLE, | ||
"Iphone14", | ||
50, | ||
true, | ||
new ArrayList<>( | ||
Arrays.asList("Phone,", "Contacts,", "Photos,", "Settings,", "Calender"))); | ||
// Turn phone on | ||
} | ||
|
||
@Test | ||
void testSmartPhoneCharge() { | ||
// Arrange | ||
|
||
// Act | ||
smartPhone.setSmartPhonePowerbattery( | ||
55); // Method with a loop to increase the battery percentage | ||
// Assert | ||
assertEquals(smartPhone.getBatteryPercentage(), 55); | ||
} | ||
|
||
@Test | ||
void testSmartPhoneApps() { | ||
// Arrange | ||
var smartPhoneApps = "Instagram"; | ||
// Act | ||
smartPhone.addSmartPhoneApps("Instagram"); // Method Add an app to my phone | ||
// Assert | ||
assertEquals( | ||
smartPhone.getSmartPhoneApps(), "Phone,Contacts,Photos,Settings,Calender,Instagram"); | ||
} | ||
|
||
@Test | ||
void testSmartPhoneRemoveApps() { | ||
// Arrange | ||
smartPhone.addSmartPhoneApps("Instagram"); | ||
// Act | ||
smartPhone.removeSmartPhoneApps(",Instagram"); // Method that removes the app from my phone | ||
// Assert | ||
assertEquals( | ||
smartPhone.getSmartPhoneApps(), | ||
"Phone,Contacts,Photos,Settings,Calender"); // Method that gets the apps on my phone | ||
} | ||
|
||
@Test | ||
void testSmartPhoneVolume() { | ||
// Arrange | ||
var smartPhoneOldVolume = 2; | ||
smartPhone.getSmartPhoneVolume(); // Method current/Old Volume of phone | ||
|
||
// Act | ||
smartPhone.addSmartPhoneVolume(); // Method add Volume to smart phone | ||
|
||
// Assert | ||
assertNotEquals(smartPhone.getSmartPhoneVolume(), smartPhoneOldVolume); | ||
} | ||
|
||
@Test | ||
void testSmartPhonePowerStatus() { | ||
// Act | ||
boolean isPhoneOn = smartPhone.isPowerOn(); // Method to check if the phone is on | ||
|
||
// Assert | ||
assertTrue(isPhoneOn); // Checks that the phone is indeed on | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
BrandName
would be better.