-
Notifications
You must be signed in to change notification settings - Fork 0
/
CoinSimViewer.java
57 lines (50 loc) · 1.68 KB
/
CoinSimViewer.java
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
import java.awt.Dimension;
import java.awt.Point;
import java.awt.Toolkit;
import java.util.Scanner;
import javax.swing.JFrame;
import java.awt.BorderLayout;
/**
* This is the main class which prompts for the number of trials. It creates the
* JFrame containing the CoinSimComponent. CoinSimViewer is only dependent on
* the CoinSimComponent class. The CoinSimComponent calls objects of the
* CoinTossSimulator and Bar classes. The CoinTossSimulator simulates the tosses
* and produces the required parameters for the Bar class to display the
* appropriate Bar on the Frame.
*/
public class CoinSimViewer {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int tries = 0;
/** Creating a Dimension variable for the Frame dimensions */
Dimension framedimen = new Dimension(800, 500);
/**
* Running a do-while loop to check for the Validity of the Input Tries
*/
do {
if (tries <= 0) {
System.out.println("Please Enter a VALID value for the number of Tries ");
}
System.out.println("Enter the number of tries : ");
tries = in.nextInt();
if (tries > 0) {
break;
/** break from do-while if we get a valid input */
}
} while (tries <= 0);
/**
* Creating a CoinSimComponent object which also calls the constructor
* of the class
*/
CoinSimComponent component = new CoinSimComponent(tries);
JFrame frame = new JFrame();
frame.setPreferredSize(framedimen);
frame.setTitle("BarChart");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.add(component);
frame.pack();
frame.setLocationRelativeTo(null);
frame.setVisible(true);
in.close();
}
}