Problem in Java Program...... need help


Joined
Oct 9, 2007
Messages
3
Reaction score
0
I have written the program but it is not giving me the outour as I want.
My program indicates
TEST 01 90
Fred 75
Mary 90
TEST 02 100
Fred 92
Mary 97
Using this as input create the following output in file GradesOut.txt. The first few lines:

For Test #01 Fred got 75 points or 83.3%
For Test #01 Mary got 90 points or 100.0%
TEST #01: 90 points, Total Points: 165, students: 2

For Test #02 Fred got 92 points or 92.0%
For Test #02 Mary got 97 points or 97.0%
TEST #02: 100 points, Total Points: 189, students: 2

You can assume all numeric input will be integers. Use a while loop to go through all records and probably an instance of Scanner to get the fields in each line.

If the first field read is "TEST" then the second field is the test # and the third is the total possible points. Otherwise the first field is a name and the second is the score on the test.

Upload your java file and both the input and output files under the WebCT assignment. Do not change the input file. I will be looking for specific output at certain lines. Make certain your file will compile as you have named it. Do not use the path in the filename in your program -- i.e., the input file should just be "grades.txt".

And the input file is
TEST 01 90
Fred 75
Mary 90
TEST 02 100
Fred 92
Mary 97
TEST 07 80
Rosemarie 58
Lorene 73
Melba 57
Cecelia 72
Rochelle 54
Emanuel 63
Christie 51
Simon 51
Orville 79
Estelle 78
Pat 69
Wilbert 56
Shari 71
Jana 78
Ignacio 65
Laurence 52
Kerry 60
Santiago 51
Dewey 63
Laverne 76
Sophie 53
Nichole 65
Marcos 65
Patti 51
Kellie 69
Sophia 78
Silvia 77
Jake 65
Elisa 79
Ollie 63
Delia 69
Faith 76
Amos 56
Eula 69
Krystal 71
Nadine 77
Cary 60
Tasha 61
Terence 71
Dixie 77
Alyssa 60
Mercedes 50
Mandy 78
Emmett 76
Lana 62
Ernestine 61
Dallas 78
Cornelius 56
Van 74
Antonia 63
Alonzo 71
Sonja 69
Alexis 69
Rachael 55
Gwen 72
Caleb 62
Elbert 69
Aubrey 50
Jenna 60
Courtney 62
Lorena 70
Phil 77
Cristina 66
Kari 71
Lela 78
Ebony 50
Mack 69
Miranda 76
Bradford 57
Sammy 57
Saul 62
Ginger 77
Betsy 65
Ora 56
Jasmine 71
Marta 66
Kate 61
Dexter 63
Ismael 62
Tomas 67
Darin 70
Jan 53
Guadalupe 56
Tami 69
Israel 75
Irvin 54
Darrel 63
Doyle 52
Camille 77
Stewart 50
Taylor 71
Rolando 77
Lora 50
Jeannie 66
Jody 55
Leland 78
Randal 68
Sheldon 80
Chelsea 60
Bert 69
Freda 61
Al 80
Emilio 63
Tabitha 50
Elsa 59
Erick 69
Grady 54
Bryant 79
Moses 75
Clark 53
Gretchen 50
Elena 50
Noah 74
Desiree 64
Teri 50
Paulette 73
Roman 60
Olive 74
Darrin 62
Abel 57
Lila 52
Lionel 67
Gustavo 58
Muriel 51
Dianna 50
Conrad 68
Boyd 77
Janis 65
Darla 60
Nettie 70
Percy 68
Traci 50
May 59
Woodrow 80
Marcella 77
Sadie 65
Carroll 56
Jaime 75
Terrell 51
Casey 72
Elias 64
Mindy 63
Ramiro 77
Leigh 64
Drew 57
Owen 76
Meredith 53
Raquel 65
Santos 60
Marlon 64
Tricia 50
Rufus 52
Kendra 58
Shawna 59
Irving 51
Ellis 74
Tommie 69
Toby 80
Levi 52
Angel 52
Eloise 63
Josefina 61
Winston 62
Johanna 56
Clay 58
Kristopher 53
Clint 57
Elvira 69
Darnell 79
Ervin 72
Hugo 68
Mona 61
Forrest 58
Brendan 63
Lucia 61
Rogelio 69
Elijah 60
Mable 62
Jermaine 71
Lynette 59
Domingo 67
Angelina 73
Nicolas 54
Josh 51
Meghan 75
Hope 78
Lamar 56
Gilberto 68
Kelley 51
Doreen 51
Marty 63
Dominick 75
Frankie 52
Wilfred 55
Henrietta 77
Bernadette 66
Merle 58
Jody 71
Timmy 75
Essie 53
My program is below.
// Program, to get student record.

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


public class Grades {

public static void main(String args[])
throws FileNotFoundException{

Scanner infile = new Scanner(new FileReader ("Grades.txt"));
PrintWriter outfile = new PrintWriter("testscore.txt");

int testtotal = 0;
int studentcount = 0;
String name = " ";
String studentoutput = " ";
int testnum = 0 ;
int testscore = 0 ;
int testpoints = 0;
double studentpercent;

while(infile.hasNext() ){
name = infile.next();
if(name.equals ("TEST") ){
outfile.println(name);

if(studentcount > 0){
outfile.println(studentcount);

outfile.println("for test #" + testnum + "the test points are"
+ testpoints + " and the total student count for this field is"
+ studentcount + "and the percent is" + studentpercent);
}
testnum = infile.nextInt();
outfile.println(testnum);

testtotal = infile.nextInt();
outfile.println(testtotal);
}
else{
outfile.println( name);

testscore = infile.nextInt();
outfile.println(testscore);

totalpoints = totalpoints + testscore;
studentcount = studentcount + 1;

studentpercent = testscore/testtotal * 100;
outfile.println(studentpercent);

studentoutput = name + " " + testnum + " " + " " + testtotal + " "
+ testscore + studentpercent ;
outfile.println(studentoutput);
}

}
infile.close();
outfile.close();
}
}

If any one can help, will be appeciate.
Thanks
 
Ad

Advertisements


Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top