Howdy, Stranger!

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

Sign In with Facebook Sign In with Google Sign In with OpenID


We have migrated to a new platform! Please note that you will need to reset your password to log in (your credentials are still in-tact though). Please contact if you have questions.
Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Please Help with a simple java assignment, stuck!

ryou00730ryou00730 Posts: 1Member
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())




Sign In or Register to comment.