I have been given a chunk of code from my teachers, and I just need help getting it to run. I'm very new to java so any help is much appreciated. Here it is:

import java.util.*;
import java.io.*;
public class CourseStats
{
	static String[ ] studentNames;
	static int[ ][ ] quizzes;
	static int[ ][ ] homeworks;
	static int[ ] exam;
	static final int NUM_QUIZZES = 9;
	static final int NUM_HOMEWORKS = 12;
	static final int QUIZZES = 1;
	static final int HOMEWORKS = 2;
	public static void main(String[] args) throws IOException
	{
		initializeArrays( );
		readFile( args[0] );
		printDetails( );
		printAverages( );
	}
	public static void printAverages( )
	{

		//NOTE - this loops from 1 (not 0) to the number of quizzes/homeworks - because we say "HW1" and "Q1" 
		// NOT HW0 and Quiz0.  So, when you implement the method getAverage - take note of this - we're sending in i which
		// starts at 1!!!!! Your index starts at zero!!
		// Do not change our code - make your code work with this.

		for ( int i=1; i<=NUM_QUIZZES; i++ )
		{
			System.out.print( "Quiz #" + i + " average: " );
			System.out.println( getAverage( QUIZZES, i ) );
		}
		for ( int i=1; i<=NUM_HOMEWORKS; i++ )
		{
			System.out.print( "HW #" + i + " average: " );
			System.out.println( getAverage( HOMEWORKS, i ) );
		}
	}
	public static void printDetails( )
	{
		System.out.print( "Q1\tQ2\tQ3\tQ4\tQ5\tQ6\tQ7\tQ8\tQ9");
		for ( int i=1; i<=12; i++ )
			System.out.print( "\tHW" + i );
		System.out.println( "\tEXAM\tName" );
	}
	public static double getAverage( int type, int whichOne )
	{
		if ( type == QUIZZES )
		{

		}
		else if ( type == HOMEWORKS )
		{

		}
	}
	public static void initializeArrays( )
	{
		studentNames = new String[ 100 ];
		quizzes = new int[100][NUM_QUIZZES];
		homeworks = new int[100][NUM_HOMEWORKS];
		exam = new int[100];
	}
	public static void readFile( String filename ) throws IOException
	{

	}
}

These are my errors:
Exception in thread "main" java.lang.Error: Unresolved compilation problem:
This method must return a result of type double

at CourseStats.getAverage(CourseStats.java:46)
at CourseStats.printAverages(CourseStats.java:31)
at CourseStats.main(CourseStats.java:18)

As the compiler stated, you must return a data of type double for your getAverage() method at line 46. If you do not want to return any value, just change to

public static void getAverage()

but that does not meet the purpose of creating accessor method if it does not return a value.

much appreciated! However, now it is giving me:

Exception in thread "main" java.lang.Error: Unresolved compilation problem:

at CourseStats.main(CourseStats.java:14)

Where you have readFile( args[0] ); which calls the readfile method, you haven't constructed what the filename is within the method.

I don't find the error that you stated above. Can you paste the code that you used. And the full exception message.

@above. It should throw a FileNotFoundException in case the file is not found in the String sent. He has passed a string. I see no issue in that.

I made it to run but I don't know if the output really meet what you expected.

Here is what I did:

import java.util.*;
import java.io.*;

public class CourseStats {

	static String[] studentNames;
	static int[][] quizzes;
	static int[][] homeworks;
	static int[] exam;
	static final int NUM_QUIZZES = 9;
	static final int NUM_HOMEWORKS = 12;
	static final int QUIZZES = 1;
	static final int HOMEWORKS = 2;
	
	public static void main(String[] args) throws IOException {
		
		initializeArrays();
		readFile("test");
		printDetails();
		printAverages();
		
	}
	
	public static void printAverages() {
		for (int i = 1; i <= NUM_QUIZZES; i++) {
			System.out.print("Quiz #" + i + " average: ");
			System.out.println(QUIZZES);
		}
		
		for (int i = 1; i <= NUM_HOMEWORKS; i++) {
			System.out.print("HW #" + i + " average: ");
			System.out.println(HOMEWORKS);
		}
	}
	public static void printDetails() {
		System.out.print("Q1\tQ2\tQ3\tQ4\tQ5\tQ6\tQ7\tQ8\tQ9");
		
		for (int i = 1; i <= 12; i++)
			System.out.print("\tHW" + i);
		
		System.out.println("\tEXAM\tName");
	}
	public static double getAverage(int type, int whichOne) {
		double test = 0.0;
		if (type == QUIZZES) {
			
		} else if (type == HOMEWORKS) {
			
		}
		return test;
	}
	public static void initializeArrays() {
		studentNames = new String[100];
		quizzes = new int[100][NUM_QUIZZES];
		homeworks = new int[100][NUM_HOMEWORKS];
		exam = new int[100];
	}
	public static void readFile(String filename) throws IOException {
		System.out.println(filename);
	}
	
}

At line 18, I just pass a string just for testing.

At line 27 and 32, I don't know what you really want to print, so I just put the final variable. In your source code, you put something like System.out.println(QUIZZES, i) which is definitely wrong. You can't concatenate strings using comma.

For my getAverage() method, I just make a new double variable just for testing.

For my readFile() method, I just print it out the argument since I don't know what would you want it to do.

Well, How will i know what output is needed for you ? If you don't know anything in this, start learning java. Don't expect us to complete your program saying its learning.

sike.mausa, you really should ask your teacher what this program will do. You said your teacher gave it to you? That's weird. Did he/she ever mention about correcting the error or something?

Thanks much for the assistance! I know most of it, but they gave us the code as a skeleteon to add on to since we havn't learnt some of it. Honestly, they are horrible teachers so I'm somewhat lost on the assignment. Basically they want me to take an input file with a bunch of test scores and averages and format it so the output is similar to the one seen here:

http://www.cs.colostate.edu/~cs160/assignments/hw9f11.html

I'm attempting to work through it now that I actually got the skeleton to run. I'm a little confused about getting the data into the arrays to go in the proper rows and columns, the data file is at:

http://www.cs.colostate.edu/~cs160/assignments/student.data

if anyone would be kind enough to shed some light on the matter.

Thanks a bunch everyone for the help.

import java.util.*;
import java.io.*;
public class CourseStats
{
	static String[ ] studentNames;
	static int[ ][ ] quizzes;
	static int[ ][ ] homeworks;
	static int[ ] exam;
	static final int NUM_QUIZZES = 9;
	static final int NUM_HOMEWORKS = 12;
	static final int QUIZZES = 1;
	static final int HOMEWORKS = 2;
	public static void main(String[] args) throws IOException
	{
		

		Scanner scan = null;
		try {
			scan = new Scanner(new File(args[0]));
		} catch (FileNotFoundException e) {
			System.out.println("Data file not found error.");
			System.exit(0);
		}

		scan.useDelimiter(";");
		while (scan.hasNextLine()){
			System.out.print(scan.next());
			
			
		}
		
		
		
		initializeArrays( );
		readFile( args[0] );
		printDetails( );
		printAverages( );
	}
	public static void printAverages( )
	{

		//NOTE - this loops from 1 (not 0) to the number of quizzes/homeworks - because we say "HW1" and "Q1" 
		// NOT HW0 and Quiz0.  So, when you implement the method getAverage - take note of this - we're sending in i which
		// starts at 1!!!!! Your index starts at zero!!
		// Do not change our code - make your code work with this.

		for ( int i=1; i<=NUM_QUIZZES; i++ )
		{
			System.out.print( "Quiz #" + i + " average: " );
			System.out.println( getAverage( QUIZZES, i ) );
		}
		for ( int i=1; i<=NUM_HOMEWORKS; i++ )
		{
			System.out.print( "HW #" + i + " average: " );
			System.out.println( getAverage( HOMEWORKS, i ) );
		}
	}
	public static void printDetails( )
	{
		System.out.print( "Q1\tQ2\tQ3\tQ4\tQ5\tQ6\tQ7\tQ8\tQ9");
		for ( int i=1; i<=12; i++ )
			System.out.print( "\tHW" + i );
		System.out.println( "\tEXAM\tName" );
	}
	public static double getAverage( int type, int whichOne )
	{
		if ( type == QUIZZES )
		{

		}
		else if ( type == HOMEWORKS )
		{

		}
	}
	public static void initializeArrays( )
	{
		studentNames = new String[ 100 ];
		quizzes = new int[100][NUM_QUIZZES];
		homeworks = new int[100][NUM_HOMEWORKS];
		exam = new int[100];
	}
	public static void readFile( String filename ) throws IOException
	{

	}
}

That is my code. I need to get the scores into seperate arrays for each quiz in the file http://www.cs.colostate.edu/~cs160/assignments/student.data

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.