Results 1 to 6 of 6
  1. #1
    Gecko is offline Member
    Join Date
    Mar 2010
    Posts
    4
    Rep Power
    0

    Unhappy Golf Scores Project

    First time posting on this forum, so pardon my mistakes. First year Java student, using Java Software Solutions 6th Edition, have just completed Chapter 5. Here is the project that I'm having problems with:

    Create a text file with golf scores. Each line in the fille will contain five integer values - the first value is Par for that hole, the next four values are scores for each of the four golfers. The file will contain a total of 18 lines (18 holes).

    Your program will:

    1. Read information from the file, add the scores from each hole for each golfer.

    2. Determine their final scores and print those scores.

    3. Determine the winner of this golf game and print a message saying who won.

    4. Produce a table showing how each golfer's score compares to par (ie: 5 over par, 2 under par...ect).


    Borrowing code here and there, I have come up with the following, followed by my errors.

    Java Code:
    import java.util.Scanner;
    import java.io.*;
    
    public class Golf
    {
    	public static void main (String[] args) throws IOException
    	{
    		int g1score=0, g2score=0, g3score=0, g4score=0, par=0;
    		int score, hole=0;
    		String strokes;
    
    		Scanner fileScan, scoresScan;
    
    		fileScan = new Scanner (new File("scores1.txt"));
    
    		while (fileScan.hasNextLine())
    		{
    			strokes = fileScan.nextLine();
    		    scoresScan = new Scanner(strokes);
    		    scoresScan.useDelimiter("/");
    		    par += scoresScan.nextInt();
    		    g1score += scoresScan.nextInt();
    		    g2score += scoresScan.nextInt();
    		    g3score += scoresScan.nextInt();
    		    g4score += scoresScan.nextInt();
             }
    
    		//
    	    //	Produces a table showing each Hole and each Golfer's score for
    	    //	that Hole and how they compare to Par.
    	    //
    		System.out.println("Hole: " + hole++ + "  Par: " + par);
    
    		score = scan.nextInt();
            g1score += score;
            System.out.println("Cheryl: " + (score - par));
    
            score = scan.nextInt();
            g2score += score;
            System.out.println("Del: " + (score - par));
    
            score = scan.nextInt();
            g3score += score;
            System.out.println("Dodi: " + (score - par));
    
            score = scan.nextInt();
            g4score += score;
            System.out.println("Mike: " + (score - par));
            System.out.println();
    
    		//
    		//	Determine final scores and print results
    		//
    		System.out.println("Par is: " + par);
    		System.out.println();
    		System.out.println("Cheryl scored: " + g1score);
    		System.out.println("Del scored: " + g2score);
    		System.out.println("Dodi scored: " + g3score);
    		System.out.println("Mike scored: " + g4score);
    
    		//
    	    //	Determine the winner and print results
    	    //
    	    System.out.println();
    		int small = g4score;
    		if (small > g1score)
    			small = g1score;
    		if (small > g2score)
    		    small = g2score;
    		if (small > g3score)
    		    small = g3score;
    
    		if (small == g1score)
    		    System.out.println("Cheryl is the winner!");
    		if (small == g2score)
    		    System.out.println("Del is the winner!");
    		if (small == g3score)
    		    System.out.println("Dodi is the winner!");
    		if (small == g4score)
    		   	System.out.println("Mike is the winner!");
    
    		System.out.println();
    		int large = g4score;
    		if (large < g1score)
    			large = g1score;
    		if (large < g2score)
    		    large = g2score;
    		if (large < g3score)
    		    large = g3score;
    
    		if (large == g1score)
    		    System.out.println("Cheryl is buying drinks at the 19th hole!");
    		if (large == g2score)
    		    System.out.println("Dodi is buying drinks at the 19th hole!");
    		if (large == g3score)
    		    System.out.println("Del is buying drinks at the 19th hole!");
    		if (large == g4score)
    		   	System.out.println("Mike is buying drinks at the 19th hole!");
    
    	}
    }
    ERROR(S):

    G:\CS161\Labs\BammelC_Lab8\Golf.java:46: cannot find symbol
    symbol : variable scan
    location: class Golf
    score = scan.nextInt();
    ^
    G:\CS161\Labs\Lab8\Golf.java:50: cannot find symbol
    symbol : variable scan
    location: class Golf
    score = scan.nextInt();
    ^
    G:\CS161\Labs\Lab8\Golf.java:54: cannot find symbol
    symbol : variable scan
    location: class Golf
    score = scan.nextInt();
    ^
    G:\CS161\Labs\Lab8\Golf.java:58: cannot find symbol
    symbol : variable scan
    location: class Golf
    score = scan.nextInt();

    What am I doing wrong? Your assistance is appreciated.

  2. #2
    Gecko is offline Member
    Join Date
    Mar 2010
    Posts
    4
    Rep Power
    0

    Default

    PS -

    Everything works (compiles/executes) EXCEPT for the 'table'.

  3. #3
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

    Default

    Quote Originally Posted by Gecko View Post
    ....
    Borrowing code here and there, I have come up with the following, followed by my errors.
    You'll be far better off if you don't try to borrow code and ask us to fix it, but rather create it yourself. Otherwise you'll miss out on the fun of learning. :)

  4. #4
    Gecko is offline Member
    Join Date
    Mar 2010
    Posts
    4
    Rep Power
    0

    Default

    Thank you Fubarable, but I actually learn a lot by 'borrowing' because I still have to know how it works (or in this case...doesn't).

  5. #5
    collin389 is offline Senior Member
    Join Date
    Nov 2009
    Posts
    235
    Rep Power
    5

    Default

    Ok, so reading what the error is saying tells us that variable "scan" does not exist. Is it supposed to? If so, what is it supposed to do? Maybe it's supposed to be fileScan?

  6. #6
    Gecko is offline Member
    Join Date
    Mar 2010
    Posts
    4
    Rep Power
    0

    Default

    Collin389 -

    I tried combining code from a few different sources...something I found here, something that was given to me via myCodeMate (but which I found out contain deprecated code and thus not usable) and something from our Instructor.

    Speaking of which...our Instructor likes to tweak our assignments with stuff that isn't even in the book...which hadn't been a problem prior to this. Anywho...I found a solution and the program now compiles and executes.

    Thank you.

Similar Threads

  1. Need Help with project, uses GUI.
    By absoltrainer in forum New To Java
    Replies: 5
    Last Post: 12-09-2009, 11:45 PM
  2. open existing project project ..
    By itaipee in forum Eclipse
    Replies: 1
    Last Post: 12-28-2008, 08:12 PM
  3. How to use ejb in our project
    By Ragini Shukla in forum Enterprise JavaBeans (EJB)
    Replies: 1
    Last Post: 12-26-2008, 09:29 AM
  4. First Project Need Big Help
    By earl in forum New To Java
    Replies: 1
    Last Post: 01-18-2008, 06:12 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •