-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRiverSimulator.java
More file actions
76 lines (58 loc) · 2.5 KB
/
RiverSimulator.java
File metadata and controls
76 lines (58 loc) · 2.5 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
import java.util.Scanner;
/**
* Simulates evolutions of river ecosystems
* containing bears and fish repeatedly.
*
* <i>(Project 1 for CS 150)</i>
*
* @author Jackson Eshbaugh
* @version 01/28/2024
*/
public class RiverSimulator {
/**
* Repeatedly simulates river ecosystem
* evolutions until the user exits.
*
* @param args not used.
*/
public static void main(String[] args) {
System.out.println("Welcome to CS 150 River Ecosystem Simulator!");
boolean exit = false;
Scanner s = new Scanner(System.in);
// Perform as many simulations as the user wants.
do {
System.out.println("River Ecosystem Simulator");
System.out.println("Please choose: 1 (random river) 2 (exit)");
int selection = s.nextInt();
if(selection == 2) exit = true;
else if(selection == 1) {
// Generate random river.
System.out.println("Creating a random river...");
System.out.println("Enter the river length (any integer bigger than 0): ");
int size = s.nextInt();
// Validate size
while (size <= 0 ) {
System.out.println("Enter the river length (any integer bigger than 0): ");
size = s.nextInt();
}
System.out.println("Enter the number of cycles (any integer bigger than 0): ");
int cycles = s.nextInt();
// Validate cycles
while (cycles <= 0 ) {
System.out.println("Enter the number of cycles (any integer bigger than 0): ");
cycles = s.nextInt();
}
// We have all data points. Create River.
River river = new River(size);
System.out.println("Initial river:");
System.out.println(river.toString());
for(int i = 0; i < cycles; ++i) {
river.updateRiver();
System.out.println("After cycle " + (i + 1));
System.out.println(river.toString());
}
} else System.out.println("Invalid selection. Please try again.\n");
} while (!exit);
System.out.println("Goodbye!");
}
}