forked from SPHS-CS/JavaZoo
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathZoo.java
More file actions
85 lines (76 loc) · 2.51 KB
/
Copy pathZoo.java
File metadata and controls
85 lines (76 loc) · 2.51 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
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.TimeUnit;
import java.util.Random;
import java.util.Scanner;
/**
* Write a description of class Zoo here.
*
* @author APCSA2014-15
* @version 2015-03-06
*/
public class Zoo
{
public static void main(String[] args) throws InterruptedException
{
List<Random> animals = new ArrayList<Random>();
System.out.println("Welcome to the Zoo!\n");
System.out.print("Building the cages");
delayDots();
System.out.print("Populating the animals");
populateAnimals(animals);
delayDots();
System.out.print("Hiring zookeepers");
delayDots();
Scanner in = new Scanner(System.in);
System.out.println("\nYou are standing in a wondrous zoo. What would you like to do?");
System.out.println("Type help to find out what you can do.\n");
String text = in.nextLine();
String msg = "";
while(!text.equals("leave"))
{
switch(text)
{
case "help" : msg = "So far we can only leave and ask for help.";
break;
default : msg = "You flail helplessly with indecision.";
}
System.out.println("\n" + msg);
System.out.println("\nYou are standing in a wondrous zoo. What would you like to do?\n");
text = in.nextLine();
}
System.out.println(Math.random() > .8 ? "\nHave a nice day! Hope you come back!" : "\nAn escaped lion eats you on your way out. Sorry!");
}
/**
* This prints an ellipses with 1 second between each period
* It then moves to the next line.
*/
public static void delayDots(int dotAmount) throws InterruptedException
{
for (int i=0; i<dotAmount; i++) {
TimeUnit.SECONDS.sleep(1);
System.out.print(".");
}
System.out.println();
}
/**
* This prints an ellipses with 1 second between each period
* It then moves to the next line.
*/
public static void delayDots() throws InterruptedException
{
delayDots(3);
}
/**
* This is where we will all collaborate.
* Construct your animal and add it to the List
* @param animals the list containing all the zoo animals
*/
public static void populateAnimals(List<Random> animals)
{
Random r = new Random();
Random q = new Random();
animals.add(r);
animals.add(q);
}
}