분명히 도움이 필요합니다. 우리의 임무는 파일을 검색하고 분류하여 다른 파일에 표시하는 것입니다. 성 이름 다음 등급. "java.util.NoSuchElementException"오류로 인해 루프가 작동하는 데 문제가 있습니다. 이것은 현재 루프가있는 동안 변경하는 경우에만 발생합니다. 또한 결과를 표시하는 데 문제가 있습니다. 내가 표시 한 결과는 한 줄에 모두 표시되어 있습니다. 우리는 arraylist, 그냥 Bufferedreader, 스캐너, 그리고 이미 가지고있는 것을 사용하도록 허용되지 않습니다. 여기 내 코드는 지금까지 있습니다 :루프 앤 토크 나이저 및 파일을 읽는 동안 도움주세요.
import java.util.;
import java.util.StringTokenizer;
import java.io.;
import javax.swing.*;
import java.text.DecimalFormat;
/*************************************
Program Name: Grade
Name: Dennis Liang
Due Date: 3/31/11
Program Description: Write a program
which reads from a file a list of
students with their Grade. Also display
last name, first name, then grade.
************************************/
import java.util.*;
import java.util.StringTokenizer;
import java.io.*;
import javax.swing.*;
import java.text.DecimalFormat;
class Grade {
public static void main(String [] args)throws IOException {
//declaring
String line = "";
StringTokenizer st;
String delim = " \t\n\r,-";
String token;
String firstname;
String lastname;
String grade;
String S69andbelow="Students with 69 or below\n";
String S70to79 ="Students with 70 to 79\n";
String S80to89= "Students with 80 to 89\n";
String S90to100= "Students with 90 to 100\n";
int gradeint;
double gradeavg = 0;
int count = 0;
File inputFile = new File("input.txt");
File outputFile = new File("output.txt");
FileInputStream finput = new FileInputStream(inputFile);
FileOutputStream foutput = new FileOutputStream(outputFile);
FileReader reader = new FileReader(inputFile);
BufferedReader in = new BufferedReader(reader);
Scanner std = new Scanner(new File("input.txt"));
Scanner scanner = new Scanner(inputFile);
BufferedWriter out = new BufferedWriter(new FileWriter(outputFile));
Scanner scan = new Scanner(S69andbelow);
//reading linev
line = scanner.nextLine();
st = new StringTokenizer(line, delim);
//avoiding selected characters
try {
while(st.hasMoreTokens()) {
firstname = st.nextToken();
lastname = st.nextToken();
grade = st.nextToken();
//storing tokens into their properties
gradeint = Integer.parseInt(grade);
//converting token to int
gradeavg = gradeavg + gradeint;
//calculating avg
count++;
//recording number of entries
if (gradeint <=69) {
S69andbelow = S69andbelow + lastname + " "
+ firstname + " " + "\t" + grade + "\n";
} // saving data by grades
else if (gradeint >= 70 && gradeint <= 79) {
S70to79 = S70to79 + lastname + " " + firstname
+ " " + "\t" + grade + "\n";
} // saving data by grades
else if (gradeint >= 80 && gradeint <=89) {
S80to89 = S80to89 + lastname + " " + firstname
+ " " + "\t" + grade + "\n";
} // saving data by grades
else {
S90to100 = S90to100 + lastname + " " + firstname
+ " " + "\t" + grade + "\n";
} // saving data by grades
}//end while
System.out.println(S69andbelow + "\n" + S70to79 + "\n"
+ S80to89 + "\n" + S90to100);
//caterorizing the grades
gradeavg = gradeavg/count;
//calculating average
DecimalFormat df = new DecimalFormat("#0.00");
out.write("The average grade is: "
+ df.format(gradeavg));
System.out.println("The average grade is: "
+ df.format(gradeavg));
Writer output = null;
output = new BufferedWriter(new FileWriter(outputFile));
// scanner.nextLine(S69andbelow);
//output.write(S69andbelow + "\n" + S70to79 + "\n"
// + S80to89 + "\n" + S90to100);
// output.close();
}
catch(Exception e) {
System.out.println(e.toString());
}
// Close the stream
try {
if(std != null)
std.close();
}
catch(Exception e) {
System.out.println(e.toString());
}
}
}
내 입력 파일은 다음과 같습니다
Bill Clinton 85 (enter)
Al Gore 100 (enter)
George Bush 95 (enter)
Hillery Clinton 83(enter)
John McCain 72(enter)
Danna Green 87(enter)
Steve Delaney 76(enter)
John Smith(enter)
Beth Bills 60(enter)
그것은 내가 통해 당신에게 모든 방법을 따르지 않는 경우에 대비해 물건을 가리 키도록 도움이 될 것이다.
아주 간단한 방금 여기를 요구하지나요해야한다 : http://stackoverflow.com/questions/5575400/help-please-i-need-help-on-looping-tokenizer-and -notepad-display – edwardsmatt
나는 한 적이 있지만 사람처럼 보이지는 않지만 한 사람이 대답하고 있습니다. – dennis
당신은 단지 처음으로 38 분 전에 질문했습니다 ... 사람들에게 기회를주십시오 ... – edwardsmatt