All pastes #763092 Raw Edit

f

public java v1 · immutable
·published 2007-11-06 03:57 UTC
rendered paste body
import javax.swing.*;import java.util.Date;/* * produce an academic transcript * * COMP 1010 Section A02 * Instructor:  Domaratzki * Assignment:  Assignment 3, Question 1 * @author:     Nick Ratuski * @version:    1.0 - 2007-October */public class Ratuski_Nicholas_A3Q1 {    /*     * PURPOSE: produce an academic transcript based on input given by user.     */         //Method to find amount of students to process     public static int getStudentAmount() {    	int amount;   //# of students to process    	String temp;  //temporary input string    	    	 //get input        temp = JOptionPane.showInputDialog        ("Enter the number of students to process (between 1 and 10).");        amount = Integer.parseInt(temp);                if (amount > 10 || amount < 1) {        	//user input invalid, retrieve it again        	getStudentAmount();	        }        return amount;    }        //Since java doesn't have array.hasValue, i'll make a method for it myself.    //Method to return true if an array contains item.    public boolean hasValue(String table[], String item) {    	int length = table.getLength();    	for ( int i=0; i<length; i++ ) {    		if (table[i].equals(item)) {    			//Found the item in the table.    			return true;    		}    	}    	//The loop never found any matches, return false.    	return false;    }         public static void main (String [] args) {        String temp;                           //temporary input string        String name;                           //student name        String studentID;                      //student ID        String course;                         //course name        String grade;                          //letter grade        int number;                            //number of classes being taken.        int total;                             //running total        int amount;                            //# of students to process        boolean addGrades;                     //boolean flag to allow entering of grades                //corresponding letter and number grades        String[] letterGrades = new String[]{"A+","A","B+","B","C+","C","D","F"};        int[] numberGrades = new int[]{4.5,4.0,3.5,3.0,2.5,2.0,1.0,0};        amount = getStudentAmount();        //find how many students need processing        //confirm input        System.out.println ("You have entered " + amount + " students to process.");                for ( int i=0; i<amount; i++ ) {        	addGrades = true;        	temp = JOptionPane.showInputDialog        	("Enter the student number and name. (ex. 1234567Doe, Jane)");        	name = temp.substring(7);        	studentID = temp.substring(0,7);        	      		System.out.println("Transcript for: " + name + " " + studentID);        	total = 0;        	number = 0;        	        	while (addGrades == true) {        		temp = JOptionPane.showInputDialog        		("Enter a course ID and grade. (ex. COMP1010C+)");        		course = temp.substring(0,8);        		grade = temp.substring(8);        		if (temp.equals("EXIT") || temp.equals("exit")) {        			//end the while loop, they're exiting.        			addGrades = false;        			break;        		}        		for ( int i=0; i<7; i++ ) {        			if (grade.toUpperCase().equals(letterGrades[i])) {        				//Their course and grade are valid.        				System.out.println(course + " " + grade.toUpperCase());        				total = total + numberGrades[i];        				number++;        			}        		}        	}        	//print the GPA.        	System.out.println("GPA for " + name + ": " + total/number);        }    System.out.println("\nProgrammed by Nick Ratuski");   	System.out.println("Date: Saturday, November 3");   	System.exit(0);}