My first post. Trying to help my daughter with her AP CompSci course in HS. She has some labs to do and I have been doing them as well but I am stumped on one for three days now. She may be able to do it when she gets to it but I want to be able to do it to, plus if she runs into issues I can point her in the right direction. I don't want to be spoon feed or give her the answer she needs to think about it. I have done about 6 labs now. The one I am stumped on is creating a multiple choice test with 10 questions. I have searched for examples but the solutions all seem outside of the teacher provided notes for this chapter. I need a solution that works for a beginner with 3 weeks instruction.
Here is what I have:
import java.util.Scanner; public class multiChoiceTest { public static void main(String[] args) { Scanner keyboard=new Scanner(System.in); System.out.print("---Multiple Choice Test. CHEATERS WILL GET AN 'F'---\n\n"); System.out.print("---Choose the best answer---\n\n"); System.out.print("1.) What is the state capitol of California?\n\n"); System.out.print("A. San Diego\n"); System.out.print("B. San Francisco\n"); System.out.print("C. Sacramento\n"); System.out.print("D. Vista\n"); System.out.print("E. Oceanside\n\n"); System.out.print ("Enter your selection: "); //I think the next line should be a "string" instead of "int" so I can accept a "C" input from the user. The correct line below is what I am struggling with. So I can match it to an if statement int question1=keyboard.nextByte(); if(question1==C) //been having issues getting an if statement to match the question1 input. Don't think I care if they got the wrong answer. { int q1points=10; } //then I will figure out how to make it go to the next question. Assume next question goes under closing brace of the if statement. //at the end I will add up the points and provide a grade result. I got that part covered. Previous labs } }
My challenge in finding help is I have only been given the teachers notes and examples in the forum here and on the net are to complicated for where we are at. So I assume the labs must be related to what was taught. I completed the other labs this way. So I was hoping someone could spot what is wrong and point me in the right direction based on his notes.
Unit 3 notes include basic int and double labs
Unit 4 Notes included:
Comparison operators
Comparing Objects
Conjunction Operators (&& ||)
De Morgans Law
Yoda Notation
Selection Statements (if and else if)
Nesting Selection Statements
and Random numbers
Any help appreciated. Thank you in advance.
--- Update ---
More specific question. How would you store the users response (hopefully a single character and capitalized) and then match it on an if statement. Do I use a string, char, int, something else? I might be able to figure out the if statement if I know I was storing the input from the user correctly. I did a lab like this one but it was matching numbers not letters. If I store the input as a char or string then I have issues matching it on the if statement.