ok what my program is suppost to do is open a file - Grades.txt and read each line the breaking the lines down w/ tokens so i may later average some numbers
an example some of the lines from the text is:
234-42-1111 90 80 23 67
214-77-2222 12 45 80
112-45-7689 99 82 71 45
it has a id number on the left and grades on the right.
Im having trouble with reading the text into a string and exempting the lowest grades and then average them at the end
My codes so far is :
import java.util.StringTokenizer;
import java.io.*;
public class Exemption
{
public static void main (String [] args) throws IOException
{
// Strings
String studentNumber, studentgrade;
// access grades.txt
FileReader Grades = new FileReader("Grades.txt");
BufferedReader inputFile = new BufferedReader(Grades);
// reading lines
studentNumber = inputFile.readLine();
System.out.println("Reading file Grades.txt");
System.out.println("");
System.out.println("The grades for the class are listed below:");
System.out.println("");
// display and keep reading
while (studentNumber != null)
{
// display student number
System.out.println(studentNumber);
// read next student number
studentNumber = inputFile.readLine();
}
System.out.println("");
System.out.println("Next we will find out who is excempted from the final");
// tokens
String line, fileIn = "Grades.txt", fileOut = "Exempt.txt";
StringTokenizer tokens;
String name;
//input
FileReader fr = new FileReader(fileIn);
BufferedReader inFile= new BufferedReader(fr);
//output
FileWriter fw = new FileWriter (fileOut);
BufferedWriter bw = new BufferedWriter (fw);
PrintWriter outFile = new PrintWriter (bw);
line = inFile.readLine();
while (line != null)
{
tokens = new StringTokenizer(line);
name = null;
if (tokens.hasMoreTokens())
name = tokens.nextToken();
}
inputFile.close();
}
}
COULD SOMEBODY HELP ME PLEASE!!!
4 1999
First of all, put your code in code tags please (when you post look to the right in the box that says "REPLAY GUIDELINES"). It's incredibly hard to read this way.
Are you reading from the file twice in the same method? Why?
I don't understand why you're just setting name to be every tokenizer one at a time.
Think about what you're trying to produce. Think about how you want to output it.
Edit: I think this is what you should be doing: tokenizing the string, making the first one equal to the student ID and taking the rest, one a time parsing them into an int and storing them. Then, after averaging them, keep the average. Sound about right?
Hope this helped
-blazed
- import java.util.StringTokenizer;
-
import java.io.*;
-
-
-
public class Exemption
-
{
-
public static void main (String [] args) throws IOException
-
{
-
// Strings
-
String studentNumber, studentgrade;
-
-
// access grades.txt
-
-
FileReader Grades = new FileReader("Grades.txt");
-
BufferedReader inputFile = new BufferedReader(Grades);
-
-
// reading lines
-
studentNumber = inputFile.readLine();
-
System.out.println("Reading file Grades.txt");
-
System.out.println("");
-
System.out.println("The grades for the class are listed below:");
-
System.out.println("");
-
-
// display and keep reading
-
while (studentNumber != null)
-
{
-
// display student number
-
System.out.println(studentNumber);
-
// read next student number
-
studentNumber = inputFile.readLine();
-
}
-
-
-
System.out.println("");
-
System.out.println("Next we will find out who is excempted from the final");
-
-
// tokens
-
String line, fileIn = "Grades.txt", fileOut = "Exempt.txt";
-
StringTokenizer tokens;
-
String name;
-
-
//input
-
FileReader fr = new FileReader(fileIn);
-
BufferedReader inFile= new BufferedReader(fr);
-
-
//output
-
FileWriter fw = new FileWriter (fileOut);
-
BufferedWriter bw = new BufferedWriter (fw);
-
PrintWriter outFile = new PrintWriter (bw);
-
-
line = inFile.readLine();
-
while (line != null)
-
{
-
tokens = new StringTokenizer(line);
-
name = null;
-
-
if (tokens.hasMoreTokens())
-
name = tokens.nextToken();
-
-
-
}
-
inputFile.close();
-
-
-
}
-
-
-
-
-
}
-
- import java.util.StringTokenizer;
-
import java.io.*;
-
-
-
public class Exemption
-
{
-
public static void main (String [] args) throws IOException
-
{
-
// Strings
-
String studentNumber, studentgrade;
-
-
// access grades.txt
-
-
FileReader Grades = new FileReader("Grades.txt");
-
BufferedReader inputFile = new BufferedReader(Grades);
-
-
// reading lines
-
studentNumber = inputFile.readLine();
-
System.out.println("Reading file Grades.txt");
-
System.out.println("");
-
System.out.println("The grades for the class are listed below:");
-
System.out.println("");
-
-
// display and keep reading
-
while (studentNumber != null)
-
{
-
// display student number
-
System.out.println(studentNumber);
-
// read next student number
-
studentNumber = inputFile.readLine();
-
}
-
-
-
System.out.println("");
-
System.out.println("Next we will find out who is excempted from the final");
-
-
// tokens
-
String line, fileIn = "Grades.txt", fileOut = "Exempt.txt";
-
StringTokenizer tokens;
-
String name;
-
-
//input
-
FileReader fr = new FileReader(fileIn);
-
BufferedReader inFile= new BufferedReader(fr);
-
-
//output
-
FileWriter fw = new FileWriter (fileOut);
-
BufferedWriter bw = new BufferedWriter (fw);
-
PrintWriter outFile = new PrintWriter (bw);
-
-
line = inFile.readLine();
-
while (line != null)
-
{
-
tokens = new StringTokenizer(line);
-
name = null;
-
-
if (tokens.hasMoreTokens())
-
name = tokens.nextToken();
-
-
-
}
-
inputFile.close();
-
-
-
}
-
-
-
-
-
}
-
My main problem is how to put the file into strings i guess to separate the id from the grades? Im very new with this so its kind of confusing!
Read entire lines using a BufferedReader; split every line into individual
tokens using the String.split() method. Tokenizers are clumsy.
Alternatively use a Scanner to read ordinary int numbers.
kind regards,
Jos
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Grrrbau |
last post by:
I'm a beginner.
I'm looking for a good C++ book.
Someone told me about Lafore's "Object-Oriented Programming in C++".
What do you think?
Grrrbau
|
by: WAYNEL |
last post by:
Hi
I am trying to re-write some of the example code that Agilent gives for
VB to VB.Net.
In .Net I keep getting the error 'cannot change the number of
dimensions of an array'.
I have paste...
|
by: john_g83 |
last post by:
Hello all, new user to c programming and am having difficulty with a
little program I am trying to write. Basically what I have is a file
which contains a list of words i.e:
tst.txt:
customer...
|
by: hothead098 |
last post by:
ASSIGNMENT (4) USING AND MANIPUPATING ARRAYS (Chapter 10 material)
For this assignment you are to:
1) Create and manage arrays
a) One of type integers (containing 10 elements).
b) One of...
|
by: Martin Jørgensen |
last post by:
Hi,
In continuation of the thread I made "perhaps a stack problem? Long
calculations - strange error?", I think I now got a "stable" error,
meaning that the error always seem to come here now...
|
by: Tyler |
last post by:
Hello All:
After trying to find an open source alternative to Matlab (or IDL), I
am currently getting acquainted with Python and, in particular SciPy,
NumPy, and Matplotlib. While I await the...
|
by: Amali |
last post by:
I'm newdie in c programming. this is my first project in programming.
I have to write a program for a airline reservation. this is what i
have done yet. but when it runs it shows the number of...
|
by: ianenis.tiryaki |
last post by:
well i got this assignment which i dont even have a clue what i am
supposed to do. it is about reading me data from the file and load
them into a parallel array here is the question:
Step (1)
...
|
by: ndedhia1 |
last post by:
I am reading in a file to see what delays I am getting on what IP address:
QuoteBlockTiming exceeded 1000 ms: 1684 --- Fri Nov 06 06:09:10 CST 2009 170.137.94.95 Class key = 649126730 block...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
| |