Question

PLEASE UPLOAD or Write a simple pesudo code and java code for this program with comments...

PLEASE UPLOAD or Write a simple pesudo code and java code for this program with comments in both describe what things do.

Problem Statement

A golf club has a small tournament consisting of five golfers every weekend. The club president has asked you to design a program that does the following:

Reads player’s names and their scores from the keyboard for each of the five golfers and simulates writing them to a file called "golf.dat" Entering "Z" for the player name will end user input.

Reads the contents of golf.dat and displays contents.

Expected Input/Output

Your results should be similar to the following:

Enter player Name (Z to terminate): Tiger Woods
Enter score: 72

Enter Player Name (Z to terminate): Rory McElroy
Enter Score: 70

Enter player name (Z to terminate): Dustin Johnson
Enter score: 67

Enter player name (Z to terminate): Patrick Reed
Enter score: 69

Enter player name (Z to terminate): Jim Furyk
Enter score: 71

Enter player name (Z to terminate): Z

Player: Tiger Woods Score: 72
Player: Rory McElroy Score: 70
Player: Dustin Johnson Score: 67
Player: Patrick Reed Score: 69
Player: Jim Furyk Score: 71
0 0
Add a comment Improve this question Transcribed image text
Answer #1

If you have any doubts, please give me comment...

import java.io.*;

import java.util.Scanner;

public class GolfGame{

    public static void main(String[] args) {

        Scanner scnr = new Scanner(System.in);

        String pname;

        int score;

        try{

            PrintWriter pw = new PrintWriter(new File("golf.dat"));

            System.out.print("Enter player Name (Z to terminate): ");

            pname = scnr.nextLine();

            while(!pname.equals("Z")){

                System.out.print("Enter score: ");

                score = Integer.parseInt(scnr.nextLine());

                pw.println(pname);

                pw.println(score);

                System.out.print("\nEnter player Name (Z to terminate): ");

                pname = scnr.nextLine();    

            }

            pw.close();

            Scanner scnrFile = new Scanner(new File("golf.dat"));

            while(scnrFile.hasNextLine()){

                pname = scnrFile.nextLine();

                score = Integer.parseInt(scnrFile.nextLine());

                System.out.println("Player: "+pname+" Score: "+score);

            }

            scnrFile.close();

        }catch(FileNotFoundException e){

            System.out.println(e.getMessage());

        }

    }

}

Add a comment
Know the answer?
Add Answer to:
PLEASE UPLOAD or Write a simple pesudo code and java code for this program with comments...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • PLEASE UPLOAD or Write a simple PSEUDO CODE AND JAVA CODE for this program WITH COMMENTS...

    PLEASE UPLOAD or Write a simple PSEUDO CODE AND JAVA CODE for this program WITH COMMENTS IN BOTH TELLING WHAT EACH PART DOES. (I NEED BOTH CODES NOT JUST ONE OR THE OTHER) Problem Statement A golf club has a small tournament consisting of five golfers every weekend. The club president has asked you to design a program that does the following: Reads player’s names and their scores from the keyboard for each of the five golfers and simulates writing...

  • #PLEASE WRITE THE CODE IN JAVA! THANK YOU IN ADVANCE! Write a program that manages a...

    #PLEASE WRITE THE CODE IN JAVA! THANK YOU IN ADVANCE! Write a program that manages a list of up to 10 players and their high scores in the computer's memory. Use two arrays to manage the list. One array should store the players' names, and the other array should store the players' high scores. Use the index of the arrays to correlate the names with the scores. Your program should support the following features: a. Add a new player and...

  • .Need code for my java class !! Write a simple java program that uses loops. You...

    .Need code for my java class !! Write a simple java program that uses loops. You may use ‘WHILE’ or ‘FOR’ or ‘DO-WHILE’ – you decide. The program should use a loop to compute the semester average for up to 5 students. In the loop the user will ask for a student name and their 3 test scores and add them up and divide the total by 3 giving the semester average. You will print out the student name and...

  • Please help as it is very important task for me please write in Python code and...

    Please help as it is very important task for me please write in Python code and divide this into function and write comments for it 1. Ask the player’s name and welcome them to the game using their name. 2. Ask the player what is par for this game (number between 3-5 inclusive) 3. Ask the player what the distance to the hole for this game is (whole number between 195 and 250 inclusive) 4. Show the game menu: (I)nstructions...

  • Write the C program, to achieve as shown in the sample code execution, using the given...

    Write the C program, to achieve as shown in the sample code execution, using the given struct and using the comments in the given main program below: typedef struct{ char first[20]; char last[20]; float gpa; int score; } student; int main(void){ student *ptr; //first name //last name //student gpa //student score } //ask a user to enter the number of students, num //dynamically allocate memory for an array of students of the appropriate size (i.e. //num that the user just...

  • Please write this in C. Write this code in Visual Studio and upload your Source.cpp file for checking (1) Write a program to prompt the user for an output file name and 2 input file names. The progra...

    Please write this in C. Write this code in Visual Studio and upload your Source.cpp file for checking (1) Write a program to prompt the user for an output file name and 2 input file names. The program should check for errors in opening the files, and print the name of any file which has an error, and exit if an error occurs opening any of the 3 For example, (user input shown in caps in first line) Enter first...

  • using java Program: Please read the complete prompt before going into coding. Write a program that...

    using java Program: Please read the complete prompt before going into coding. Write a program that handles the gradebook for the instructor. You must use a 2D array when storing the gradebook. The student ID as well as all grades should be of type int. To make the test process easy, generate the grade with random numbers. For this purpose, create a method that asks the user to enter how many students there are in the classroom. Then, in each...

  • Please help. I need a very simple code. For a CS 1 class. Write a program...

    Please help. I need a very simple code. For a CS 1 class. Write a program in Java and run it in BlueJ according to the following specifications: The program reads a text file with student records (first name, last name and grade). Then it prompts the user to enter a command, executes the command and loops. The commands are the following: "printall" - prints all student records (first name, last name, grade). "firstname name" - prints all students with...

  • For this lab you will write a Java program that plays a simple Guess The Word...

    For this lab you will write a Java program that plays a simple Guess The Word game. The program will prompt the user to enter the name of a file containing a list of words. These words mustbe stored in an ArrayList, and the program will not know how many words are in the file before it starts putting them in the list. When all of the words have been read from the file, the program randomly chooses one word...

  • CREATE TWO C++ PROGRAMS : Program 1 Write a program that reads in babynames.txt (provided) and...

    CREATE TWO C++ PROGRAMS : Program 1 Write a program that reads in babynames.txt (provided) and outputs the top 20 names, regardless of gender. The file has the following syntax: RANK# BoyName Boy#OfBirths Boy% GirlName Girl#OfBirths Girl% You should ignore the rank and percentages. Compare the number of births to rerank. Output should go to standard out. Program 2 Write a program that reads a text file containing floating-point numbers. Allow the user to specify the source file name on...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT