|
-
January 29th, 2013, 12:59 PM
#3
Re: File import and read file, HELP PLEASE!!!:) beginner coder
thank you Alex for your reply. I do need to have a total of all the numbers by column. for instance....column 1 Par, Column 2-5 Player1-4. I have tried different ways to get a total, my latest attempt has been to tackle it column by column, but do not know or understand where to start. I can import the file which the professor gave us to use but I can not get it to add the columns at the bottom. at this point I am dazed and confused.. I need help !!
This is my latest attempt....
It runs great, BUT it doesn't have the Columns added at the bottom of it, which is where I don't know how to get to start or complete it.
import java.io.*;
import java.util.*;
public class Readscorecard {
public static void main(String[] args) {
// TODO Auto-generated method stub
Readscorecard h = new Readscorecard ();
h.scorecard();
h.readgolffile();
h.closefile();
}
private Scanner file;
private double TPar, TPlayer1, TPlayer2 , TPlayer3, TPlayer4;
private int 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");
Par = 0;
Player1 = 0;
while (file.hasNext()){
Par = file.nextInt();
TPar = Par;
TPar = TPar + Par;
Player1 = file.nextInt();
TPlayer1 = Player1++;
Player2 = file.nextInt();
Player3 = file.nextInt();
Player4 = file.nextInt();
System.out.printf("%-10s %1s %12s %12s %12s\n", Par, Player1, Player2, Player3, Player4);
}
System.out.println("_________________________________________________");
System.out.printf("%-10s %1s %12s %12s %12s\n", TPar, TPlayer1, Player2, Player3, Player4);
}
public void closefile(){
file.close();
}
}
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
|