-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchallenge4.java
More file actions
219 lines (217 loc) · 8.81 KB
/
challenge4.java
File metadata and controls
219 lines (217 loc) · 8.81 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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
/**
* Write a description of class challenge4 here.
*
* @author (Kate V.)
* @version (June 1st, 2020)
*/
import java.util.Scanner;
public class challenge4
{
public static void main()
{
System.out.println("As you finish a call with Thomas, you see a poster that challenges you to test your knowledge in Java.\n You decide to do it since it’s also has a Cicada logo, which means it’s one of their challenges.");
System.out.println("Is String immutable? type yes or no");
Scanner questions = new Scanner(System.in);
String oneAns = questions.nextLine();
while(!oneAns.equals("yes"))
{
if(oneAns.equals("exit"))
{
System.exit(1);
}
else if(oneAns.equals("help"))
{
if(Hints.getnumOfHints() != 0)
{
System.out.println("Can you change the String and characters in that String?");
Hints.numOfHints--;
oneAns = questions.nextLine();
}
else
{
System.out.println("Sorry, but you ran out of hints. Good luck!");
oneAns = questions.nextLine();
}
}
else
{
System.out.println("Sorry, but the answer is incorrect. Try again!");
oneAns = questions.nextLine();
}
}
System.out.println("Can you change 1-D Array or 2-D Array? Type yes or no");
String twoAns = questions.nextLine();
while(!twoAns.equals("no"))
{
if(twoAns.equals("exit"))
{
System.exit(1);
}
else if(twoAns.equals("help"))
{
if(Hints.getnumOfHints() != 0)
{
System.out.println("Can you remove and change the number of “slots” in an Array? (Not Array List)");
Hints.numOfHints--;
twoAns = questions.nextLine();
}
else
{
System.out.println("Sorry, but you ran out of hints. Good luck!");
twoAns = questions.nextLine();
}
}
else
{
System.out.println("Sorry, but the answer is incorrect. Try again!");
twoAns = questions.nextLine();
}
}
System.out.println("What is the data type of a number would you get when you divide (/) int by a double?");
String threeAns = questions.nextLine();
while(!threeAns.equals("double"))
{
if(threeAns.equals("exit"))
{
System.exit(1);
}
else if(threeAns.equals("help"))
{
if(Hints.getnumOfHints() != 0)
{
System.out.println("What data type you get when you divide 2 doubles? Same thing here");
Hints.numOfHints--;
threeAns = questions.nextLine();
}
else
{
System.out.println("Sorry, but you ran out of hints. Good luck!");
threeAns = questions.nextLine();
}
}
else
{
System.out.println("Sorry, but the answer is incorrect. Try again!");
threeAns = questions.nextLine();
}
}
System.out.println("Can you call a static method without writing a class’s name before it? type yes or no");
String fourAns = questions.nextLine();
while(!fourAns.equals("no"))
{
if(fourAns.equals("exit"))
{
System.exit(1);
}
else if(fourAns.equals("help"))
{
if(Hints.getnumOfHints() != 0)
{
System.out.println("Think of what word “static” in Java means and how is it different from a non-static class");
Hints.numOfHints--;
fourAns = questions.nextLine();
}
else
{
System.out.println("Sorry, but you ran out of hints. Good luck!");
fourAns = questions.nextLine();
}
}
else
{
System.out.println("Sorry, but the answer is incorrect. Try again!");
fourAns = questions.nextLine();
}
}
System.out.println("What are 3 main pieces of codes a Java Class generally have?");
String fiveAns = questions.nextLine();
boolean isCorrect = false;
while(isCorrect != true)
{
if(fiveAns.indexOf("fields") != -1 && fiveAns.indexOf("constructor") != -1 && fiveAns.indexOf("methods") != -1)
{
isCorrect = true;
}
else if(fiveAns.equals("exit"))
{
System.exit(1);
}
else if(fiveAns.equals("help"))
{
if(Hints.getnumOfHints() != 0)
{
System.out.println("One of them is fields");
Hints.numOfHints--;
fiveAns = questions.nextLine();
}
else
{
System.out.println("Sorry, but you ran out of hints. Good luck!");
fiveAns = questions.nextLine();
}
}
else if(fiveAns.indexOf("fields") == -1 || fiveAns.indexOf("constructor") == -1 || fiveAns.indexOf("methods") == -1)
{
System.out.println("Sorry, but the answer is incorrect. Try again!");
fiveAns = questions.nextLine();
}
}
System.out.println("What method do you use to compare 2 Strings?");
String sixAns = questions.nextLine();
while(sixAns.indexOf("equals") == -1)
{
if(sixAns.equals("exit"))
{
System.exit(1);
}
else if(sixAns.equals("help"))
{
if(Hints.getnumOfHints() != 0)
{
System.out.println("Look at Java Quick Reference Guide");
Hints.numOfHints--;
sixAns = questions.nextLine();
}
else
{
System.out.println("Sorry, but you ran out of hints. Good luck!");
sixAns = questions.nextLine();
}
}
else
{
System.out.println("Sorry, but the answer is incorrect. Try again!");
sixAns = questions.nextLine();
}
}
System.out.println("How does a method called, that just returns a private field?");
String sevenAns = questions.nextLine();
while(sevenAns.indexOf("accessor") == -1)
{
if(sevenAns.equals("exit"))
{
System.exit(1);
}
else if(sevenAns.equals("help"))
{
if(Hints.getnumOfHints() != 0)
{
System.out.println("What you do, is accessing the field. The name of that method comes from the word “access”");
Hints.numOfHints--;
sevenAns = questions.nextLine();
}
else
{
System.out.println("Sorry, but you ran out of hints. Good luck!");
sevenAns = questions.nextLine();
}
}
else
{
System.out.println("Sorry, but the answer is incorrect. Try again!");
sevenAns = questions.nextLine();
}
}
System.out.println("Cool! \nAfter sending all your answers, you are getting a message from your buddy, saying to go to a school field for practice.");
}
}