Empty prompt
Lesson 14....
The author has a tendency to have to write stuff half way and complete it, clean it up later in the lesson. In the beginning of this lesson you create a new promptForYesNo(), that has it's own prewritten prompt in a while loop.
The thing I find odd is that you have to give a prompt in the function call to make it run properly, but that prompt will not be used at all. I'll copy and paste the code and highlight what I'm talking about. It seems like a waste somehow, but I can see how having a function to just ask to continue would be useful, but if you want to change the prompt, you have to change it in the method's while loop, and not in the class you're importing the method too.
Maybe this will be addressed later, will update.
MasterMind class method:
public WordMastermind() {
boolean repeat = true;
while(repeat) {
print("Hello!");
repeat = promptForYesNo(""); Whatever you put into the prompt will not change the prompt in the imported method.
}
}
public static void main(String[] args) {
new WordMastermind();
}
MyWindow class method that is being imported:
protected boolean promptForYesNo(String prompt) {
boolean yes = true;
boolean valid = false;
while(!valid) {
String YorN = promptForString("repeat? Y or N:");
switch (YorN) {
case "Y":
case "y":
yes = true;
valid = true;
break;
case "N":
case "n":
yes = false;
valid = true;
break;
default:
print("Enter Y for yes, N for no");
valid = false;
}
}
return yes;
}
The author has a tendency to have to write stuff half way and complete it, clean it up later in the lesson. In the beginning of this lesson you create a new promptForYesNo(), that has it's own prewritten prompt in a while loop.
The thing I find odd is that you have to give a prompt in the function call to make it run properly, but that prompt will not be used at all. I'll copy and paste the code and highlight what I'm talking about. It seems like a waste somehow, but I can see how having a function to just ask to continue would be useful, but if you want to change the prompt, you have to change it in the method's while loop, and not in the class you're importing the method too.
Maybe this will be addressed later, will update.
MasterMind class method:
public WordMastermind() {
boolean repeat = true;
while(repeat) {
print("Hello!");
repeat = promptForYesNo(""); Whatever you put into the prompt will not change the prompt in the imported method.
}
}
public static void main(String[] args) {
new WordMastermind();
}
MyWindow class method that is being imported:
protected boolean promptForYesNo(String prompt) {
boolean yes = true;
boolean valid = false;
while(!valid) {
String YorN = promptForString("repeat? Y or N:");
switch (YorN) {
case "Y":
case "y":
yes = true;
valid = true;
break;
case "N":
case "n":
yes = false;
valid = true;
break;
default:
print("Enter Y for yes, N for no");
valid = false;
}
}
return yes;
}
Comments
Post a Comment