Student Quiz

  • (2 Pages)
  • +
  • 1
  • 2

26 Replies - 7284 Views - Last Post: 09 June 2010 - 05:46 PM Rate Topic: -----

#1 slumdawg  Icon User is offline

  • New D.I.C Head

Reputation: -7
  • View blog
  • Posts: 11
  • Joined: 30-May 10

Student Quiz

Posted 30 May 2010 - 08:02 PM

I am working on this project for my class, and I am getting an error when im trying to compile. I dont understand what the problem is. can some one help me out. The error is
"Exception in thread "main" java.lang.RuntimeException: Uncompilable source code - cannot find symbol
symbol: class Student
location: class lab6.ReadSource
at lab6.ReadSource.main(ReadSource.java:21)"

I have attached a .rar file with the code i am working with now.

Write a program to keep records and perform statistical analysis for a class of students. The class may have up to 40 students. There are five quizzes during the term. Each student is identified by a four-digit student ID number.
The program is to print the student scores and calculate and print the statistics for each quiz. The output is in the same order as the input; no sorting is needed. The input is to be read from a text file. The output from the program should be similar to the following -
Stud Q1 Q2 Q3 Q4 Q5
1234 78 83 87 91 86
2134 67 77 84 82 79
1852 77 89 93 87 71
High Score 78 89 93 91 86
Low Score 67 77 84 82 71
Average 73.4 83.0 88.2 86.6 78.6

Try and implement ideas learnt in class.
Use one and two-dimensional arrays only. Test your program with the following data -

Stud Qu1 Qu2 Qu3 Qu4 Qu5
1234 052 007 100 078 034
2134 090 036 090 077 030
3124 100 045 020 090 070
4532 011 017 081 032 077
5678 020 012 045 078 034
6134 034 080 055 078 045
7874 060 100 056 078 078
8026 070 010 066 078 056
9893 034 009 077 078 020
1947 045 040 088 078 055
2877 055 050 099 078 080
3189 022 070 100 078 077
4602 089 050 091 078 060
5405 011 011 000 078 010
6999 000 098 089 078 020

Some help with Lab 6
---------------------
You must apply the following concepts in Lab 6.
1. Object Theory
2. File IO
3. Wrapper Classes.

Student Class
Attached File  Student.txt (765bytes)
Number of downloads: 163
Util Class
Attached File  Util.txt (1.1K)
Number of downloads: 155
ReadSource Class
Attached File  ReadSource.txt (1.22K)
Number of downloads: 141

Is This A Good Question/Topic? 0
  • +

Replies To: Student Quiz

#2 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8325
  • View blog
  • Posts: 31,857
  • Joined: 06-March 08

Re: Student Quiz

Posted 30 May 2010 - 08:11 PM

View Postslumdawg, on 30 May 2010 - 09:02 PM, said:

I am working on this project for my class, and I am getting an error when im trying to compile. I dont understand what the problem is. can some one help me out. The error is
"Exception in thread "main" java.lang.RuntimeException: Uncompilable source code - cannot find symbol
symbol: class Student
location: class lab6.ReadSource
at lab6.ReadSource.main(ReadSource.java:21)"

I have attached a .rar file with the code i am working with now.

Write a program to keep records and perform statistical analysis for a class of students. The class may have up to 40 students. There are five quizzes during the term. Each student is identified by a four-digit student ID number.
The program is to print the student scores and calculate and print the statistics for each quiz. The output is in the same order as the input; no sorting is needed. The input is to be read from a text file. The output from the program should be similar to the following -
Stud Q1 Q2 Q3 Q4 Q5
1234 78 83 87 91 86
2134 67 77 84 82 79
1852 77 89 93 87 71
High Score 78 89 93 91 86
Low Score 67 77 84 82 71
Average 73.4 83.0 88.2 86.6 78.6

Try and implement ideas learnt in class.
Use one and two-dimensional arrays only. Test your program with the following data -

Stud Qu1 Qu2 Qu3 Qu4 Qu5
1234 052 007 100 078 034
2134 090 036 090 077 030
3124 100 045 020 090 070
4532 011 017 081 032 077
5678 020 012 045 078 034
6134 034 080 055 078 045
7874 060 100 056 078 078
8026 070 010 066 078 056
9893 034 009 077 078 020
1947 045 040 088 078 055
2877 055 050 099 078 080
3189 022 070 100 078 077
4602 089 050 091 078 060
5405 011 011 000 078 010
6999 000 098 089 078 020

Some help with Lab 6
---------------------
You must apply the following concepts in Lab 6.
1. Object Theory
2. File IO
3. Wrapper Classes.

Student Class
Attachment Student.txt
Util Class
Attachment Util.txt
ReadSource Class
Attachment ReadSource.txt


Post your code... we do not like to download here... this site has been attacked by malicious attachments in the past and narrow down your problem (the code generating your run time error)

As it is a compilation error we do not need all tuour "data" files

Post only the class where you have a compilation error
Was This Post Helpful? 0
  • +
  • -

#3 slumdawg  Icon User is offline

  • New D.I.C Head

Reputation: -7
  • View blog
  • Posts: 11
  • Joined: 30-May 10

Re: Student Quiz

Posted 30 May 2010 - 09:26 PM

Quote

Post your code... we do not like to download here... this site has been attacked by malicious attachments in the past and narrow down your problem (the code generating your run time error)

As it is a compilation error we do not need all tuour "data" files

Post only the class where you have a compilation error

Its just a notepad file, if i was a hacker i wouldnt need to be on this website asking for help. I posted those three .txt files because its too long and it takes up the entire page.
Was This Post Helpful? -5
  • +
  • -

#4 macosxnerd101  Icon User is online

  • Self-Trained Economist
  • member icon




Reputation: 10397
  • View blog
  • Posts: 38,479
  • Joined: 27-December 08

Re: Student Quiz

Posted 30 May 2010 - 09:31 PM

As long as you post the code into code tags, don't worry about page length. We are happy to look at your code, so long as you follow the rules and good ettiquete (like properly formatting your code). If there is something that would be better off in or out of certain tags, a Team Member will edit your post to adjust. :)
Was This Post Helpful? 0
  • +
  • -

#5 slumdawg  Icon User is offline

  • New D.I.C Head

Reputation: -7
  • View blog
  • Posts: 11
  • Joined: 30-May 10

Re: Student Quiz

Posted 30 May 2010 - 09:33 PM

View Postmacosxnerd101, on 30 May 2010 - 08:31 PM, said:

As long as you post the code into code tags, don't worry about page length. We are happy to look at your code, so long as you follow the rules and good ettiquete (like properly formatting your code). If there is something that would be better off in or out of certain tags, a Team Member will edit your post to adjust. :)

Alright just for you
package Lab6;
import java.io.*;
import java.util.StringTokenizer;
public class ReadSource
{
    //Example references
    //ReadSource.java -- shows how to work with readLine and FileReader
    //How do you tokenize a String
    //How to convert a String to an Integer
	//int x = Integer.parseInt(String) ;
        //Putting it altogether:
        public static void main(String [] args) throws Exception
	{
            /************************
             * IF STUDENTS > 40
             * PRINT "TOO MANY RECORDS"
             * AND QUIT PROGRAM
             ************************/
            Student lab6 [] = new Student[40];
            //Populate the student array
            if (lab6.length > 40)
            {
                System.out.println("Too Many Records");
            }
          //  lab6 = Util.readFile("Data.txt", lab6);
            Statistics statlab6 = new Statistics();
            statlab6.findlow(lab6);
            //add calls to findhigh and find average
            //Print the data and statistics
            StringTokenizer st = new StringTokenizer("this is a test");
            while (st.hasMoreTokens())
            {
                System.out.println(st.nextToken());
            }
        }
}

package Lab6;
import java.io.*;
import corejava.*;
import java.util.StringTokenizer;
public class Util
{
    public static Student [] readFile(String filename, Student [] stu)
            throws Exception
    {
    /*  - Reads the file and builds student array.
	- Open the file using FileReader Object.
	- In a loop read a line using readLine method.
	- Tokenize each line using StringTokenizer Object
	- Each token is converted from String to Integer using parseInt method
	- Value is then saved in the right property of Student Object.
    */
        String x;
        FileReader fr = new FileReader("Data.txt");
        BufferedReader br = new BufferedReader(fr);
        while ((x = br.readLine())!= null)
        {
            System.out.println(x);
        }
        StringTokenizer tokenizer = new StringTokenizer("Data.txt");
        while (tokenizer.hasMoreTokens()) 
        {
            System.out.println(tokenizer.nextToken());
        }
        fr.close();
        return stu;
    }
    Student a1[][] = new Student [40][6];  //array of object references
    //40 students, 6 quizzes

    //if numofrows > 40 exit with an error message else compute statistics

    /* if number of rows < 40
     *     a1[] = new Student (...........);
     *     where i < 40
     */
    public static void read()
    {

    }
}

package Lab6;
import java.io.*;
public class Student
{
    private int SID;       //Student ID
    private Integer scores[] = new Integer[5];

    public int getSID() {
        return SID;
    }
    public void setSID(int SID) {
        this.SID = SID;
    }
    public Integer[] getScores() {
        return scores;
    }
    public void setScores(Integer[] scores) {
        this.scores = scores;
    }
    
    //add methods to print values of instance variables.
    public String Print()
    {
        Student [] students = new Student[5];
        for (int i = 0; i < students.length; i++)
        {
            return ("SID: " + this.SID + "Scores" + this.scores);
        }
        return ("SID: " + this.SID + "Scores" + this.scores);
    }
}

Was This Post Helpful? 0
  • +
  • -

#6 macosxnerd101  Icon User is online

  • Self-Trained Economist
  • member icon




Reputation: 10397
  • View blog
  • Posts: 38,479
  • Joined: 27-December 08

Re: Student Quiz

Posted 30 May 2010 - 10:50 PM

Can you also post your Statistics class so I can compile your code? I'm guessing it's probably from your school's library.
Was This Post Helpful? 0
  • +
  • -

#7 slumdawg  Icon User is offline

  • New D.I.C Head

Reputation: -7
  • View blog
  • Posts: 11
  • Joined: 30-May 10

Re: Student Quiz

Posted 30 May 2010 - 11:18 PM

View Postmacosxnerd101, on 30 May 2010 - 09:50 PM, said:

Can you also post your Statistics class so I can compile your code? I'm guessing it's probably from your school's library.

I havent really done much to it. but it doesnt have any compilation errors
package Lab6;
class Statistics
{
    int [] lowscores = new int [5];
    int [] highscores = new int [5];
    float [] avgscores = new float [5];
    void findlow(Student [] a)
    {
        //This method will find lowest score and store it in an array names lowscores
    }

    void findhigh(Student [] a)
    {
    //This method will find highest score and store it in an array names highscores
    }

    void findaverage(Student [] a)
    {
        //This method will find avg score for each quiz and store it in an
        //array names avgscores
    }
        //add methods to print values of instance variables.
}


Was This Post Helpful? 0
  • +
  • -

#8 g00se  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2657
  • View blog
  • Posts: 11,214
  • Joined: 20-September 08

Re: Student Quiz

Posted 31 May 2010 - 02:47 AM

I suspect you have not organised your source properly: the code as it is runs fine for me. Start afresh and extract the attached to a new directory with

jar xvf lab6.zip

Attached File(s)

  • Attached File  lab6.zip (5.43K)
    Number of downloads: 103

Was This Post Helpful? 0
  • +
  • -

#9 slumdawg  Icon User is offline

  • New D.I.C Head

Reputation: -7
  • View blog
  • Posts: 11
  • Joined: 30-May 10

Re: Student Quiz

Posted 31 May 2010 - 04:56 PM

View Postg00se, on 31 May 2010 - 01:47 AM, said:

I suspect you have not organised your source properly: the code as it is runs fine for me. Start afresh and extract the attached to a new directory with
jar xvf lab6.zip

OK well I got it to say
"this
is
a
test"
So looks like its working. I put throws Exception in my ReadSource main method.
Was This Post Helpful? 0
  • +
  • -

#10 g00se  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2657
  • View blog
  • Posts: 11,214
  • Joined: 20-September 08

Re: Student Quiz

Posted 01 June 2010 - 02:04 AM

Quote

OK well I got it to say ..


Yes, that's what it does at the moment - so it's running
Was This Post Helpful? 0
  • +
  • -

#11 slumdawg  Icon User is offline

  • New D.I.C Head

Reputation: -7
  • View blog
  • Posts: 11
  • Joined: 30-May 10

Re: Student Quiz

Posted 01 June 2010 - 11:13 AM

Quote

Yes, that's what it does at the moment - so it's running

So this is what I have as of now. I get
"
Exception in thread "main" java.lang.NumberFormatException: For input string: "1234 052 007 100 078 034"
at java.lang.NumberFormatException.forInputString(NumberFormatException.java:48)
at java.lang.Integer.parseInt(Integer.java:456)
at java.lang.Integer.parseInt(Integer.java:497)
at lab6.Util.readFile(Util.java:31)
at lab6.Util.main(Util.java:80)
"
I dont know why im getting an error on readFile
package lab6;
import java.io.*;
import java.util.StringTokenizer;

class Util
{
	static Student [][] readFile(String filename, Student [][] stu)
	{
        try
        {
            FileReader file = new  FileReader("Data.txt");
            BufferedReader buff = new BufferedReader(file);
            boolean eof = false;
            //In a loop read a line using readLine method.
            while (!eof)
            {
                System.out.println("Start");
                String line = buff.readLine();
                if (line == null)
                    eof = true;
                else
                {
                    System.out.println(line);
                }   //Tokenize each line using StringTokenizer Object
                StringTokenizer st = new StringTokenizer(line);
                while (st.hasMoreTokens())
                {
                    System.out.println(st.nextToken());
                }
                //Each token is converted from String to Integer using parseInt method
                int x = Integer.parseInt(line);
                //System.out.println(x);
                }//while
                buff.close();
        }//try
        catch (IOException e)
        {
            System.out.println("Error -- " + e.toString());
        }//catch
        //Value is then saved in the right property of Student Object.
        return stu;
    }

package lab6;
class Student
{
	  private int SID;
	  private Integer scores[] = new Integer[5];
	  //write public get and set methods for SID and scores
      Student()
      {
          SID = 0;
          scores[1] = 0;
          scores[2] = 0;
          scores[3] = 0;
          scores[4] = 0;
          scores[5] = 0;
      }
	  public int getSID(){
              return SID;
      }
	  public int getScores(int i){ 
              return scores[i];
      }
	  public void setSID(int tempSID){ 
              SID = tempSID;
      }
	  public void setScores(int i, int tempScore[]){
              scores[i] = tempScore[i];
      }
	  //add methods to print values of instance variables.
	  void printSID(){
              System.out.print(getSID());
      }
	  void printScores(int i){
              System.out.print(getScores(i));
      }
}


package lab6;
class Statistics
{
    int [] lowscores = new int [5];
    int [] highscores = new int [5];
    float [] avgscores = new float [5];
  
    //This method will find lowest score and store it in an array names lowscores
    void findlow(Student  a[][])
    {
        int row = 0, lowCol = 0, col = 1, minValue;
        while( col < 6)
        {
            minValue = a[row][col].getScores(col);
            for(row++; row<a.length; row++)
            {
                if(a[row][col].getScores(col) < minValue)
                    minValue = a[row][col].getScores(col);
            }//for
            col++;
            lowscores[lowCol++] = minValue;
        }//while
    }//findlow
    //This method will find highest score and store it in an array names highscores
    void findhigh(Student [][] a)
    {
        int row = 0, col = 1,highCol = 0, maxValue;
        while( col < 6)
        {
            maxValue = a[row][col].getScores(col);
            for(row++; row<a.length; row++)
            {
                if(a[row][col].getScores(col) < maxValue)
                    maxValue = a[row][col].getScores(col);
            }//for
                highscores[highCol++] = maxValue;
                col++;
        }//while
    }//findhigh

    //This method will find highest score and store it in an array names avgscores
    void findAverage(Student [][] a)
    {
        int row = 0,avgCol=0, col = 1, avgValue;
        while( col<6)
        {
            avgValue = a[row][col].getScores(col);
            for(row++; row<a.length; row++)
            {
                if(a[row][col].getScores(col) < avgValue)
                {
                    avgValue = a[row][col].getScores(col);
                }
            }//for
            col++;
            avgscores[avgCol++] = avgValue/a.length;
        }//while
    }//findAverage
    //prints all the data
    void printData(Student [][]a)
    {
        int row=0,col=0;
        System.out.println("Stud Qu1 Qu2 Qu3 Qu4 Qu5");
        for(row = 0; row < a.length; row++)
        {
            System.out.printf("%d ",a[row][col].getSID());
            for(col = 1; col < 6; col++)
            {
                System.out.printf("%d ",a[row][col].getScores(col));
            }
        }//for
    }//printData
}//class

Was This Post Helpful? 0
  • +
  • -

#12 g00se  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2657
  • View blog
  • Posts: 11,214
  • Joined: 20-September 08

Re: Student Quiz

Posted 01 June 2010 - 11:29 AM

Quote

int x = Integer.parseInt(line);



That won't work. The line is full of spaces. You need to parse individual numbers. I suggest you use a Scanner
Was This Post Helpful? 0
  • +
  • -

#13 sh1n3  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 24
  • View blog
  • Posts: 164
  • Joined: 22-April 10

Re: Student Quiz

Posted 01 June 2010 - 11:34 AM

Is there a whitespace after Student....I think it should be Student[][].
Was This Post Helpful? 0
  • +
  • -

#14 slumdawg  Icon User is offline

  • New D.I.C Head

Reputation: -7
  • View blog
  • Posts: 11
  • Joined: 30-May 10

Re: Student Quiz

Posted 01 June 2010 - 11:43 AM

View Postg00se, on 01 June 2010 - 10:29 AM, said:

Quote

int x = Integer.parseInt(line);



That won't work. The line is full of spaces. You need to parse individual numbers. I suggest you use a Scanner

How would you change that then?

Quote

Is there a whitespace after Student....I think it should be Student[][].

It shouldnt matter where the [][] are, my instructor said it can be either way. it can be "Student [][] a" or "Student a[][]"
Was This Post Helpful? 0
  • +
  • -

#15 m-e-g-a-z  Icon User is offline

  • Winning
  • member icon


Reputation: 496
  • View blog
  • Posts: 1,453
  • Joined: 19-October 09

Re: Student Quiz

Posted 01 June 2010 - 12:25 PM

Instantiate a Scanner Object

Scanner s = new Scanner(new FileReader("filename"));



Then invoke the nextInt() method on the Scanner object which will get each integer.

Have a while loop with a condition such as while(s.hasNextInt()) if you are storing each number within an array which i presume you are doing.

Quote

Is there a whitespace after Student....I think it should be Student[][].


It does not matter what side it is at.

This post has been edited by m-e-g-a-z: 01 June 2010 - 12:26 PM

Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2