/* * File: Grader.java * Author: Java, Java, Java * Description: This application program illustrates the use of * methods in the java.io.BufferedReader class to perform simple I/O operations * for a keyboard/console interface. An instance (object) of the BufferedReader * class is created, and it handles the input task for the program. * The program prompts the user to input 3 exam grades. * It reads the grades, and then computes and reports the exam average. Note * the use of the Integer.parseInt() method to convert the input strings into * integers (ints). */ import java.io.*; // Java I/O classes public class Grader { public static void main(String argv[]) throws IOException { BufferedReader input = new BufferedReader (new InputStreamReader(System.in)); String inputString; int midterm1, midterm2, finalExam; // Three exam grades float sum; // The sum of the 3 grades System.out.print("Input your grade on the first midterm: "); // Prompt inputString = input.readLine(); // Read a String midterm1 = Integer.parseInt(inputString); // Convert the String to an int System.out.println("You input: " + midterm1); // Echo what the user input System.out.print("Input your grade on the second midterm: "); inputString = input.readLine(); midterm2 = Integer.parseInt(inputString); System.out.println("You input: " + midterm2); System.out.print("Input your grade on the final exam: "); inputString = input.readLine(); finalExam = Integer.parseInt(inputString); System.out.println("You input: " + finalExam); sum = midterm1 + midterm2 + finalExam; // Compute and report the average System.out.print("Your average in this course is "); System.out.println(sum/3); // Divide sum by 3 for the average } // main() } // Grader