Skip to content

Commit 68ff344

Browse files
authored
Merge branch 'code-differently:main' into lesson_17
2 parents b0099ab + 815ec63 commit 68ff344

File tree

24 files changed

+1438
-4
lines changed

24 files changed

+1438
-4
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package com.codedifferently.lesson16.dylans_xbox;
2+
3+
public class DiskDriveFullException extends Exception {
4+
public DiskDriveFullException(String message) {
5+
super(message);
6+
}
7+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package com.codedifferently.lesson16.dylans_xbox;
2+
3+
import java.io.BufferedReader;
4+
import java.io.FileReader;
5+
import java.io.IOException;
6+
7+
public class LoadGame {
8+
private String filePath;
9+
10+
public LoadGame(String filePath) {
11+
this.filePath = filePath;
12+
}
13+
14+
public void loadGamesFromFile(Xbox xbox) throws Exception {
15+
try (BufferedReader br = new BufferedReader(new FileReader(filePath))) {
16+
String line;
17+
br.readLine(); // Skip the header line
18+
while ((line = br.readLine()) != null) {
19+
String[] gameDetails = line.split(",");
20+
if (gameDetails.length >= 2) {
21+
22+
int id = Integer.parseInt(gameDetails[0].trim());
23+
String name = gameDetails[1].trim();
24+
xbox.getGames().put(id, name);
25+
}
26+
}
27+
} catch (IOException e) {
28+
throw new Exception("Error reading the games file: " + e.getMessage());
29+
}
30+
}
31+
}
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
package com.codedifferently.lesson16.dylans_xbox;
2+
3+
import java.util.ArrayList;
4+
import java.util.HashMap;
5+
6+
public class Xbox {
7+
private ArrayList<String> insertedGames = new ArrayList<>();
8+
private HashMap<Integer, String> games;
9+
// Declares the model of the Xbox by using the enum XboxModel
10+
private XboxModel model;
11+
private String color;
12+
private int price;
13+
// Declares if there is a disk drive on the Xbox
14+
private boolean diskDrive = false;
15+
16+
// Defines a fixed set of constants for GameGenre
17+
public enum XboxModel {
18+
XBOX360,
19+
XBOXONE,
20+
XBOXONES,
21+
XBOXONEX,
22+
XBOXSERIESS,
23+
XBOXSERIESX
24+
}
25+
26+
// Constructor for the Xbox class
27+
public Xbox(String model, int price, String color, boolean diskDrive, boolean diskDriveFull) {
28+
this.model = XboxModel.valueOf(model.toUpperCase());
29+
this.price = price;
30+
this.color = color;
31+
this.diskDrive = diskDrive;
32+
this.insertedGames = new ArrayList<>();
33+
this.games = new HashMap<>();
34+
}
35+
36+
public int getInsertedGamesSize() {
37+
return insertedGames.size();
38+
}
39+
40+
// Getters for the Xbox class
41+
public XboxModel getModel() {
42+
return model;
43+
}
44+
45+
public HashMap<Integer, String> getGames() {
46+
return games;
47+
}
48+
49+
public int getPrice() {
50+
return price;
51+
}
52+
53+
public String getColor() {
54+
return color;
55+
}
56+
57+
public boolean DiskDrive() {
58+
return diskDrive;
59+
}
60+
61+
// Method that will add a game to the disk drive
62+
// it will check if the disk drive is empty and if it is, it will add the game to the disk drive
63+
// by turning it to true.
64+
public void inputGame(int id) throws Exception {
65+
if (!diskDrive) {
66+
throw new Exception("This Xbox does not have a disk drive. Cannot insert game.");
67+
}
68+
if (insertedGames.size() >= 2) {
69+
throw new DiskDriveFullException("Disk drive is full. Cannot insert game.");
70+
}
71+
72+
String gameName = games.get(id);
73+
if (gameName == null) {
74+
throw new Exception("Game with ID: " + id + " does not exist in the library.");
75+
}
76+
if (insertedGames.contains(gameName)) {
77+
throw new Exception("Game \"" + gameName + "\" is already inserted.");
78+
}
79+
80+
insertedGames.add(gameName);
81+
games.remove(id);
82+
83+
System.out.println("Game \"" + gameName + "\" (ID: " + id + ") was added to the disk drive.");
84+
}
85+
86+
// Method that will eject a game from the disk drive
87+
// it will check if the game is in the drive and if it is, it will turn the drive to false.
88+
public void ejectGame(int id) {
89+
if (insertedGames.size() >= 1) {
90+
insertedGames.removeAll(insertedGames);
91+
System.out.println("Game with ID: " + id + " was ejected from the disk drive.");
92+
} else {
93+
System.out.println("Game with ID: " + id + " not found in the disk drive.");
94+
}
95+
}
96+
97+
// This method will print all the games in the HashMap
98+
// By running a for loop that will iterate through the games
99+
public void printAllGames() {
100+
for (Integer id : games.keySet()) {
101+
System.out.println("Game ID: " + id + ", Game Name: " + games.get(id));
102+
}
103+
}
104+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
id, name
2+
1, Call of Duty
3+
2, Elden Ring
4+
3, Minecraft
5+
4, Monster Hunter
6+
5, Fortnite
7+
6, Marvel Rivals
8+
7, Tetris
9+
8, Madden NFL
10+
9, Terraria
11+
10,Baldur's Gate 3
Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
package com.codedifferently.lesson16.hiphopArtist;
2+
3+
import java.util.ArrayList;
4+
5+
public class HipHopArtist {
6+
private boolean isAlive;
7+
private String stageName;
8+
private int debutYear;
9+
private double netWorth;
10+
private ArrayList<String> albums;
11+
private Genre genre;
12+
13+
public HipHopArtist(
14+
boolean isAlive,
15+
String stageName,
16+
int debutYear,
17+
double netWorth,
18+
ArrayList<String> albums,
19+
Genre genre) {
20+
this.isAlive = isAlive;
21+
this.stageName = stageName;
22+
this.debutYear = debutYear;
23+
this.netWorth = netWorth;
24+
this.albums = albums;
25+
this.genre = genre;
26+
}
27+
28+
public String checkLegendStatus() {
29+
return debutYear <= 2000
30+
? stageName + " is a legend in the game."
31+
: stageName + " is a modern star.";
32+
}
33+
34+
public void addAlbum(String album) {
35+
albums.add(album);
36+
System.out.println(album + " was added to " + stageName + "'s discography.");
37+
}
38+
39+
public String listAlbums() throws NoAlbumsException {
40+
if (albums.isEmpty()) {
41+
throw new NoAlbumsException(stageName + " has no albums listed.");
42+
}
43+
System.out.println("Albums by " + stageName + ":");
44+
for (String album : albums) {
45+
System.out.println("- " + album);
46+
}
47+
return stageName;
48+
}
49+
50+
public String getBio() {
51+
return stageName
52+
+ " ("
53+
+ genre
54+
+ ") debuted in "
55+
+ debutYear
56+
+ ", is "
57+
+ (isAlive ? "alive" : "deceased")
58+
+ ", and has a net worth of $"
59+
+ netWorth
60+
+ ".";
61+
}
62+
63+
public boolean isAlive() {
64+
return isAlive;
65+
}
66+
67+
public void setAlive(boolean alive) {
68+
isAlive = alive;
69+
}
70+
71+
public String getStageName() {
72+
return stageName;
73+
}
74+
75+
public void setStageName(String stageName) {
76+
this.stageName = stageName;
77+
}
78+
79+
public int getDebutYear() {
80+
return debutYear;
81+
}
82+
83+
public void setDebutYear(int debutYear) {
84+
this.debutYear = debutYear;
85+
}
86+
87+
public double getNetWorth() {
88+
return netWorth;
89+
}
90+
91+
public void setNetWorth(double netWorth) {
92+
this.netWorth = netWorth;
93+
}
94+
95+
public ArrayList<String> getAlbums() {
96+
return albums;
97+
}
98+
99+
public void setAlbums(ArrayList<String> albums) {
100+
this.albums = albums;
101+
}
102+
103+
public Genre getGenre() {
104+
return genre;
105+
}
106+
107+
public void setGenre(Genre genre) {
108+
this.genre = genre;
109+
}
110+
111+
public enum Genre {
112+
RAP,
113+
GANGSTA_RAP,
114+
OLD_SCHOOL,
115+
TRAP,
116+
DRILL,
117+
}
118+
119+
@Override
120+
public String toString() {
121+
return "HipHopArtist{"
122+
+ "isAlive="
123+
+ isAlive
124+
+ ", stageName='"
125+
+ stageName
126+
+ '\''
127+
+ ", debutYear="
128+
+ debutYear
129+
+ ", netWorth="
130+
+ netWorth
131+
+ ", albums="
132+
+ albums
133+
+ ", genre="
134+
+ genre
135+
+ '}';
136+
}
137+
}
138+
139+
class NoAlbumsException extends Exception {
140+
public NoAlbumsException(String message) {
141+
super(message);
142+
}
143+
}
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
package com.codedifferently.lesson16.oliviajames;
2+
3+
import java.util.ArrayList;
4+
import java.util.List;
5+
6+
public class MakeupRoutine {
7+
8+
public enum MakeupLook {
9+
DEWY,
10+
NATURAL,
11+
FULL_GLAM,
12+
SOFT_GLAM,
13+
}
14+
15+
// Member Variables
16+
private String name;
17+
private int time;
18+
private final boolean usesPrimer;
19+
private final MakeupLook lookType;
20+
List<String> vanityItems;
21+
22+
// Constructor
23+
public MakeupRoutine(String name, int time, boolean usesPrimer, MakeupLook lookType) {
24+
this.name = name;
25+
this.time = time;
26+
this.usesPrimer = true;
27+
this.lookType = lookType;
28+
}
29+
30+
// Getters/setters
31+
32+
public String getName() {
33+
return name;
34+
}
35+
36+
public void setName(String name) {
37+
this.name = name;
38+
}
39+
40+
public int getTime() {
41+
return time;
42+
}
43+
44+
public void setTime(int time) {
45+
this.time = time;
46+
}
47+
48+
public boolean getUsesPrimer() throws MissingPrimerException {
49+
if (!usesPrimer) {
50+
throw new MissingPrimerException("missing primer");
51+
}
52+
System.out.println("has primer");
53+
return true;
54+
}
55+
56+
public MakeupLook getLookType() {
57+
return lookType;
58+
}
59+
60+
public void MakeupVanity() {
61+
vanityItems = new ArrayList<>();
62+
vanityItems.add("Foundation");
63+
vanityItems.add("Concealer");
64+
vanityItems.add("Setting Powder");
65+
vanityItems.add("Blush");
66+
vanityItems.add("Highlighter");
67+
vanityItems.add("Eyeshadow Palette");
68+
vanityItems.add("Mascara");
69+
vanityItems.add("Eyeliner");
70+
vanityItems.add("Lipstick");
71+
vanityItems.add("Lip Gloss");
72+
vanityItems.add("Setting Spray");
73+
vanityItems.add("Makeup Brushes");
74+
}
75+
76+
public void showVanityItems() {
77+
System.out.println("Items on the vanity:");
78+
for (String item : vanityItems) {
79+
System.out.println("- " + item);
80+
}
81+
}
82+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package com.codedifferently.lesson16.oliviajames;
2+
3+
public class MissingPrimerException extends Exception {
4+
public MissingPrimerException(String message) {
5+
super(message);
6+
}
7+
}

0 commit comments

Comments
 (0)