-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMusicStore.java
More file actions
131 lines (115 loc) · 4.95 KB
/
MusicStore.java
File metadata and controls
131 lines (115 loc) · 4.95 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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
import java.util.ArrayList;
/**
* This is a tester class named MusicStore. It is used to test the
* the instruments homework which uses/outputs every moethod created
* @author Alizain Charania
* @version 1.0 Oct. 6 2015
*/
public class MusicStore {
/**
* This is the main method. This is the initial begging point of the program
* @param args it takes in the input from the command line call
*/
public static void main(String[] args) {
double violinPrice = 80.00;
String violinProperty = "10 strings";
Instrument violin = new Violin(violinPrice,
violinProperty);
Instrument trumpet = new Trumpet(120.00, "15cm diameter");
Instrument flute = new Flute(35.00, "2cm thick and 10cm long");
Instrument snareDrum = new SnareDrum(200.00,
"25 inches diameter");
String musicianName = "Mark";
double musicianFund = 350.00;
ArrayList<Instrument> instruments = new ArrayList<>();
instruments.add(violin);
Musician mark = null;
try {
mark = new Musician(musicianName, musicianFund, instruments);
} catch (NoLessThanOneInstrumentException e) {
System.out.println(e.getMessage());
}
System.out.println(violin.play());
System.out.println(violin.toString());
System.out.println("-----------------------------");
System.out.println(trumpet.play());
System.out.println(trumpet.toString());
System.out.println("-----------------------------");
System.out.println(flute.play());
System.out.println(flute.toString());
System.out.println("-----------------------------");
System.out.println(snareDrum.play());
System.out.println(snareDrum.toString());
System.out.println("-----------------------------");
System.out.printf("Musician name: %s, funds: $%.2f.\n",
mark.getName(), mark.getFunds());
System.out.printf("%s has the following instruments by "
+ "serial number:\n", mark.getName());
for (Instrument i : mark.getInstruments()) {
System.out.println(i.getSerialNum());
}
System.out.println("-----------------------------");
try {
mark.purchase(trumpet);
mark.purchase(snareDrum);
System.out.println("Buying new instruments");
System.out.printf("Musician name: %s, funds: $%.2f.\n",
mark.getName(), mark.getFunds());
System.out.printf("%s has the following instruments by "
+ "serial number:\n", mark.getName());
for (Instrument i : mark.getInstruments()) {
System.out.println(i.getSerialNum());
}
System.out.println("-----------------------------");
mark.purchase(flute);
System.out.println("-----------------------------");
} catch (NotEnoughFundsException e) {
System.out.println(e.getMessage());
} catch (NoSameInstrumentException e) {
System.out.println(e.getMessage());
}
System.out.println("-----------------------------");
try {
mark.sell(flute);
} catch (NoLessThanOneInstrumentException e) {
System.out.println(e.getMessage());
} catch (DoNotOwnInstrumentException e) {
System.out.println(e.getMessage());
}
System.out.println("-----------------------------");
try {
mark.sell(trumpet);
mark.sell(snareDrum);
System.out.println("Selling owned instruments");
System.out.printf("Musician name: %s, funds: $%.2f.\n",
mark.getName(), mark.getFunds());
System.out.printf("%s has the following instruments by "
+ "serial number:\n", mark.getName());
for (Instrument i : mark.getInstruments()) {
System.out.println(i.getSerialNum());
}
System.out.println("-----------------------------");
mark.sell(violin);
System.out.println("-----------------------------");
} catch (NoLessThanOneInstrumentException e) {
System.out.println(e.getMessage());
} catch (DoNotOwnInstrumentException e) {
System.out.println(e.getMessage());
}
System.out.println("-----------------------------");
try {
mark.purchase(violin);
} catch (NoSameInstrumentException e) {
System.out.println(e.getMessage());
} catch (NotEnoughFundsException e) {
System.out.println(e.getMessage());
}
System.out.println("-----------------------------");
ArrayList<Instrument> nullInstrument = new ArrayList<>();
try {
Musician john = new Musician("John", 1000.00, nullInstrument);
} catch (NoLessThanOneInstrumentException e) {
System.out.println(e.getMessage());
}
}
}