-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApp.java
More file actions
110 lines (87 loc) · 3.94 KB
/
App.java
File metadata and controls
110 lines (87 loc) · 3.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
import java.io.Console;
import java.util.List;
import java.util.ArrayList;
public class App {
public static void main(String[] args) {
Console myConsole = System.console();
int tenPercentCoupon = 123;
int twentyPercentCoupon = 234;
int thirtyPercentCoupon = 345;
Cd radiohead = new Cd("Radiohead", "Hail to the Thief", 2003, 13);
Cd metalica = new Cd("Metalica", "Enter Sandman", 1991, 10);
List <Cd> allCds = new ArrayList<Cd>();
allCds.add(radiohead);
allCds.add(metalica);
System.out.println("Welcome to our CD Shop! What would you like to do?");
boolean programRunning = true;
while(programRunning) {
System.out.println("Enter one of the following options:" + "\n" + "All Cds, Apply Coupon, Add your own CD, Search by Release Date, Search by Price Range, Search by Band, Exit");
String navigationChoice = myConsole.readLine();
if (navigationChoice.equals("All Cds")) {
for (Cd individualCd : allCds) {
individualCd.displayProp(individualCd);
}
} else if (navigationChoice.equals("Apply Coupon")) {
System.out.println("Please enter your coupon code.");
int myCouponCode = Integer.parseInt(myConsole.readLine());
if (myCouponCode == tenPercentCoupon) {
for (Cd individualCd : allCds) {
individualCd.mPrice = (individualCd.mPrice * .9);
individualCd.displayProp(individualCd);
}
} else if (myCouponCode == twentyPercentCoupon) {
for (Cd individualCd : allCds) {
individualCd.mPrice = (individualCd.mPrice * .8);
individualCd.displayProp(individualCd);
}
} else if (myCouponCode == thirtyPercentCoupon) {
for (Cd individualCd : allCds) {
individualCd.mPrice = (individualCd.mPrice * .7);
individualCd.displayProp(individualCd);
}
}
} else if (navigationChoice.equals("Add your own CD")) {
System.out.println("What is the name of the band?");
String myBandName = myConsole.readLine();
System.out.println("What is the name of the album?");
String myAlbumName = myConsole.readLine();
System.out.println("What year did the album come out?");
int myReleaseDate = Integer.parseInt(myConsole.readLine());
System.out.println("What price would you like to sell it for?");
double myPrice = Double.parseDouble(myConsole.readLine());
Cd userCd = new Cd(myBandName, myAlbumName, myReleaseDate, myPrice);
allCds.add(userCd);
System.out.println("Here is your new CD!");
userCd.displayProp(userCd);
} else if (navigationChoice.equals("Search by Release Date")) {
System.out.println("What release date would like to search for?");
int searchDate = Integer.parseInt(myConsole.readLine());
for (Cd individualCd : allCds) {
if (individualCd.mRDate == searchDate) {
individualCd.displayProp(individualCd);
}
}
} else if (navigationChoice.equals("Search by Price Range")) {
System.out.println("What is your min price?");
double minPrice = Double.parseDouble(myConsole.readLine());
System.out.println("What is your max price?");
double maxPrice = Double.parseDouble(myConsole.readLine());
for (Cd individualCd : allCds) {
if (minPrice <= individualCd.mPrice && individualCd.mPrice <= maxPrice) {
individualCd.displayProp(individualCd);
}
}
} else if (navigationChoice.equals("Search by Band")) {
System.out.println("What band would you like to search for?");
String searchBand = myConsole.readLine();
for (Cd individualCd : allCds) {
if (individualCd.mBand.equals(searchBand)) {
individualCd.displayProp(individualCd);
}
}
} else if (navigationChoice.equals("Exit")) {
programRunning = false;
}
}
}
}