January 26th, 2013 10:58 AM
#1
File import and read file, HELP PLEASE!!!:) beginner coder
I am trying to write this code but I am running into a brick wall, I Import this file and everything is good. but when I try to add the Players and Par for a Total at the bottom I keep getting different errors. Can someone please help. My code is as follows....
import java.io.*;
import java.util.*;
public class Readscorecard {
private Scanner file;
private double TPar, TPlayer1, TPlayer2 , TPlayer3, TPlayer4;
private double Par, Player1, Player2, Player3, Player4, Sum;
public void scorecard(){
try{
file = new Scanner(new File("golfFile.txt"));
}
catch (Exception e){
System.out.println("you received an Error");
}
}
public void readgolffile(){
System.out.printf("%-10s %1s %12s %12s %12s\n", "Par", "Player 1", "Player 2", "Player 3", "Player 4\n");
while (file.hasNext()){
Par = file.nextDouble(); //Line 31
Player1 = file.nextDouble();
Player2 = file.nextDouble();
Player3 = file.nextDouble();
Player4 = file.nextDouble();
System.out.printf("%-10s %1s %12s %12s %12s\n", Par, Player1, Player2, Player3, Player4);
}
System.out.println("_________________________________________________");
Par = Par + Par;
System.out.println(Par);
}
OUTPUT:
Par Player 1 Player 2 Player 3 Player 4
5.0 6.0 6.0 4.0 7.0
5.0 6.0 2.0 7.0 3.0
3.0 2.0 4.0 4.0 7.0
5.0 5.0 2.0 2.0 4.0
4.0 7.0 5.0 4.0 2.0
5.0 4.0 6.0 7.0 3.0
4.0 2.0 2.0 2.0 2.0
3.0 3.0 7.0 5.0 7.0
5.0 2.0 4.0 6.0 6.0
3.0 7.0 6.0 5.0 4.0
4.0 6.0 3.0 7.0 6.0
5.0 4.0 6.0 5.0 3.0
4.0 4.0 7.0 5.0 3.0
4.0 6.0 4.0 2.0 4.0
4.0 5.0 3.0 3.0 6.0
5.0 3.0 6.0 4.0 2.0
5.0 6.0 7.0 3.0 2.0
3.0 3.0 5.0 4.0 2.0
Tags for this Thread
Posting Permissions
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
Forum Rules
Click Here to Expand Forum to Full Width
Bookmarks