Help with GradedBook

need help

  • (2 Pages)
  • +
  • 1
  • 2

17 Replies - 1051 Views - Last Post: 26 January 2009 - 10:09 PM Rate Topic: -----

#1 ProGraM  Icon User is offline

  • D.I.C Head

Reputation: 10
  • View blog
  • Posts: 150
  • Joined: 28-September 05

Help with GradedBook

Posted 20 January 2009 - 06:56 PM

This is what my program is supposed to do:

Enter students name, press enter. Superwiz
Enter students id, press enter. 66666
Enter 4 test scores, press enter. 90 92 94 96

Enter students name, press enter. Top Gun
Enter students id, press enter. #1
Enter 4 test scores, press enter. 50 40 60 30

Enter students name, press enter. Darth Vader
Enter students id, press enter. r2d2
Enter 4 test scores, press enter. 80 100 40 95

Enter students name, press enter. Rock n roll
Enter students id, press enter. Music
Enter 4 test scores, press enter. 87 85 78 83

Enter students name, press enter. Go Rams
Enter students id, press enter. %$#@!
Enter 4 test scores, press enter. 76 75 74 73

*** The Echo data follows ***
Student Name ID# Test Scores
Superwiz 66666 90 92 94 96
Top Gun #1 50 40 60 30
Darth Vader r2d2 80 100 40 95
Rock n roll Music 87 85 78 83
Go Rams %$#@! 76 75 74 73
The student Superwiz, 66666 had the highest average of 93
The student Top Gun, #1 had the lowest average of 25
The class average is: 74.9

*** The list with letter grades follows ***
Student Name ID# Total Score Letter
Superwiz 66666 93.0 A
Top Gun #1 45.0 F
Darth Vader r2d2 78.75 C
Rock n roll Music 83.25 B
Go Rams %$#@! 74.5 C

Type add, delete, ascend or descend, press enter: Ascend (account for all human errors)

***The Ascending list follows ***
Student Name ID# Total Score Letter
Top Gun #1 45.0 F
Go Rams %$#@! 74.5 C
Darth Vader r2d2 78.75 C
Rock n roll Music 83.25 B
Superwiz 66666 93.0 A

Type add, delete, ascend or descend, press enter: Descend (account for all human errors)

***The Ascending list follows ***
Student Name ID# Total Score Letter
Superwiz 66666 93.0 A
Rock n roll Music 83.25 B
Darth Vader r2d2 78.75 C
Go Rams %$#@! 74.5 C
Top Gun #1 45.0 F

Are you done, type a Yes or a No Yes or No, press enter? Y e z
Oh Divine one please type a Yes or No, try again, press enter! N o

Type add, delete, ascend or descend, press enter: add (account for all human errors)

Enter students name, press enter. Butch Jr.
Enter students id, press enter. fun
Enter 4 test scores, press enter. 5 10 0 85

*** The Echo data follows ***
Student Name ID# Test Scores
Superwiz 66666 90 92 94 96
Top Gun #1 50 40 60 30
Darth Vader r2d2 80 100 40 95
Rock n roll Music 87 85 78 83
Go Rams %$#@! 76 75 74 73
Butch Jr. fun 5 10 0 85
The student Superwiz, 66666 had the highest average of 93
The student Butch Jr., fun had the lowest average of 25
The class average is: 66

Type add, delete, ascend or descend, press enter: delete (account for all human errors)

Enter Students name, press return. Top Gun
Enter students ID, press return. #1

** The Echo data follows **
Student Name ID# Test Scores
Superwiz 66666 90 92 94 96
Darth Vader r2d2 80 100 40 95
Rock n roll Music 87 85 78 83
Go Rams %$#@! 76 75 74 73
Butch Jr. fun 5 10 0 85
The student Superwiz, 66666 had the highest average of 93
The student Butch Jr., fun had the lowest average of 25
The class average is: 70

**************************************************************
**************************************************************

This is what my program does:
Welcome to GradeBook !!
How many students do you have, Enter a number(1-10) and press return.
5

Enter students name, press enter. Superwiz
Enter students id, press enter. 66666
Enter 4 test scores, press enter. 90 92 94 96

Enter students name, press enter. Top Gun
Enter students id, press enter. #1
Enter 4 test scores, press enter. 50 40 60 30

Enter students name, press enter. Darth Vader
Enter students id, press enter. r2d2
Enter 4 test scores, press enter. 80 100 40 95

Enter students name, press enter. Rock n roll
Enter students id, press enter. Music
Enter 4 test scores, press enter. 87 85 78 83

Enter students name, press enter. Go Rams
Enter students id, press enter. %$#@!
Enter 4 test scores, press enter. 76 75 74 73

*** The Echo data follows ***
Student Name ID# Test Scores
Superwiz 66666 90 92 94 96
Top Gun #1 50 40 60 30
Darth Vader r2d2 80 100 40 95
Rock n roll Music 87 85 78 83
Go Rams %$#@! 76 75 74 73
The student with the highest grade is 0
The student with the lowest grade is 0


So i need help with getting the student with the highest and lowest averages then the class average...Then i need to create functions for ascending order, descending order, adding someone, deleting someone... Here's my code....

*****************************************************
 import java.util.*;
 import java.io.*;
 import java.text.DecimalFormat;
public class GradeBook 
{
	static int studCount = 0, numStudents, highStud, lowStud, studID;
	static int fourTests[][];
	static double testAvg[], classAvg;
	static String studName[], studentID[];
	public static void main(String[] args) throws IOException
	{
	 GradeBookStart();
	 StudentInfo(numStudents, studCount);
	 EchoData();
	 highGrade();
	 lowGrade();
	}
	public static void GradeBookStart() throws IOException
	{
		Scanner keyboard = new Scanner(System.in);
		System.out.println("Welcome to teachers GradeBook !!");
		System.out.println("How many students do you have? Enter a number(1-10) and press return. ");
		numStudents = keyboard.nextInt();
		studName = new String[numStudents];
		fourTests = new int[numStudents][4];
		studentID = new String[numStudents]; 
	}
	private static void StudentInfo(int numStudents, int studCount) throws IOException
	{
		do
		{
			Scanner keyboard = new Scanner(System.in);
			System.out.println("\nEnter students name, press enter.");
			studName[studCount] = keyboard.nextLine().trim();
			studName[studCount] = studName[studCount].replace(" ", "");
			System.out.println("enter students id, press enter.");
			studentID[studCount] = keyboard.nextLine().trim();
			studentID[studCount] = studentID[studCount].replace(" ", "");
			for(int i=0;i<4;i++)
			{
   				System.out.println("Enter test score #" + (i+1) + ", press enter");
				fourTests[studCount][i] = keyboard.nextInt();
			}
			studCount++;
		}while(studCount != numStudents);
	}
	private static void EchoData()
	{
		System.out.println("\n*** The Echo data Follows ***");
		System.out.println("Student Name\tID#\tTest Scores");
		for(int i = 0; i < numStudents; i++)
		{
		   System.out.print(studName[i] + "\t" + studentID[i] + "\t");
   			for(int j=0;j<4;j++)
   			{
	 		 System.out.print(fourTests[i][j] + " "); 
   			}
   		System.out.println();   		
		}
		System.out.println("The Student with the highest grade was " + highStud);
   		System.out.println("The Student with the lowest grade was " + lowStud);
	}
	private static int highGrade()
	{
		
		highStud = fourTests[0][0];
		for ( int studentGrades[] : fourTests )
		{
			for ( int grade : studentGrades )
			{
				if ( grade > highStud )
				highStud = grade;
			}
		}
		return highStud;
		
	}
	private static int lowGrade()
	{
	int lowStud = fourTests[ 0 ][ 0 ];

		for ( int studentGrades[] : fourTests )
		{
			for ( int grade : studentGrades )
			{
				if ( grade < lowStud )
				lowStud = grade;
			}
		}
		return lowStud;
	}
}

This post has been edited by ProGraM: 20 January 2009 - 07:45 PM


Is This A Good Question/Topic? 0
  • +

Replies To: Help with GradedBook

#2 BigAnt  Icon User is offline

  • May Your Swords Stay Sharp
  • member icon

Reputation: 101
  • View blog
  • Posts: 2,392
  • Joined: 16-August 08

Re: Help with GradedBook

Posted 20 January 2009 - 07:00 PM

Please edit your post to contain the ending code tag.
Was This Post Helpful? 0
  • +
  • -

#3 ProGraM  Icon User is offline

  • D.I.C Head

Reputation: 10
  • View blog
  • Posts: 150
  • Joined: 28-September 05

Re: Help with GradedBook

Posted 20 January 2009 - 07:46 PM

View PostBigAnt, on 20 Jan, 2009 - 07:00 PM, said:

Please edit your post to contain the ending code tag.



Sry bout that :P
fixed
Was This Post Helpful? 0
  • +
  • -

#4 BigAnt  Icon User is offline

  • May Your Swords Stay Sharp
  • member icon

Reputation: 101
  • View blog
  • Posts: 2,392
  • Joined: 16-August 08

Re: Help with GradedBook

Posted 20 January 2009 - 07:57 PM

Do you wish to print out the highest test grade or the Student with the highest test score?

You could create 2 nested for loops, the first one cycle through each student, the second one cycles through each student's scores. In the loop you can then check for higher/lower.

Now here if you want to print out the highest score, have the method return the highest score, and if you want to print out the Student, have the method return the index belonging to which student it is with the highest.lowest.
Was This Post Helpful? 0
  • +
  • -

#5 ProGraM  Icon User is offline

  • D.I.C Head

Reputation: 10
  • View blog
  • Posts: 150
  • Joined: 28-September 05

Re: Help with GradedBook

Posted 20 January 2009 - 08:09 PM

View PostBigAnt, on 20 Jan, 2009 - 07:57 PM, said:

Do you wish to print out the highest test grade or the Student with the highest test score?

You could create 2 nested for loops, the first one cycle through each student, the second one cycles through each student's scores. In the loop you can then check for higher/lower.

Now here if you want to print out the highest score, have the method return the highest score, and if you want to print out the Student, have the method return the index belonging to which student it is with the highest.lowest.


Yea i want to print out the person with the highest grade, their ID# and their test average.
This is what i got but it's not doing what i want

 private static int highGrade()
	{
	   
		highStud = fourTests[0][0];
		for ( int studentGrades[] : fourTests )
		{
			for ( int grade : studentGrades )
			{
				if ( grade > highStud )
				highStud = grade;
			}
		}
		return highStud;
	   
	}

so i need to change it to something like

private static int highGrade()
{
	   highStud = fourTest[0][0];
	  for(int r = 0; r < numStudents; i++)
	  {
		  for(int k = 0; k < highStud; k++)
		  {
			  for(int grade : highstud)
			  {
				  if ( grade > highStud)
				 {
					 highStud = grade;
				  }
			   }
		   }
	   }
		return highStud;
}


I know this isn't right but I have know idea of how to do it and this is my only guess...
Was This Post Helpful? 0
  • +
  • -

#6 BigAnt  Icon User is offline

  • May Your Swords Stay Sharp
  • member icon

Reputation: 101
  • View blog
  • Posts: 2,392
  • Joined: 16-August 08

Re: Help with GradedBook

Posted 20 January 2009 - 08:26 PM

What I would do, since you do not do anything with the return values, is just make the methods high/low print out the high and low, then from your echo data, instead of printing the the high and lows just call the methods. Then higher would look like:
    private static void highGrade()
    {
    	int index = 0;
    	int low = fourTests[0][0];
    	for(int i = 0; i < numStudents; i++){
    		for( int j = 0; j < 4; j++){
    			if(fourTests[i][j] > low){
    				index = i;
    				low = fourTests[i][j];
    			}
    		}
    	}
    	System.out.println("The Student with the highest grade was " + studName[index] + " Score: " + low);
    }


Was This Post Helpful? 0
  • +
  • -

#7 ProGraM  Icon User is offline

  • D.I.C Head

Reputation: 10
  • View blog
  • Posts: 150
  • Joined: 28-September 05

Re: Help with GradedBook

Posted 20 January 2009 - 08:29 PM

View PostBigAnt, on 20 Jan, 2009 - 08:26 PM, said:

What I would do, since you do not do anything with the return values, is just make the methods high/low print out the high and low, then from your echo data, instead of printing the the high and lows just call the methods. Then higher would look like:
    private static void highGrade()
    {
    	int index = 0;
    	int low = fourTests[0][0];
    	for(int i = 0; i < numStudents; i++){
    		for( int j = 0; j < 4; j++){
    			if(fourTests[i][j] > low){
    				index = i;
    				low = fourTests[i][j];
    			}
    		}
    	}
    	System.out.println("The Student with the highest grade was " + studName[index] + " Score: " + low);
    }




Ok that was simpler than i was thinking :P

And i would pretty much do the same thing for the low student
Was This Post Helpful? 0
  • +
  • -

#8 BigAnt  Icon User is offline

  • May Your Swords Stay Sharp
  • member icon

Reputation: 101
  • View blog
  • Posts: 2,392
  • Joined: 16-August 08

Re: Help with GradedBook

Posted 20 January 2009 - 08:30 PM

Yea, but just change the output message and the checking in the loop.
Was This Post Helpful? 0
  • +
  • -

#9 ProGraM  Icon User is offline

  • D.I.C Head

Reputation: 10
  • View blog
  • Posts: 150
  • Joined: 28-September 05

Re: Help with GradedBook

Posted 20 January 2009 - 08:54 PM

	private static void highGrade()
	{
	 int index = 0;
	 int high = fourTests[0][0];
	 for(int i = 0; i < numStudents; i++){
		  for( int j = 0; j < 4; j++){
			   if(fourTests[i][j] > high){
					index = i;
					high = fourTests[i][j] / 4; // added /4
			   }
		  }
	 }
	 System.out.println("The Student " + studName[index]+", " + studentID[index] + " had the highest test average of: " + high);
	}




ok so this is working but i'm haveing problems with the average. It's supposed to print out the student with the highest average.. so i added a divided by 4 but its taking the student with the highest grade( take the students and seeing who has A test that is higher than everyone elses) then dividing that by 4 instead of taking all for test and dividing by four

i also tried to divide this by 4
if(fourTests[i][j] /4 > high)


and this

	 int high = fourTests[0][0] /4;



Ok i'll check this tomorrow after school cause i gotta get up early for football =\

This post has been edited by ProGraM: 20 January 2009 - 09:49 PM

Was This Post Helpful? 0
  • +
  • -

#10 BigAnt  Icon User is offline

  • May Your Swords Stay Sharp
  • member icon

Reputation: 101
  • View blog
  • Posts: 2,392
  • Joined: 16-August 08

Re: Help with GradedBook

Posted 20 January 2009 - 10:11 PM

Well I would advise creating a method called get average, which takes the index of the student to calculate the average of. Then loop through that students tests scores adding them up then divide by number of tests scores, the method then returns this average.

Then to compare the average, you will only need the outer for loop to loop through the students, compare the averages instead of each individual test score.
Was This Post Helpful? 0
  • +
  • -

#11 ProGraM  Icon User is offline

  • D.I.C Head

Reputation: 10
  • View blog
  • Posts: 150
  • Joined: 28-September 05

Re: Help with GradedBook

Posted 24 January 2009 - 11:43 AM

View PostBigAnt, on 20 Jan, 2009 - 10:11 PM, said:

Well I would advise creating a method called get average, which takes the index of the student to calculate the average of. Then loop through that students tests scores adding them up then divide by number of tests scores, the method then returns this average.

Then to compare the average, you will only need the outer for loop to loop through the students, compare the averages instead of each individual test score.



Ok i've been trying to figure out how to do this since my last post and no luck =/...
Was This Post Helpful? 0
  • +
  • -

#12 ProGraM  Icon User is offline

  • D.I.C Head

Reputation: 10
  • View blog
  • Posts: 150
  • Joined: 28-September 05

Re: Help with GradedBook

Posted 25 January 2009 - 08:08 PM

is this on the right path for the averages?

private static void Average(int fourTests[][])
	{
	  int total = 0; // initialize total
 
	  // sum grades for one student
	  for ( int grade : fourTests )
		 total += grade;

	  // return average of grades
	  return (double) total / fourTests.length;
	}



Here's my whole code again edited:

 import java.util.*;
 import java.io.*;
 import java.text.DecimalFormat;
 import javax.swing.JOptionPane;
public class GradeBook 
{
	static int studCount = 0, numStudents, studID;
	static int fourTests[][];
	static double testAvg[], classAvg;
	static String studName[], studentID[], Students;
	public static void main(String[] args) throws IOException
	{
	 GradeBookStart();
	 StudentInfo(numStudents, studCount);
	 EchoData();
	 highGrade();
	 lowGrade();
	}
	public static void GradeBookStart() throws IOException
	{
		try
		{
			BufferedReader keyboard = new BufferedReader(new InputStreamReader(System.in));
			System.out.println("Welcome to teachers GradeBook !!");
			System.out.println("How many students do you have? Enter a number(1-10) and press return. ");
			Students = keyboard.readLine().trim();
			Students = Students.replace(" ", "");
			numStudents = Integer.parseInt(Students);
			if(numStudents > 0 && numStudents < 10)
			{
				studName = new String[numStudents];
				fourTests = new int[numStudents][4];
				studentID = new String[numStudents]; 
			}
			else if(numStudents < 0 || numStudents > 10)
			{
				JOptionPane.showMessageDialog(null, "Invalid Input....restarting the program");
				JOptionPane.showMessageDialog(null, "No Negatives, No Numbers Over 10, No Letters or Symbols.");
	   		GradeBookStart();	
			}	
		}catch(NumberFormatException e)
		{
			JOptionPane.showMessageDialog(null, "Invalid Input....restarting the program");
	   		JOptionPane.showMessageDialog(null, "No Negatives, No Numbers Over 10, No Letters or Symbols.");
	   		GradeBookStart();
		}
	}
	private static void StudentInfo(int numStudents, int studCount) throws IOException
	{
		do
		{
			BufferedReader keyboard = new BufferedReader(new InputStreamReader(System.in));
			System.out.println("\nEnter students name, press enter.");
			studName[studCount] = keyboard.readLine().trim();
			System.out.println("enter students id, press enter.");
			studentID[studCount] = keyboard.readLine().trim();
			for(int i=0;i<4;i++)
			{
   				try
   				{
   					System.out.println("Enter test score #" + (i+1) +", press enter");		
					fourTests[studCount][i] = Integer.parseInt(keyboard.readLine().trim());
					if(fourTests[studCount][i] < 0 || fourTests[studCount][i] > 100)
					{
						System.out.println("We Have Found A Cheater!!!");
						System.out.println("We do not give negative grades or extra credit..system restarting!\n");
						GradeBookStart();
					}
   				}catch(NumberFormatException e)
				{
					System.out.println("We Have Found A Cheater!!!\nSystem Restarting\n");
					GradeBookStart();
				}
			}
				studCount++;
		}while(studCount != numStudents);
	}
	private static void EchoData()
	{
		System.out.println("\n*** The Echo data Follows ***");
		System.out.println("Student Name\tID#\tTest Scores");
		for(int i = 0; i < numStudents; i++)
		{
		   System.out.print(studName[i] + "\t" + studentID[i] + "\t");
   			for(int j=0;j<4;j++)
   			{
	 		 System.out.print(fourTests[i][j] + " "); 
   			}
   		System.out.println();   		
		}
	}
	private static void Average(int fourTests[][])
	{
	  int total = 0; // initialize total
 
	  // sum grades for one student
	  for ( int grade : fourTests )
		 total += grade;

	  // return average of grades
	  return (double) total / fourTests.length;
	}
	private static void highGrade()
	{
	 int index = 0;
	 int high = fourTests[0][0];
	 for(int i = 0; i < numStudents; i++)
	 {
		  for( int j = 0; j < 4; j++)
		  {
			   if(fourTests[i][j] > high)
			   {
					index = i;
					high = fourTests[i][j];
			   }
		  }
	 }
	 System.out.println("The Student " + studName[index]+", " + studentID[index] + " had the highest test average of: " + high);
	}

	private static void lowGrade()
	{
	 int lowIndex = 0;
	 int low = fourTests[0][0];
	 for(int i = 0; i < numStudents; i++)
	 {
		  for( int j = 0; j < 4; j++)
		  {
			   if(fourTests[i][j] < low)
			   {
					lowIndex = i;
					low = fourTests[i][j];
			   }
		  }
	 }
	 System.out.println("The Student " + studName[lowIndex]+", " + studentID[lowIndex] + " had the lowest test average of: " + low);
	}
}


Was This Post Helpful? 0
  • +
  • -

#13 ProGraM  Icon User is offline

  • D.I.C Head

Reputation: 10
  • View blog
  • Posts: 150
  • Joined: 28-September 05

Re: Help with GradedBook

Posted 25 January 2009 - 10:04 PM

Ok i'm getting an error "incompatible types"
at
for(int grade : fourTests)





	private static double getAverage()
	{
	  int index = 0;
	  int total = 0; // initialize total
 
	  // sum grades for one student
	  for ( int i = 0; i < numStudents; i++);
	  {
			  for(int j = 0; j < 4; j++)
			  {
				  for(int grade : fourTests)
				  {
				  total += grade;	
				  }
			  }
	  }
		 

	  double averageGrades = total / fourTests.length;
	  // return average of grades
	  return (double) averageGrades;
	}


Was This Post Helpful? 0
  • +
  • -

#14 ProGraM  Icon User is offline

  • D.I.C Head

Reputation: 10
  • View blog
  • Posts: 150
  • Joined: 28-September 05

Re: Help with GradedBook

Posted 25 January 2009 - 11:02 PM

Ok since i didn't get ne inputs or help i moved onto the next task which was enabling the program to add students...
The program will add the student but instead of putting it under the last person it deletes the first person inputed and add then..

here's my Add function code

	private static void Add() throws IOException
	{
		BufferedReader keyboard = new BufferedReader(new InputStreamReader(System.in));
		 		System.out.println("\nEnter students name, press enter.");
			studName[studCount] = keyboard.readLine().trim();
			System.out.println("enter students id, press enter.");
			studentID[studCount] = keyboard.readLine().trim();
			for(int i=0;i<4;i++)
			{
   				try
   				{
   					System.out.println("Enter test score #" + (i+1) +", press enter");		
					fourTests[studCount][i] = Integer.parseInt(keyboard.readLine().trim());
					if(fourTests[studCount][i] < 0 || fourTests[studCount][i] > 100)
					{
						System.out.println("We Have Found A Cheater!!!");
						System.out.println("We do not give negative grades or extra credit..system restarting!\n");
						GradeBookStart();
					}
   				}catch(NumberFormatException e)
				{
					System.out.println("We Have Found A Cheater!!!\nSystem Restarting\n");
					GradeBookStart();
				}
			}
		System.out.println("\n*** The Echo data Follows ***");
		System.out.println("Student Name\tID#\tTest Scores");
		for(int i = 0; i < numStudents; i++)
		{
		   System.out.print(studName[i] + "\t" + studentID[i] + "\t");
   			for(int j=0;j<4;j++)
   			{
	 		 System.out.print(fourTests[i][j] + " "); 
   			}
   		System.out.println();   		
		}
	}





*******************************************************************
*******************************************************************

heres my whole code now

import java.util.*;
 import java.io.*;
 import java.text.DecimalFormat;
 import javax.swing.JOptionPane;
public class GradeBook 
{
	static int studCount = 0, numStudents, studID;
	static int fourTests[][];
	static double testAvg[], classAvg;
	static String studName[], studentID[], Students, Listings;
	public static void main(String[] args) throws IOException
	{
	 GradeBookStart();
	 StudentInfo(numStudents, studCount);
	 EchoData();
	}
	public static void GradeBookStart() throws IOException
	{
		try
		{
			BufferedReader keyboard = new BufferedReader(new InputStreamReader(System.in));
			System.out.println("Welcome to teachers GradeBook !!");
			System.out.println("How many students do you have? Enter a number(1-10) and press return. ");
			Students = keyboard.readLine().trim();
			Students = Students.replace(" ", "");
			numStudents = Integer.parseInt(Students);
			if(numStudents > 0 && numStudents < 10)
			{
				studName = new String[numStudents];
				fourTests = new int[numStudents][4];
				studentID = new String[numStudents]; 
			}
			else if(numStudents < 0 || numStudents > 10)
			{
				JOptionPane.showMessageDialog(null, "Invalid Input....restarting the program");
				JOptionPane.showMessageDialog(null, "No Negatives, No Numbers Over 10, No Letters or Symbols.");
	   		GradeBookStart();	
			}	
		}catch(NumberFormatException e)
		{
			JOptionPane.showMessageDialog(null, "Invalid Input....restarting the program");
	   		JOptionPane.showMessageDialog(null, "No Negatives, No Numbers Over 10, No Letters or Symbols.");
	   		GradeBookStart();
		}
	}
	private static void StudentInfo(int numStudents, int studCount) throws IOException
	{
		do
		{
			BufferedReader keyboard = new BufferedReader(new InputStreamReader(System.in));
			System.out.println("\nEnter students name, press enter.");
			studName[studCount] = keyboard.readLine().trim();
			System.out.println("enter students id, press enter.");
			studentID[studCount] = keyboard.readLine().trim();
			for(int i=0;i<4;i++)
			{
   				try
   				{
   					System.out.println("Enter test score #" + (i+1) +", press enter");		
					fourTests[studCount][i] = Integer.parseInt(keyboard.readLine().trim());
					if(fourTests[studCount][i] < 0 || fourTests[studCount][i] > 100)
					{
						System.out.println("We Have Found A Cheater!!!");
						System.out.println("We do not give negative grades or extra credit..system restarting!\n");
						GradeBookStart();
					}
   				}catch(NumberFormatException e)
				{
					System.out.println("We Have Found A Cheater!!!\nSystem Restarting\n");
					GradeBookStart();
				}
			}
				studCount++;
		}while(studCount != numStudents);
	}
	private static void EchoData() throws IOException
	{
		BufferedReader keyboard = new BufferedReader(new InputStreamReader(System.in));
		System.out.println("\n*** The Echo data Follows ***");
		System.out.println("Student Name\tID#\tTest Scores");
		for(int i = 0; i < numStudents; i++)
		{
		   System.out.print(studName[i] + "\t" + studentID[i] + "\t");
   			for(int j=0;j<4;j++)
   			{
	 		 System.out.print(fourTests[i][j] + " "); 
   			}
   		System.out.println();   		
		}
		highGrade();
		lowGrade();
		System.out.println("Type add, delete, ascend, or descend, press enter:");
		Listings = keyboard.readLine().trim();
		Listings = Listings.replace(" ", "");
		if(Listings.equalsIgnoreCase("add"))
		{
		 	Add();
		}
	/*	if(Listing.equalsIgnoreCase("delete"))
		{
		 	Delete();
		}
		if(Listing.equalsIgnoreCase("ascend"))
		{
		 	Ascending();
		}
		if(Listing.equalsIgnoreCase("descend"))
		{
		 	Descending();
		}*/
	}
   /* private static double getAverage()
	{
	  int index = 0;
	  int total = 0; // initialize total
 
	  // sum grades for one student
	  for ( int i = 0; i < numStudents; i++);
	  {
			  for(int j = 0; j < 4; j++)
			  {
				  for(int grade : fourTests)
				  {
				  total += grade;	
				  }
			  }
	  }
		 

	  double averageGrades = total / fourTests.length;
	  // return average of grades
	  return (double) averageGrades;
	}*/
	private static void highGrade()throws IOException
	{
		
	 int index = 0;
	 int high = fourTests[0][0];
	 for(int i = 0; i < numStudents; i++)
	 {
		  for( int j = 0; j < 4; j++)
		  {
			   if(fourTests[i][j] > high)
			   {
					index = i;
					high = fourTests[i][j];
			   }
		  }
	 }
	 System.out.println("The Student " + studName[index]+", " + studentID[index] + " had the highest test average of: " + high);
	}

	private static void lowGrade() throws IOException
	{
	 int lowIndex = 0;
	 int low = fourTests[0][0];
	 for(int i = 0; i < numStudents; i++)
	 {
		  for( int j = 0; j < 4; j++)
		  {
			   if(fourTests[i][j] < low)
			   {
					lowIndex = i;
					low = fourTests[i][j];
			   }
		  }
	 }
	 System.out.println("The Student " + studName[lowIndex]+", " + studentID[lowIndex] + " had the lowest test average of: " + low);
	}
	private static void Add() throws IOException
	{
		BufferedReader keyboard = new BufferedReader(new InputStreamReader(System.in));
		 		System.out.println("\nEnter students name, press enter.");
			studName[studCount] = keyboard.readLine().trim();
			System.out.println("enter students id, press enter.");
			studentID[studCount] = keyboard.readLine().trim();
			for(int i=0;i<4;i++)
			{
   				try
   				{
   					System.out.println("Enter test score #" + (i+1) +", press enter");		
					fourTests[studCount][i] = Integer.parseInt(keyboard.readLine().trim());
					if(fourTests[studCount][i] < 0 || fourTests[studCount][i] > 100)
					{
						System.out.println("We Have Found A Cheater!!!");
						System.out.println("We do not give negative grades or extra credit..system restarting!\n");
						GradeBookStart();
					}
   				}catch(NumberFormatException e)
				{
					System.out.println("We Have Found A Cheater!!!\nSystem Restarting\n");
					GradeBookStart();
				}
			}
		System.out.println("\n*** The Echo data Follows ***");
		System.out.println("Student Name\tID#\tTest Scores");
		for(int i = 0; i < numStudents; i++)
		{
		   System.out.print(studName[i] + "\t" + studentID[i] + "\t");
   			for(int j=0;j<4;j++)
   			{
	 		 System.out.print(fourTests[i][j] + " "); 
   			}
   		System.out.println();   		
		}
	}
}


Was This Post Helpful? 0
  • +
  • -

#15 ProGraM  Icon User is offline

  • D.I.C Head

Reputation: 10
  • View blog
  • Posts: 150
  • Joined: 28-September 05

Re: Help with GradedBook

Posted 26 January 2009 - 08:30 AM

View PostProGraM, on 25 Jan, 2009 - 10:04 PM, said:

Ok i'm getting an error "incompatible types"
at
for(int grade : fourTests)





	private static double getAverage()
	{
	  int index = 0;
	  int total = 0; // initialize total
 
	  // sum grades for one student
	  for ( int i = 0; i < numStudents; i++);
	  {
			  for(int j = 0; j < 4; j++)
			  {
				  for(int grade : fourTests)
				  {
				  total += grade;	
				  }
			  }
	  }
		 

	  double averageGrades = total / fourTests.length;
	  // return average of grades
	  return (double) averageGrades;
	}



Ok Coming back to the averages i finally figured it out..i didn't need a new function i just tweaked the if statement inside both of the highgrade and lowgrade functions

if((fourTests[i][0] + fourTests[i][1] + fourTests[i][2] + fourTests[i][3]) / 4 > high)
			   {
					index = i;
					high = (fourTests[i][0] + fourTests[i][1] + fourTests[i][2] + fourTests[i][3]) / 4;
			   }



and

if((fourTests[i][0] + fourTests[i][1] + fourTests[i][2] + fourTests[i][3]) / 4 < low)
			   {
					lowIndex = i;
					low = (fourTests[i][0] + fourTests[i][1] + fourTests[i][2] + fourTests[i][3]) / 4;
			   }


Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2