i am having a problem to store the item and call from it.It is like you already created a text file,then you need to assess item from it.the item is in disorder. :sad:

Recommended Answers

All 4 Replies

I don't know what you are asking for. Can you clarify?

Can you show an example of what you are trying to do and what problem you are having with getting it to work?

It also helps if you ask specific questions.

while (line!=null)
{



tokens = new StringTokenizer(line, ",",false);
String assessNameToken = tokens.nextToken();
if((tokens.hasMoreTokens()) );
int maxScoreToken = Integer.parseInt(tokens.nextToken());
int scaleScoreToken = Integer.parseInt(tokens.nextToken());


descript = new Assessment(assessNameToken, maxScoreToken, scaleScoreToken);
size++;
line = readDescription.readLine();


}

is almost like tat..i wanted to read the string file...but i dont think it can uses the parseString..i wanted to store into an array and called it afterward for further use...i dunno whether i make the question clear o not??

Firstly,

The line with the code

if((tokens.hasMoreTokens()) );

is basically useless. This checks if there are tokens and does nothing. What you want is

if((tokens.hasMoreTokens()) )
{
	//put code here
}

Also, you might want to use the trim() function when getting tokens. This cleans out the string of weird spaces at the beginning and end:

String someTokenHere = tokens.nextToken().trim();

For more help, www.NeedProgrammingHelp.com

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


public class try2
{
public static void main(String[] args)
{
Assessment[] result= new Assessment[10];


String line,line1, subjectName,token;
int lineNum=0;
int size=0;
int time=0;


try
{


BufferedReader readResult= new BufferedReader(new FileReader("ResultFile.txt."));



subjectName = readResult.readLine();



line = readResult.readLine();



StringTokenizer tokens;


while (line!=null)
{



tokens = new StringTokenizer(line, ",",false);
String studentIdToken = tokens.nextToken();
if(tokens.hasMoreTokens() );
String studentToken = tokens.nextToken();
String assessmentItemToken = tokens.nextToken();
double assessmentMarkToken = Double.parseDouble(tokens.nextToken());


result = new Assessment(studentIdToken, studentToken, assessmentItemToken,assessmentMarkToken);
size++;
line = readResult.readLine();


}
System.out.println(subjectName);  // check whether the infomation have been stored
System.out.println(result[2].getStudentId());
System.out.println(result[3].getStudent());
System.out.println(result[4].getAssessmentItem());
System.out.println(result[4].getAssessmentMark());



}



catch(FileNotFoundException e)
{
System.err.println("file not found");
}


catch(IOException e)
{
System.err.println(e);
}
}


}


class Assessment
{
private String student, assessmentItem;
private int studentId;
private double assessmentMark;


public Assessment(String name,String item, int id, double mark)
{
student=name;
assessmentItem=item;
studentId=id;
assessmentMark=mark;
}



public double getAssessmentMark()
{
return assessmentMark;
}


public int getStudentId()
{
return studentId;
}


public String getAssessmentItem()
{
return assessmentItem;
}


public String getStudent()
{
return student;
}


}

i still dunno wat happen to my program..it says tat cannot find the symbol constructor.

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.