Results 1 to 14 of 14
  1. #1
    jcolli08 is offline Member
    Join Date
    Oct 2013
    Posts
    6
    Rep Power
    0

    Post Need some help. keep it simple, please.

    Java Code:
    /* I need help with this! D:
     * jcolli08
     * 10/23/13
     * read the .pdf I have attached. 
       default package!!!
     */
    import java.util.Scanner;
    import java.io.*;
    public class jcolli08Lab3 {
    
    	/**
    	 * @param args
    	 */
    	public static void main(String[] args) throws IOException {
    		// TODO Auto-generated method stub
    		int players = numPlayers();
    		menu(players);
    		
    	} // main ends here.
    	public static void menu(int player) throws IOException
    	{
    	Scanner scan = new Scanner(System.in);
    	int num;
    	System.out.println("1.	Enter Scores.");
    	System.out.println("2.  	Display Scores.");
    	System.out.println("3.      Quit.  ");
    	num = scan.nextInt();
    	if (num == 1)
    		enterScores(player);
    	if (num == 2)
    		displayScores(player);
    	if (num == 3)
    		System.exit(0);
    	scan.close();
    	}// menu ends here.
    	
    	/**
    	 * The enterScores Method asks how many players, then asks three
    	 * scores from each player. Both are then written to "jcolli08.txt".
    	 *  
    	 */
    	public static void enterScores(int numPlayer) throws IOException
    	{
    		String fileName = "jcolli08.txt";
    		Scanner scan = new Scanner(System.in);
    		PrintWriter outFile = new PrintWriter(fileName);
    		int addScore = 0;
    		
    		
    		for (int count = 1; count <= numPlayer; count++)
    		{
    			String name;
    			System.out.println("Enter name of player "+count+". ");
    			name = scan.next();
    			outFile.println(name);
    			scan.nextLine();
    			
    			for (int i = 1; i <= 3; i++)
    			{
    				System.out.println("Enter Score "+i);
    				addScore = scan.nextInt();
    				outFile.println(addScore);
    				
    			}
    			
    		}
    		outFile.close();
    		System.out.println("Data written to '"+fileName+"'.");
    		String input;
    		scan.nextLine();
    		char menuReturn = 'y';
    		System.out.println("Return to menu? (y/n) ");
    		input = scan.nextLine();
    		menuReturn = input.charAt(0);
    		if (menuReturn == ('y'))
    			menu(numPlayer);
    		scan.close();	
    	}
    	
    	/**
    	 * displayScores method reads file and processes it (jcolli08.txt) onto a single
    	 * line per golfer and afterwards calculates and displays the average, minimum, and 
    	 * maximum scores per hole.
    	 * @throws IOException
    	 */
    	public static void displayScores(int numPlayer) throws IOException
    	{
    		String name;
    		int score1, score2, score3; //, avg, min, max;
    		int h1Avg = 0, h1Min = 100, h1Max= 0;  // for hole 1's name/score loop (includes calculation for average, min, and max
    		int h2Avg = 0, h2Min = 100, h2Max = 0;	// for hole 2's name/score loop (includes calculation for average, min, and max
    		int h3Avg = 0, h3Min = 100, h3Max = 0;	// for hole 3's name/score loop (includes calculation for average, min, and max
    		int j = 1;
    		int total1 = 0, total2 = 0, total3 = 0;
    		
    		File file = new File("jcolli08.txt");
    		Scanner inputFile = new Scanner(file);
    		while (j <= numPlayer)
    		{
    			for (int i = 1; i <= 3; i++)
    			{	
    				
    				name = inputFile.nextLine();
    				hole1 = inputFile.nextInt();
    				hole2 = inputFile.nextInt();
    				hole3 = inputFile.nextInt();
    				inputFile.nextLine();
    				System.out.println(name + ":\t"+score1+", "+score2+", "+score3);
    			while (j <= numPlayer)
    			{
    				total1 += hole1;
    				total2 += hole2;
    				total3 += hole3;
    			}
    			
    			
    			} // end of for 
    			h1Avg = total1;
    			h2Avg = total2;
    			h3Avg = total3;
    			System.out.println("Averages:  "+total1+"  "+total2+"   "+total3);
    			
    		}
    		
    			// must average each hole's score, and find minimum, and max of each hole. loop for each hole's scores then display scores.
    			
    		
    			
    			
    			
    /*
    			System.out.println("\n");
    			System.out.println("Hole 1" + ":\t"+h1S1+"\t"+h1S2+"\t"+h1S3+"\t Avg: "+h1Avg + ". Min: "+h1Min+". Max: "+h1Max+". ");
    			System.out.println("Hole 2" + ":\t"+h2S1+"\t"+h2S2+"\t"+h2S3+"\t Avg: "+h2Avg + ". Min: "+h2Min+". Max: "+h2Max+". ");
    			System.out.println("Hole 3" + ":\t"+h3S1+"\t"+h3S2+"\t"+h3S3+"\t Avg: "+h3Avg+ ". Min: "+h3Min+". Max: "+h3Max+". ");
    		*/	
    		
    		inputFile.close();
    		Scanner scan = new Scanner(System.in);
    		String input;
    		char menuReturn = 'y';
    		System.out.println("Return to menu? (y/n) ");
    		input = scan.nextLine();
    		menuReturn = input.charAt(0);
    		if (menuReturn == ('y'))
    			menu(numPlayer);
    		scan.close();	
    	}
    	public static int numPlayers() 
    	{
    		Scanner scan1 = new Scanner(System.in);
    		System.out.println("How many players do you have?");
    		int numPlayers = scan1.nextInt();
    		int playerNum = numPlayers;
    		scan1.close();
    		return playerNum;
    	}
    
    }
    Attached Files Attached Files
    Last edited by JosAH; 10-31-2013 at 06:43 AM. Reason: added [code] ... [/code] tags

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,371
    Blog Entries
    7
    Rep Power
    20

    Default Re: Need some help. keep it simple, please.

    What help? Doesn't it compile? Doesn't is run? Throws your code an Exception of some sort? Please be a bit more detailed.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  3. #3
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    3,733
    Rep Power
    5

    Default Re: Need some help. keep it simple, please.

    Also strip the multiline comments, they are apparently confusing the forum's syntax highlighter.

    Bit of a stretch by the way, demanding "keep it simple please" in the subject and then creating an impossible to answer post due to total lack of any kind of question at all.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  4. #4
    jcolli08 is offline Member
    Join Date
    Oct 2013
    Posts
    6
    Rep Power
    0

    Default Re: Need some help. keep it simple, please.

    Quote Originally Posted by gimbal2 View Post
    Also strip the multiline comments, they are apparently confusing the forum's syntax highlighter.

    Bit of a stretch by the way, demanding "keep it simple please" in the subject and then creating an impossible to answer post due to total lack of any kind of question at all.
    dude, I gave the prompt and by "keep it simple" I mean not to use arrays (which would make this a helluva lot easier, but we're not supposed to be using them yet). Use what's given in my program (no importing complex classes, etc.). Anyways, all it would have taken is running the program within a default java runtime environment, (jr7), then realizing that I'm not displaying the results from the file properly. I'm sure I'm writing it to file correctly, but it's the displayScores method that gets me. If you can get it to do what's said in the pdf, i'd appreciate it a lot if someone could show me how to do it and explain it (if I don't facepalm myself after seeing the answer first). Thanks for your time, and sorry for not clarifying.

  5. #5
    jcolli08 is offline Member
    Join Date
    Oct 2013
    Posts
    6
    Rep Power
    0

    Default Re: Need some help. keep it simple, please.

    The multi-line comments are there because I commented that section of the code out. If I mean it to not run, why would it confuse the sytax on forums? Did you think I meant to run that section and hence misunderstood or is there something I'm missing? New to the forums sorry.

  6. #6
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    3,413
    Rep Power
    5

    Default Re: Need some help. keep it simple, please.

    Quote Originally Posted by jcolli08 View Post
    dude, I gave the prompt and by "keep it simple" I mean not to use arrays (which would make this a helluva lot easier, but we're not supposed to be using them yet).
    This is why you need to be specific. For most folks on this forum (or the ones who are likely to provide help to you), arrays are simple.

    Regards,
    Jim
    The Java™ Tutorial | SSCCE | Java Naming Conventions
    Poor planning our your part does not constitute an emergency on my part.

  7. #7
    Tolls is online now Moderator
    Join Date
    Apr 2009
    Posts
    11,841
    Rep Power
    19

    Default Re: Need some help. keep it simple, please.

    Quote Originally Posted by jcolli08 View Post
    The multi-line comments are there because I commented that section of the code out. If I mean it to not run, why would it confuse the sytax on forums? Did you think I meant to run that section and hence misunderstood or is there something I'm missing? New to the forums sorry.
    The forum software is a bit rubbish at handling the /*..*/ style comments, and frequently misses the closing */, resulting in lots of code looking like it's been commented out. The only way around it is to not use them.

    By the way, expecting someone to actually run your code to see the problem is a sure fire way to lose a lot of the people who might be able to help. You need to actually describe your problem, and post code that is relevant to the problem. A narrowed down question is far more likely to get an answer than a code dump and a pdf.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  8. #8
    jcolli08 is offline Member
    Join Date
    Oct 2013
    Posts
    6
    Rep Power
    0

    Default Re: Need some help. keep it simple, please.

    Solved it. nvm
    Last edited by jcolli08; 11-01-2013 at 06:34 AM.

  9. #9
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,755
    Rep Power
    7

    Default Re: Need some help. keep it simple, please.

    First you post unreadable code due to blocks being commented out. Now you post code that is not formatted at all. You are not going to get much help. Before you fly off into a rage and start abusing people Google "ask questions the smart way". Follow that advice and people will be more than willing to help you.

  10. #10
    jcolli08 is offline Member
    Join Date
    Oct 2013
    Posts
    6
    Rep Power
    0

    Default Re: Need some help. keep it simple, please.

    Quote Originally Posted by Junky View Post
    First you post unreadable code due to blocks being commented out. Now you post code that is not formatted at all. You are not going to get much help. Before you fly off into a rage and start abusing people Google "ask questions the smart way". Follow that advice and people will be more than willing to help you.
    Solved it myself. I don't need help from condescending pricks. I wasn't flying into any rage. You're just acting like a troll and I'm not gonna feed ya. I'm outta here.

  11. #11
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,371
    Blog Entries
    7
    Rep Power
    20

    Default Re: Need some help. keep it simple, please.

    Quote Originally Posted by jcolli08 View Post
    Solved it myself. I don't need help from condescending pricks. I wasn't flying into any rage. You're just acting like a troll and I'm not gonna feed ya. I'm outta here.
    Good decision because this forum doesn't need posters like you.

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  12. #12
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    3,733
    Rep Power
    5

    Default Re: Need some help. keep it simple, please.

    Its nutrition I tell you. All these carb-rich diets nowadays with a total lack of saturated fats is damaging the brains of all these unfortunates around the world.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  13. #13
    Tolls is online now Moderator
    Join Date
    Apr 2009
    Posts
    11,841
    Rep Power
    19

    Default Re: Need some help. keep it simple, please.

    Quote Originally Posted by Junky View Post
    First you post unreadable code due to blocks being commented out.
    To be fair, that is the fault of the forum software.
    It's inability to handle /*..*/ blocks is quite annoying at times.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  14. #14
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    3,733
    Rep Power
    5

    Default Re: Need some help. keep it simple, please.

    Quote Originally Posted by Tolls View Post
    To be fair, that is the fault of the forum software.
    It's inability to handle /*..*/ blocks is quite annoying at times.
    True enough, but it is still the fault of the poster to leave it like that, especially something that obviously visible. People who either do not review their own posts or see the problem and then just leave it like that show a clear lack of willingness to invest time into asking a proper question.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

Similar Threads

  1. Simple program, simple problem
    By taymilll in forum New To Java
    Replies: 12
    Last Post: 06-20-2011, 05:12 AM
  2. 30 line simple gui, simple error, need help
    By cc11rocks in forum New To Java
    Replies: 6
    Last Post: 02-05-2011, 08:33 PM
  3. Replies: 2
    Last Post: 05-04-2008, 05:27 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
  •