GradeHandlerNonOO

GradeHandlerNonOO -...

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

View Full Document Right Arrow Icon
/* * This program handles student grades * * However, it does it in a non-Object-Oriented way * it uses coordinated arrays, like you did in your last * JavaScript assignment * * We will develop an OO version, the right way, with classes * specifically a class for Student */ import java.io.*; // Import all classes in java.io package. Saves typing. // the BufferedReaderClass we will use for keyboard // input is in this package public class GradeHandlerNonOO { p public static void main(String[] args) throws IOException { String line; // to hold user keyboard input double num = 0; // to hold the number converted from user input int i; int MAX; BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); MAX = Integer.parseInt(args[0]); if (MAX <= 0) { System.out.println("command line needs to be positive integer"); return; } return; } double[] grade1; grade1 = new double[MAX]; double[] grade2; grade2 = new double[MAX]; double[] grade3; grade3 = new double[MAX]; String[] name = new String[MAX]; for (i=0; i<name.length; i++) {
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(&amp;quot;Student name? &amp;quot;); line = in.readLine(); if ( line.equals(&amp;quot;quit&amp;quot;) || line.equals(&amp;quot;q&amp;quot;) ) { break; } name[i]= line; System.out.println(&amp;quot;grade 1? &amp;quot;); line = in.readLine(); num = Double.parseDouble(line); grade1[i] = num; System.out.println(&amp;quot;grade 2? &amp;quot;); line = in.readLine(); num = Double.parseDouble(line); grade2[i] = num; System.out.println(&amp;quot;grade 3? &amp;quot;); line = in.readLine(); num = Double.parseDouble(line); grade3[i] = num; }// end for printArray(grade1); System.out.println(); printArray(grade2); System.out.println(); printArray(grade3); System.out.println(); System.out.println(&amp;quot;Largest grade, exam 1: &amp;quot;+ highest(grade1)); }// end main method public static void printArray (double arr) { int i; for (i=0; i&amp;lt;arr.length; i++) { System.out.print(arr[i]+&amp;quot;, &amp;quot;); } return; } public static double highest (double grades) { double big = 0; int i; for (i=0; i&amp;lt;grades.length; i++) { if (grades[i]&amp;gt; big) { big = grades[i]; } } return big; } } // end class...
View Full Document

Page1 / 2

GradeHandlerNonOO -...

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