GradingProgram

GradingProgram - largest average invalid * 0 5 19 -1 0 19 8...

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

View Full Document Right Arrow Icon
import java.util.Scanner; /* * Name:Xin Chi * Section:004 * Program 5 - Grading Program * * *Implementation Plan * 0. Download skeleton. * 1. Print message to ask for input numbers. * 2. Design a loop to obtain input numbers. * 3. End the program, when the input is a negative integer. * 4. Identify invalid numbers and print out notifications.(invalid numbers are not used for calculation) * 5. Design "If" statements to: * a. Determine the largest number among these input numbers * b. Determine the smallest number among these input numbers * c. Determine the average value of these input numbers * 6. Print out the final result. * ** Test Plan * Idea - the GradingProgram should be able to identify: * 1).the smallest value (especially 0). * 2).the largest value (especially 100). * 3).be able to identify invalid values and continue on to read the next number. * 4). give out correct average value. * Tests * input smallest
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: largest average invalid * 0 5 19 -1 0 19 8 N/A * 3 20 100 -1 3 100 41 N/A * 2 200 10 -1 2 10 6 200 * */ public class GradingProgram { public static void main(String args) { int grade = 0; double averageGrade = 0.0; System.out.println("Enter a nonnegative integer (negative to stop): "); Scanner keyboard = new Scanner(System.in); int n; n = keyboard.nextInt(); int max; int min; int count; count = 0; if (0 <= n) { max = min = n; while (0 <= n) { { while (n > 100) { System.out.println(n + "!!! Invalid value"); n = keyboard.nextInt(); } grade = grade + n; count = count + 1; if (n > max) max = n; if (n < min) min = n; n = keyboard.nextInt(); if (n < 0) { averageGrade = (double) grade / count; System.out.println("The largest value is" + max); System.out.println("The smallest value is" + min); System.out.println("The average value is" + averageGrade); } } } } } }...
View Full Document

This note was uploaded on 06/10/2011 for the course COMP 110 taught by Professor Stotts during the Spring '08 term at UNC.

Page1 / 2

GradingProgram - largest average invalid * 0 5 19 -1 0 19 8...

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