-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPet.java
More file actions
165 lines (148 loc) · 4.17 KB
/
Copy pathPet.java
File metadata and controls
165 lines (148 loc) · 4.17 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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
import java.util.Scanner;
public class Pet {
int age;
double userNumber; double weight; double height; double money = 1.00;
String color; String userAnswer; String food;
private int theHealth;
Scanner input = new Scanner (System.in);
/* -------------------------- CHECK VARIABLES ----------------------------------*/
// CHECK THE HEALTH METHOD
public void checkHealth () {
if (theHealth == 10 ){
System.out.println("Optimum Health! :D");
}
else if (theHealth <= 10 && theHealth > 0) {
System.out.println("I'm not the best, but I'll be fine");
}
else if ( theHealth == 0 ) {
System.out.println("Critical and in need of health");
}
else {
System.out.println("You ran out of health and died." + " " + "BYE FELICIA!");
restartGame();
}
}
// CHECK FUNDS
public void checkFunds()
{
if (money == 0.00 )
{
System.out.println("You ran out of health and died." + " " + "BYE FELICIA!");
restartGame();
}
}
/* -------------------------- PET, GAME OPTIONS < RESTART < QUIT ----------------------------------*/
// RESTART OR QUIT GAME
public void restartGame() {
System.out.println(" Would you like to play again?");
userAnswer = input.next();
if ( userAnswer.equalsIgnoreCase("yes")) {
theOptions();
}
else if (userAnswer.equalsIgnoreCase("no")) {
System.out.println("See you next time, goodbye!");
System.exit(0);
}
else { restartGame();
}
}
// OPTIONS METHOD
public void theOptions () {
System.out.println("What would you like to do?");
System.out.println("Choose 'eat', 'sleep', 'walk' or 'Q' to quit");
userAnswer = input.next();
if ( userAnswer.equalsIgnoreCase("eat")) {
eat();
theOptions();
}
else if ( userAnswer.equalsIgnoreCase("walk")) {
System.out.println("How far should I walk?");
userNumber = input.nextDouble();
while (userNumber <= 4.5) {
if (userNumber >= 3.0){
System.out.println("WALKING. . .");
try {Thread.sleep(6000);}
catch (Exception e) {}
}
else {
System.out.println("WALKING. . .");
try {Thread.sleep(6000);}
catch (Exception e) {}
}
theOptions();
}
}
else if (userAnswer.equalsIgnoreCase("sleep")) {
sleep();
}
else if (userAnswer.equalsIgnoreCase("Q")) {
System.out.println("See you next time, goodbye!");
System.exit(0);
}
else {
System.out.println("Please choose an activity for your pet");
System.out.println(theHealth);
theOptions();
}
}
// CHOOSE PET METHOD
public void petOptions () {
System.out.println("What Pet would you like?");
System.out.println("Choose 'puppy', 'fishy' or 'Q' to quit");
userAnswer = input.next();
if ( userAnswer.equalsIgnoreCase("puppy")) {
System.out.println("Please choose a name for your pup");
userAnswer = input.next();
Puppy myPup = new Puppy(userAnswer);
myPup.getAge();
theOptions();
}
else if (userAnswer.equalsIgnoreCase("fishy")) {
System.out.println("Please choose a name for your fish");
userAnswer = input.next();
Fish myFish = new Fish(userAnswer);
myFish.getAge();
theOptions();
}
else if (userAnswer.equalsIgnoreCase("Q")) {
System.out.println("See you next time, goodbye!");
System.exit(0);
}
//else if ( userAnswer.equalsIgnoreCase("birdy")) {}
else {
System.out.println("Please choose a pet");
petOptions();
}
}
/* ----------------------------------------------------------------------------------------------*/
// SLEEP METHOD
public void sleep () {
theHealth++;
checkHealth(); System.out.println("Goodnight");
restartGame();
}
// EAT METHOD
public void eat () {
System.out.println("I'm hungry, let me have a snack please");
System.out.println("Choose YES or NO");
userAnswer = input.next();
if ( userAnswer.equalsIgnoreCase("yes")) {
checkFunds();
theHealth++; System.out.println(theHealth);
checkHealth(); theOptions();
}
else if (userAnswer.equalsIgnoreCase("no")) {
theHealth--; System.out.println(theHealth);
checkHealth(); theOptions();
}
else {
checkHealth(); theOptions();
}
}
// WALK METHOD
public int walk (int theMiles) {
theHealth++; System.out.println(theHealth);
int petExcercise = theMiles;
return petExcercise;
}
}