Skip to content

Commit d91857f

Browse files
authored
Merge branch 'code-differently:main' into lesson_17
2 parents 5b263d8 + 0632a13 commit d91857f

File tree

27 files changed

+1646
-0
lines changed

27 files changed

+1646
-0
lines changed
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
package com.codedifferently.lesson16.horseStable;
2+
3+
import java.util.ArrayList;
4+
import java.util.List;
5+
6+
public class HorseStable {
7+
8+
public enum StableType {
9+
PRIVATE,
10+
COMMERCIAL,
11+
RACE,
12+
SHOW
13+
}
14+
15+
private final String name;
16+
private final String location;
17+
private final int capacity;
18+
private final StableType stableType;
19+
private final List<String> horses;
20+
21+
// constructur
22+
public HorseStable(String name, String location, int capacity, StableType stableType) {
23+
this.name = name;
24+
this.location = location;
25+
this.capacity = capacity;
26+
this.stableType = stableType;
27+
this.horses = new ArrayList<>();
28+
}
29+
30+
// getters & setters
31+
public String getName() {
32+
return name;
33+
}
34+
35+
public String getLocation() {
36+
return location;
37+
}
38+
39+
public int getCapacity() {
40+
return capacity;
41+
}
42+
43+
public StableType getStableType() {
44+
return stableType;
45+
}
46+
47+
public List<String> getHorses() {
48+
return horses;
49+
}
50+
51+
// methods
52+
public String stableFull() {
53+
if (horses.size() >= capacity) {
54+
return "The stable is full. Cannot add more horses.";
55+
} else {
56+
return "Space available in the stable.";
57+
}
58+
}
59+
60+
public void addHorse(String horseName) throws StableFullException {
61+
if (horses.size() >= capacity) {
62+
throw new StableFullException("Cannot add horse: stable is at full capacity!");
63+
}
64+
horses.add(horseName);
65+
}
66+
67+
public void removeHorse(String horseName) {
68+
if (!horses.contains(horseName)) {
69+
throw new IllegalArgumentException("Horse not found in the stable.");
70+
}
71+
horses.remove(horseName);
72+
}
73+
74+
public String displayHorses() {
75+
if (horses.isEmpty()) {
76+
return "No horses in the stable.";
77+
}
78+
return "There are " + horses.size() + " horses in " + name + ".";
79+
}
80+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package com.codedifferently.lesson16.horseStable;
2+
3+
public class StableFullException extends Exception {
4+
public StableFullException(String message) {
5+
super(message);
6+
}
7+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package com.codedifferently.lesson16.KimberleeObject;
2+
3+
public class ConnectionNotFoundException extends Exception {
4+
public ConnectionNotFoundException(String message) {
5+
super(message);
6+
}
7+
}
Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
package com.codedifferently.lesson16.KimberleeObject;
2+
3+
import java.util.Arrays;
4+
5+
public class HeadPhones {
6+
7+
private int volume = 0;
8+
private boolean isPoweredOn = false;
9+
private HeadPhoneColor headPhoneColor = HeadPhoneColor.BLACK;
10+
private boolean isWireless = true;
11+
private String brands = "Beats";
12+
boolean isPreferredBrand = BrandUtils.isPreferredBrand(brands);
13+
private boolean isConnectedToBluetooth = false;
14+
15+
public enum BoostMode {
16+
BASS_BOOST,
17+
VOCAL_BOOST,
18+
TREBLE_BOOST;
19+
}
20+
21+
private BoostMode currentMode;
22+
private BoostMode[] modes = BoostMode.values();
23+
private int currentModeIndex = 0;
24+
25+
public HeadPhones() {
26+
this.currentMode = BoostMode.BASS_BOOST;
27+
System.out.println("Constructor called: currentMode set to " + currentMode);
28+
}
29+
30+
public void nextBoostMode() {
31+
currentModeIndex = (currentModeIndex + 1) % modes.length;
32+
currentMode = modes[currentModeIndex];
33+
}
34+
35+
public BoostMode getCurrentMode() {
36+
System.out.println("getCurrentMode called: currentMode is " + currentMode);
37+
return currentMode;
38+
}
39+
40+
public enum HeadPhoneColor {
41+
RED,
42+
BLUE,
43+
ROSEGOLD,
44+
PINK,
45+
WHITE,
46+
BLACK;
47+
}
48+
49+
public void BrandsArray() {
50+
String[] brands = new String[5];
51+
brands[0] = "Beats";
52+
brands[1] = "Sony";
53+
brands[2] = "Bose";
54+
brands[3] = "SkullCandy";
55+
brands[4] = "Juicy";
56+
}
57+
58+
public int getVolume() {
59+
return volume;
60+
}
61+
62+
public HeadPhoneColor getHeadPhoneColor() {
63+
return headPhoneColor;
64+
}
65+
66+
public boolean isPoweredOn() {
67+
return isPoweredOn;
68+
}
69+
70+
public boolean isWireless() {
71+
return isWireless;
72+
}
73+
74+
public String[] getBrandsArray() {
75+
return BrandUtils.PREFERRED_BRANDS;
76+
}
77+
78+
public void turnOn() {
79+
isPoweredOn = true;
80+
}
81+
82+
public void turnOff() {
83+
isPoweredOn = false;
84+
}
85+
86+
public void increaseVolume() {
87+
if (volume < 100) {
88+
volume++;
89+
}
90+
}
91+
92+
public void setVolume(int volume) {
93+
if (volume >= 0 && volume <= 100) {
94+
this.volume = volume;
95+
}
96+
}
97+
98+
public void decreaseVolume() {
99+
if (volume > 0) {
100+
volume--;
101+
}
102+
}
103+
104+
public void setColor(HeadPhoneColor color) {
105+
this.headPhoneColor = color;
106+
}
107+
108+
public class BrandUtils {
109+
private static final String[] PREFERRED_BRANDS = {
110+
"Beats", "Sony", "Bose", "SkullCandy", "Juicy"
111+
};
112+
113+
public static boolean isPreferredBrand(String brand) {
114+
return Arrays.asList(PREFERRED_BRANDS).contains(brand);
115+
}
116+
}
117+
118+
public boolean connectToBluetooth() {
119+
if (isPoweredOn && isWireless) {
120+
isConnectedToBluetooth = true;
121+
}
122+
return isConnectedToBluetooth;
123+
}
124+
125+
public boolean isConnectedToBluetooth() {
126+
return connectToBluetooth();
127+
}
128+
129+
public void wirelessConnection() throws ConnectionNotFoundException {
130+
if (!isConnectedToBluetooth) {
131+
throw new ConnectionNotFoundException("Headphones Wireless Connection Not Found.");
132+
}
133+
}
134+
}
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: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
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+
private int volume;
13+
14+
public SmartPhone(
15+
Name brandName, String model, int batteryPercentage, boolean power, ArrayList<String> apps) {
16+
this.brandName = brandName;
17+
this.batteryPercentage = batteryPercentage;
18+
this.power = power;
19+
this.apps = apps;
20+
this.volume = volume;
21+
}
22+
23+
public void setSmartPhonePowerbattery(int currentBatteryPercentage) {
24+
if (currentBatteryPercentage < 0 || currentBatteryPercentage > 100) {
25+
throw new IllegalArgumentException("Battery percentage must be in between 0 and 100.");
26+
}
27+
this.batteryPercentage = currentBatteryPercentage;
28+
}
29+
30+
public int getBatteryPercentage() {
31+
return batteryPercentage;
32+
}
33+
34+
public String getSmartPhoneApps() {
35+
var smartPhoneApps = "";
36+
for (String s : apps) {
37+
smartPhoneApps += s;
38+
}
39+
return smartPhoneApps;
40+
}
41+
42+
public void removeSmartPhoneApps(String App) {
43+
apps.remove(App);
44+
}
45+
46+
public int getSmartPhoneVolume() {
47+
return 5;
48+
}
49+
50+
public boolean isPowerOn() {
51+
return true;
52+
}
53+
54+
public void addSmartPhoneApps(String instagram) {
55+
apps.add("," + instagram);
56+
}
57+
58+
public void addSmartPhoneVolume() {
59+
volume++;
60+
}
61+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
package com.codedifferently.lesson16.chelseaogbonnia.bookshelf;
2+
3+
enum Genre {
4+
FICTION,
5+
NON_FICTION,
6+
MYSTERY,
7+
SCIENCE_FICTION,
8+
FANTASY,
9+
HORROR,
10+
ROMANCE,
11+
ADVENTURE,
12+
HISTORY,
13+
CRIME
14+
}
15+
16+
enum BookType {
17+
HARDCOVER,
18+
PAPERBACK,
19+
MAGAZINE,
20+
NOVEL,
21+
POEM,
22+
COMICS
23+
}
24+
25+
public class Book {
26+
private String title;
27+
private String author;
28+
private Genre genre;
29+
private BookType bookType;
30+
31+
public Book(String title, String author, Genre genre, BookType bookType) {
32+
this.title = title;
33+
this.author = author;
34+
this.genre = genre;
35+
this.bookType = bookType;
36+
}
37+
38+
public String getTitle() {
39+
return title;
40+
}
41+
42+
public String getAuthor() {
43+
return author;
44+
}
45+
46+
public Genre getGenre() {
47+
return genre;
48+
}
49+
50+
public BookType getBookType() {
51+
return bookType;
52+
}
53+
}

0 commit comments

Comments
 (0)