#I need help figuring out why my test code doesn't work
26 messages ยท Page 1 of 1 (latest)
โ This post has been reserved for your question.
Hey @wraith bronze! Please use
/closeor theClose Postbutton above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically marked as dormant after 300 minutes of inactivity.
TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.
Please format your code to make it more readable.
For java, it should look like this:
```โโโ`โjava
public void foo() {
}
โโโ`โ```
Why are using an endless loop here?
๐ค Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived.
If your question was not answered yet, feel free to re-open this post or create a new one.
In case your post is not getting any attention, you can try to use/help ping.
Warning: abusing this will result in moderative actions taken against you.
Scanner.next() gets the next word separated by whitespace. If the answer is a phrase it will never match the full string
๐ค Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived.
If your question was not answered yet, feel free to re-open this post or create a new one.
In case your post is not getting any attention, you can try to use/help ping.
Warning: abusing this will result in moderative actions taken against you.
That's not a reason to put an infinite loop. Don't do things without a reason.
Start from what you know, and extend.
if u want the user to try guessing the correct answers infinetely then yea u need an infinite loop
but it shouldnt be inside the for loop
should be outside
i gave up on my initual attempt and continued with the video for the solution that was way diffrent than what i was doing but when i typed everything to match what was in the video it still doesn't function properly
here is the new code and what happens when i run it
import java.util.Scanner;
public class Main93 {
public static void main(String[] args) {
String[] questions = new String[5];
questions[0] = "What is The_Sandwich's favorite candy on 12-2-2024??";
questions[1] = "What does The_Sandwich want for Christmas????";
questions[2] = "What is The_Sandwich's favorite snack??";
questions[3] = "Best drink in the world??";
questions[4] = "Who is referred to as a beverage of sort??";
String[] answers = new String[5];
answers[0] = "Sour Patch";
answers[1] = "Gummies";
answers[2] = "Peanuts";
answers[3] = "Water";
answers[4] = "Future Trunks";
Scanner scanner = new Scanner(System.in);
int points = 0;
while (true) {
printTitle();
for (int i = 0; i < questions.length; i++) {
printQuestion(questions[i]);
String userAnswer = scanner.next();
if(isCorrectAnswer(userAnswer, answers[i])) {
printYouHadCorrect();
points = increasePointTotal(points);
printCurrentPoints(points);
} else {
printYouHadIncorrect();
printTheCorrectAnswer(answers[i]);
}
}
printPointTotal(points);
printPlayAgain();
if (scanner.next().equals("Y")) {
points = 0;
continue;
} else {
break;
}
} ```
printGoodbye();
This message has been formatted automatically. You can disable this using /preferences.
If you are finished with your post, please close it.
If you are not, please ignore this message.
Note that you will not be able to send further messages here after this post have been closed but you will be able to create new posts.
} ```java
public static void printTitle() {
System.out.println("SIGMAS-TRIAL");
}
public static int increasePointTotal(int points) {
return points + 1;
}
public static void printCurrentPoints(int points) {
System.out.println("You currently have " + points + " Sigma Points!");
}
public static void printPlayAgain() {
System.out.println("Do you want to test you're sigma again? Y / N");
}
public static void printPointTotal(int points) {
System.out.println("You had " + points + " Sigma Points!");
}
public static void printGoodbye() {
System.out.println("Thank you very much for Testing you're Sigma!!");
}
public static void printQuestion(String question) {
System.out.println(question);
}
public static boolean isCorrectAnswer(String userAnswer, String realAnswer) {
return userAnswer.equals(realAnswer);
}
public static void printYouHadCorrect() {
System.out.println("That was the Correct Answer!");
}
public static void printYouHadIncorrect() {
System.out.println("That was the Incorrect answer");
}
public static void printTheCorrectAnswer(String realAnswer) {
System.out.println("The correct answer was " + realAnswer);
}
} ```
This message has been formatted automatically. You can disable this using /preferences.
sorry for it being 3 texts but there was a limit
SIGMAS-TRIAL
What is The_Sandwich's favorite candy on 12-2-2024??
Sour Patch
That was the Incorrect answer
The correct answer was Sour Patch
What does The_Sandwich want for Christmas????
That was the Incorrect answer
The correct answer was Gummies
What is The_Sandwich's favorite snack??
Peanuts
That was the Correct Answer!
You currently have 1 Sigma Points!
Best drink in the world??
Water
That was the Correct Answer!
You currently have 2 Sigma Points!
Who is referred to as a beverage of sort??
Future Trunks
That was the Incorrect answer
The correct answer was Future Trunks
You had 2 Sigma Points!
Do you want to test you're sigma again? Y / N
Thank you very much for Testing you're Sigma!!
Process finished with exit code 0
this is how it ran when i only typed the correct answer
i don't know why it skips questions and works sometimes but not all the time
in other runs the final input of "Y" would return the code the the start of the test
๐ค Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived.
If your question was not answered yet, feel free to re-open this post or create a new one.
In case your post is not getting any attention, you can try to use/help ping.
Warning: abusing this will result in moderative actions taken against you.
Before your post will be closed, would you like to express your gratitude to any of the people who helped you? When you're done, click I'm done here. Close this post!.