Programming Assignment 1
CS 1102-1 Programming 1
9 February 2024
Program Code
import java.util.Scanner;
//Scanner class is a util import that is used to get user input
class MakeAQuiz {
public static void main(String[] args) {
Scanner scan = new Scanner (System.in);
//scannner will take user input for the responses
String[] correct = {"b", "b", "b", "b", "c"};
//array containing the correct answers
String[] answers = {"", "", "", "", ""};
//array that stores user's responses
System.out.println("Who was the first man on the moon?");
System.out.println("a. Buzz Aldrin");
System.out.println("b. Neil Armstrong");
System.out.println("c. Louis Armstrong");
System.out.println("d. Trick question. The moon landing was faked");
//question 1
System.out.println("Which of the following is not a pasta?");
System.out.println("a. conchiglie");
System.out.println("b. boticelli");
System.out.println("c. spaghetti");
System.out.println("d. rigatoni");
//question 2
System.out.println("Select the statement that is true.");
System.out.println("a. None are true");
System.out.println("b. One is true");
System.out.println("c. The option before this one is false");
System.out.println("d. The option before this one is true");
//question 3
System.out.println("Thou shall not pass is the 11th commandment");
System.out.println("a. True");
System.out.println("b. False");
System.out.println("c. Fly you fools");
System.out.println("d. A balrog is a valar");
//question 4
System.out.println("How many of these choices are true?");
System.out.println("a. One is true");
System.out.println("b. Two are true");
System.out.println("c. Three are true");
System.out.println("d. None are true");
//question 5
answers[0] = scan.next();
answers[1] = scan.next();
answers[2] = scan.next();
answers[3] = scan.next();
answers[4] = scan.next();
//assigns the chronological order of recorded responses; starts with 0 as per Java
conventions
int Score = 0;
//assigns variable called "Score" as an integer
for (int i = 0; i<5; i++) {
if (answers[i].equalsIgnoreCase(correct[i])) {
Score++;
}
}
//for loop that checks if the responses match the answer key and adds 1 for every correct
response
//if statement added to ignore uppercase/lowercase distinction for responses
System.out.println("Score is = " +Score+"/5");
//prints the resulting value "Score", which indicates the user's final score
}
}
Screenshots