'F' → Fullscreen
import java.util.Scanner;
public class Program{ public static void main(String[] args) { // Task 1 — Numeric App: Student Score Analyzer (Parallel Arrays) // // You are given two parallel arrays: // - names[i] goes with scores[i] // // Your job: // 1) Print a roster (each student + score) // 2) Compute and print the class average // 3) Find and print the highest score AND the student's name // 4) Count and print how many students are passing (>= 70) // 5) Ask the user for a name and print that student's score (or "Not found")
String[] names = {"Ava", "Ben", "Chris", "Dina", "Eli"}; int[] scores = {88, 73, 95, 67, 81};
// 1) Print roster System.out.println("Roster:"); for (int i = 0; i < names.length; i++) { System.out.println(names[i] + ": " + scores[i]); }
// 2) Average int sum = 0; for (int i = 0; i < scores.length; i++) { sum += scores[i]; } double avg = (double) sum / scores.length; System.out.println("Average: " + avg);
// 3) Highest score + name int bestIndex = 0; for (int i = 1; i < scores.length; i++) { if (scores[i] > scores[bestIndex]) { bestIndex = i; } } System.out.println("Top student: " + names[bestIndex]); System.out.println("Top score: " + scores[bestIndex]);
// 4) Count passing (>= 70) int passing = 0; for (int i = 0; i < scores.length; i++) { if (scores[i] >= 70) { passing++; } } System.out.println("Passing count: " + passing);
// 5) Search by name Scanner scanner = new Scanner(System.in); System.out.print("Enter a student name to look up: "); String targetName = scanner.nextLine();
int index = -1; for (int i = 0; i < names.length; i++) { if (names[i].equals(targetName)) { index = i; } }
if (index == -1) { System.out.println("Not found."); } else { System.out.println(targetName + "'s score: " + scores[index]); }
scanner.close(); }}equalsIgnoreCase. import java.util.Scanner;
public class Program{ public static void main(String[] args) { // Task 2 — Quiz App: Question + Answer Parallel Arrays // // You are given two parallel arrays: // - questions[i] goes with answers[i] // // Your job: // 1) Ask each question // 2) Compare the user's answer to the correct answer (case-insensitive) // 3) Keep score and print the final result // // Notes: // - Use equalsIgnoreCase(...) for comparison // - Print "Correct!" or "Incorrect. The answer was ___"
String[] questions = { "What is 2 + 2?", "What keyword starts a for loop in Java?", "What is the first index in an array?", "True/False: Arrays can change size after creation." };
String[] answers = { "4", "for", "0", "false" };
Scanner scanner = new Scanner(System.in); int correct = 0;
System.out.println("Quiz Time!"); System.out.println("----------");
for (int i = 0; i < questions.length; i++) { System.out.println("Q" + (i + 1) + ": " + questions[i]); System.out.print("Your answer: "); String user = scanner.nextLine();
if (user.equalsIgnoreCase(answers[i])) { System.out.println("Correct!"); correct++; } else { System.out.println("Incorrect. The answer was: " + answers[i]); }
System.out.println(); }
System.out.println("Final Score: " + correct + " / " + questions.length);
scanner.close(); }}Your program output should something similar to the sample output below.
Roster:Ava: 88Ben: 73Chris: 95Dina: 67Eli: 81Average: 80.8Top student: ChrisTop score: 95Passing count: 4Enter a student name to look up: DinaDina's score: 67
Quiz Time!----------Q1: What is 2 + 2?Your answer: 4Correct!
Q2: What keyword starts a for loop in Java?Your answer: forCorrect!
Q3: What is the first index in an array?Your answer: 1Incorrect. The answer was: 0
Q4: True/False: Arrays can change size after creation.Your answer: falseCorrect!
Final Score: 3 / 4You may write your reflection answers as comments at the bottom of your code.
-1 mean in a search algorithm?Submit your activity and reflection answers to the appropriate dropbox.