Quizzes - System.out.print ("Enter the number of...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
//****************************************************************** // Quizzes.java // // Grades multiple choice quizzes. //****************************************************************** import java.util.Scanner; import java.text.NumberFormat; public class Quizzes { //---------------------------------------------- // Read in the number of questions followed by // the key, then read in each student's answers // and calculate the number and percent correct. //---------------------------------------------- public static void main(String[] args) { int numQuestions; int numCorrect; String anotherQuiz; int answer; NumberFormat percent = NumberFormat.getPercentInstance(); Scanner scan = new Scanner (System.in); System.out.println ("Quiz Grading"); System.out.println ();
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: System.out.print ("Enter the number of questions on the quiz: "); numQuestions = scan.nextInt(); int key = new int[numQuestions]; System.out.print ("Enter the answer key: "); for (int i = 0; i < numQuestions; i++) key[i] = scan.nextInt(); do { numCorrect = 0; System.out.print("Enter the student answers: "); for (int i = 0; i < numQuestions; i++) { answer = scan.nextInt(); if (answer == key[i]) numCorrect++; } System.out.println (numCorrect + " correct for a grade of " + percent.format((double)numCorrect/numQuestions)); System.out.println(); System.out.print ("Grade another quiz (y/n)? "); anotherQuiz = scan.next(); System.out.println(); } while (anotherQuiz.equalsIgnoreCase("y")); } }...
View Full Document

This note was uploaded on 03/22/2010 for the course CS 202 taught by Professor Fong during the Spring '10 term at SIU Carbondale.

Page1 / 2

Quizzes - System.out.print ("Enter the number of...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online