i worked on a little multiple choice programm as seen here
import java.util.Arrays;
import java.util.Scanner;
public class logic {
public static void main(String[] args) {
String question = "Welche Fabe hat der Frosch?"; //Your Question here
//Possible Answers
String a = "Gelb";
String b = "Rot";
String c = "Grün";
String correct = "c"; //Right Answer
String [] arr = new String[5];
arr[0] = question;
arr[1] = a;
arr[2] = b;
arr[3] = c;
arr[4] = correct;
System.out.println(arr[0] + "\n");
System.out.println("Answer a: " + arr[1]);
System.out.println("Answer b: " + arr[2]);
System.out.println("Answer c: " + arr[3] + "\n");
int i = 0;
while (i != 1) {
Scanner userin = new Scanner(System.in);
System.out.println("Type a,b,c for correct answer.\n");
String selected = userin.next();
if (selected.equals(correct)) {
i = 1;
System.out.println("\nCorrect!");
}else {
System.out.println("Try again");
}
}
}
}
I thought i could create a class based on that. And that's were the trouble starts.
This is what i got so far.
import java.util.Scanner;
public class MultipleChoice {
private String question, a, b, c, correct;
public void setQuestion(String question) {
this.question = question;
}
public void setA(String a) {
this.a = a;
}
public void setB (String b) {
this.b = b;
}
public void setC (String c) {
this.c = c;
}
public void setCorrect (String correct) {
this.correct = correct;
}
String[] arr = new String[5];
arr[0] = question;
arr[1] = a;
arr[2] = b;
arr[3] = c;
arr[4] = correct;
System.out.println(arr[0] + "\n");
System.out.println("Answer a: " + arr[1]);
System.out.println("Answer b: " + arr[2]);
System.out.println("Answer c: " + arr[3] + "\n");
int i = 0;
while (i != 1) {
Scanner userin = new Scanner(System.in);
System.out.println("Type a,b,c for correct answer.\n");
String selected = userin.next();
if (selected.equals(correct)) {
i = 1;
System.out.println("\nCorrect!");
}else {
System.out.println("Try again");
}
}
}
}
When i try to create the Array i get the error "Syntax error on token ";", { expected after this token".
I'm relative new to Java.
Thanks in advance