-
Notifications
You must be signed in to change notification settings - Fork 111
Expand file tree
/
Copy pathMain.java
More file actions
59 lines (46 loc) · 1.79 KB
/
Main.java
File metadata and controls
59 lines (46 loc) · 1.79 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
import java.util.Scanner;
public class Main {
private static ISubscriber subscribers[] = {
new MultiplicationSeries(),
new SummationSeries(),
new CircleCircumference(),
new CircleArea(),
new CircleVolume(),
new SphereCircumference(),
new SphereArea(),
new SphereVolume(),
new Fibonacci(),
new TwoPowerN(),
};
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
Topic mathTopic = new Topic();
for (ISubscriber sub : subscribers) {
mathTopic.addSubscriber(sub);
}
try {
while (true) {
for (int i = 0; i < subscribers.length; ++i) {
System.out.println((i + 1) + " - " + subscribers[i].getClass().getName());
}
System.out.println("0 - Run all functions");
System.out.println("X - Exit application");
System.out.println("Choose your option:");
String input = sc.next();
if (input.equals("X")) break;
int choice = Integer.parseInt(input);
System.out.println("Enter input number: ");
int n = Integer.parseInt(sc.next());
if (choice < 0 || choice > subscribers.length) throw new Exception("Invalid choice.");
if (choice != 0)
subscribers[choice - 1].notifySubscriber(n);
else
mathTopic.dispatchEvent(n);
}
} catch (NumberFormatException ignored) {
System.out.println("Your input is not a valid integer.");
} catch (Exception ex) {
System.out.println(ex.getMessage());
}
}
}