What's wrong?
import java.util.*;
import java.lang.*;
import java.io.*;
public class Grades
{
public static void main(String []args)throws Exception
{
// check to see if user entered file name
// Get the name of the data file from the screen
// You should prompt user to enter the name of the
// file with data for the grades. You will need this
// file to read the meta data and the actual
// scores for the quizzes and tests.
if(args.length < 1)
{
System.out.println("Usage: java Quiz10 names.txt");
System.exit(1);
}
// create a file reader to read the data from
// a file supplied at the prompt. Using this
// FileReader, you will create an instance of
// the BufferedReader to read a line at a time
// from the file
FileReader file = new FileReader(args[0]);
BufferedReader bfile = new BufferedReader(file);
// Create an instance of BufferedReader to readLine
String line;
line = bfile.readLine();
// read the first line from the file which has
// the number of quizzes and tests. This value
// will later be used to size the array of
// various objects to hold meta and actual scores for
// the quizzes and tests
// Create a ValueTokenizer to parse the
// first 2 integers as number of quizzes and number of
// tests and save the values into 2 local variables
// (numQuizzes and numTests). These values will be used
// quite extensively later in the program to size the arrays
LineTokenizer myLine = new LineTokenizer(line);
ValueTokenizer myLine = new ValueTokenizer(line);
int numQuizzes = myLine.nextInt();
int numTests = myLine.nextInt();
// Create an array of Meta information about
// Quizzes. We will read the max Scores and
// Weight from the next 2 lines and create the
// Meta objects for Quiz and Tests. Do not forget to
// initialize each array value to a Meta object also
// Repeat the same for Tests as for the quizzes
Quizzes studentQuiz = new Quizzes(numQuizzes);
Tests studentTests = new Tests(numTests);
// read Max Scores for Quiz and Test
// Use line and value tokenizer to tokenize the
// values of max scores for the quizzes and tests
// and save them into meta objects
String line2;
line2 = bfile.readLine();
LineTokenizer myLine2 = LineTokenizer(line2);
ValueTokenizer myLine2 = ValueTokenizer(line2);
while(myLine.hasMoreTokens())
{
String token = myLine.nextToken();
System.out.println(token);
}
}
}
//Here's the LineTokenizer class
import java.util.StringTokenizer;
//
// This class takes string as arg and parses
// it into quizes, tests extra credit
public class LineTokenizer {
StringTokenizer tok = null;
public LineTokenizer(String line) {
tok = new StringTokenizer(line,";");
}
public String nextString() {
return tok.nextToken();
}
}
//Here's the ValueTokenizer class
import java.util.StringTokenizer;
//
// This class takes a string
// and return int values separated by ' '
//
public class ValueTokenizer {
StringTokenizer tok = null;
public ValueTokenizer(String str) {
tok = new StringTokenizer(str," ");
}
public int nextInt() {
String str = tok.nextToken();
if (str != null)
return Integer.parseInt(str.trim());
return -1;
}
public double nextDouble() {
String str = tok.nextToken();
if (str != null)
return Double.parseDouble(str);
return -1.0;
}
}
//Here's a bit of the file I'm trying to read
10 3 ;
3 3 3 3 3 3 3 3 3 3 ; 40 40 40 ;
2 2 2 2 2 2 2 2 2 2 ; 20 25 35 ;
A0262 ; 51030 ; 3 3 2 3 3 3 3 3 3 3 ; 33 37 39 ; 0.5 ;
A6958 ; 51050 ; 2 3 0 3 3 3 0 3 2 3 ; 26 29 31 ; 0 ;
A8338 ; 51005 ; 1 3 1 2 1 3 3 2 2 2 ; 13 25 16 ; 0 ;
B2065 ; 51005 ; 2 3 0 2 3 2 2 3 1 2 ; 21 30 28 ; 0 ;
B4563 ; 51040 ; 2 2 3 0 2 0 3 3 0 3 ; 32 28 0 ; 0 ;
# 4
import java.util.*;
import java.lang.*;
import java.io.*;
public class Grades
{
public static void main(String []args)throws Exception
{
// check to see if user entered file name
// Get the name of the data file from the screen
// You should prompt user to enter the name of the
// file with data for the grades. You will need this
// file to read the meta data and the actual
// scores for the quizzes and tests.
if(args.length < 1)
{
System.out.println("Usage: java Quiz10 names.txt");
System.exit(1);
}
// create a file reader to read the data from
// a file supplied at the prompt. Using this
// FileReader, you will create an instance of
// the BufferedReader to read a line at a time
// from the file
FileReader file = new FileReader(args[0]);
BufferedReader bfile = new BufferedReader(file);
// Create an instance of BufferedReader to readLine
String line;
line = bfile.readLine();
// read the first line from the file which has
// the number of quizzes and tests. This value
// will later be used to size the array of
// various objects to hold meta and actual scores for
// the quizzes and tests
// Create a ValueTokenizer to parse the
// first 2 integers as number of quizzes and number of
// tests and save the values into 2 local variables
// (numQuizzes and numTests). These values will be used
// quite extensively later in the program to size the arrays
LineTokenizer myLine = new LineTokenizer(line);
ValueTokenizer myLine = new ValueTokenizer(line);
int numQuizzes = myLine.nextInt();
int numTests = myLine.nextInt();
// Create an array of Meta information about
// Quizzes. We will read the max Scores and
// Weight from the next 2 lines and create the
// Meta objects for Quiz and Tests. Do not forget to
// initialize each array value to a Meta object also
// Repeat the same for Tests as for the quizzes
Quizzes studentQuiz = new Quizzes(numQuizzes);
Tests studentTests = new Tests(numTests);
// read Max Scores for Quiz and Test
// Use line and value tokenizer to tokenize the
// values of max scores for the quizzes and tests
// and save them into meta objects
String line2;
line2 = bfile.readLine();
LineTokenizer myLine2 = LineTokenizer(line2);
ValueTokenizer myLine2 = ValueTokenizer(line2);
while(myLine.hasMoreTokens())
{
String token = myLine.nextToken();
System.out.println(token);
}
}
}
//Here's the LineTokenizer class
import java.util.StringTokenizer;
//
// This class takes string as arg and parses
// it into quizes, tests extra credit
public class LineTokenizer {
StringTokenizer tok = null;
public LineTokenizer(String line) {
tok = new StringTokenizer(line,";");
}
public String nextString() {
return tok.nextToken();
}
}
//Here's the ValueTokenizer class
import java.util.StringTokenizer;
//
// This class takes a string
// and return int values separated by ' '
//
public class ValueTokenizer {
StringTokenizer tok = null;
public ValueTokenizer(String str) {
tok = new StringTokenizer(str," ");
}
public int nextInt() {
String str = tok.nextToken();
if (str != null)
return Integer.parseInt(str.trim());
return -1;
}
public double nextDouble() {
String str = tok.nextToken();
if (str != null)
return Double.parseDouble(str);
return -1.0;
}
}
//Here's a bit of the file I'm trying to read
10 3 ;
3 3 3 3 3 3 3 3 3 3 ; 40 40 40 ;
2 2 2 2 2 2 2 2 2 2 ; 20 25 35 ;
A0262 ; 51030 ; 3 3 2 3 3 3 3 3 3 3 ; 33 37 39 ; 0.5 ;
A6958 ; 51050 ; 2 3 0 3 3 3 0 3 2 3 ; 26 29 31 ; 0 ;
A8338 ; 51005 ; 1 3 1 2 1 3 3 2 2 2 ; 13 25 16 ; 0 ;
B2065 ; 51005 ; 2 3 0 2 3 2 2 3 1 2 ; 21 30 28 ; 0 ;
B4563 ; 51040 ; 2 2 3 0 2 0 3 3 0 3 ; 32 28 0 ; 0 ;
Errors include
-jGRASP wedge2: exit code for process is 1.
-jGRASP: operation complete.
-jGRASP exec: javac -g D:\Java\project4classes\Grades.java
Grades.java:48: myLine is already defined in main(java.lang.String[])
ValueTokenizer myLine = new ValueTokenizer(line);
^
Grades.java:49: cannot find symbol
symbol : method nextInt()
location: class LineTokenizer
int numQuizzes = myLine.nextInt();
^
Grades.java:50: cannot find symbol
symbol : method nextInt()
location: class LineTokenizer
int numTests = myLine.nextInt();
^
Grades.java:69: cannot find symbol
symbol : method LineTokenizer(java.lang.String)
location: class Grades
LineTokenizer myLine2 = LineTokenizer(line2);
^
Grades.java:70: myLine2 is already defined in main(java.lang.String[])
ValueTokenizer myLine2 = ValueTokenizer(line2);
^
Grades.java:70: cannot find symbol
symbol : method ValueTokenizer(java.lang.String)
location: class Grades
ValueTokenizer myLine2 = ValueTokenizer(line2);
^
Grades.java:73: cannot find symbol
symbol : method hasMoreTokens()
location: class LineTokenizer
while(myLine.hasMoreTokens())
^
Grades.java:75: cannot find symbol
symbol : method nextToken()
location: class LineTokenizer
String token = myLine.nextToken();
^
8 errors
-jGRASP wedge2: exit code for process is 1.
-jGRASP: operation complete.
Message was edited by:
student022