Please Help with a simple java assignment, stuck!

I'm trying to do my java assignment but I got stuck on a loop. I'm really new to all of this, so it's almost impossible for me. I'm trying to define the class that will take care of reading in different categories (ie assignment, lab assignment, final, midterm) plus their grade in double type from a file, and will update the current subtotal of that category in a certain weight of the class. I have this so far, and I am stuck at the while loop at the bottom where i need to [b]"Write a loop to ask the scanner object to read in each category-mark pair. In the loop, for each read-in pair, update the corresponding sub-total variables."[/b] Any help would be greatly appreciated!

import java.util.*;
public class MarkManager
private PrintWriter writer;

public MarkManager()
try {
writer = new PrintWriter(new BufferedWriter(new FileWriter("cs1073marks", true)));
} catch(IOException e) {System.err.println("Cannot open output file: cs1073marks"); System.exit(1);}

public void saveMark(String category, double mark)
writer.write(category + " " + mark + "

public void close()

public double getTotalScore()
Scanner scanner;
try {
scanner = new Scanner(new File("cs1073marks"));
} catch(IOException e) {System.err.println("Cannot open input file: cs1073marks"); System.exit(2);}
double Lab = 0;
double Assignment = 0;
double Midterm = 0;
double Final = 0;

while (scanner.hasNext())




  • Hey,
    the attached is provided to give you a start. the instructions are not all that clear to me.

    g.l. se52
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


In this Discussion