Question

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 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

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)

0 0
Add a comment Improve this question Transcribed image text
Answer #1

CODE:

//importing the required classes
import java.util.Scanner;
import java.io.IOException;
import java.io.File;
import java.io.FileOutputStream;
import java.io.DataOutputStream;
import java.io.FileInputStream;
import java.io.DataInputStream;
//driver class
public class GolfScoreRecord {
   public static void main(String[] args) {
       //instantiating scanner class to take the input names and score
       Scanner scanner = new Scanner(System.in);
       // variables that hold the playerName and score
   String playerName, score;
   try{
       // the DataOutputStream object that writes to the file
   DataOutputStream output = new DataOutputStream(new FileOutputStream("golf.dat"));
     
   //while loop to read playernames and score till the user enters Z
   while(true) {
       // prompt for name
   System.out.print("Enter player Name (Z to terminate):");
   // getting the name
   playerName = scanner.nextLine();
   // if the input is Z break the loop
   if(playerName.equals("Z")){
       break;
   }else{
       // else read in the player score
       System.out.print("Enter score: ");
       score = scanner.nextLine();
   }
   // write the output to the file
   output.writeChars("Player: " + playerName + " Score: " + score + "\n");
   }
   // closing the DataOutputStream object
   output.close();
   }
   catch(IOException ex){
   ex.getMessage();
   }
   // code to read the dat file
   try{  
       // scanner object that reads the data from the dat file
       Scanner input = new Scanner(new File("golf.dat"));
       String line;
       // loop to read the entire content of the file
   while (input.hasNext()) {
       // getting the line from file
       line = input.nextLine();
       // printing to the console
   System.out.println(line);
   }
   //close the input
   input.close();
   }catch(IOException e){
       e.getMessage();
   }
   }
}

OUTPUT:

Add a comment
Know the answer?
Add Answer to:
PLEASE UPLOAD or Write a simple PSEUDO 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 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...

  • (PLEASE UPLOAD ALL PARTS TO THE QUESTION) (IE: PSEUDO CODE AND JAVA CODE TOGETHER NOT ONE...

    (PLEASE UPLOAD ALL PARTS TO THE QUESTION) (IE: PSEUDO CODE AND JAVA CODE TOGETHER NOT ONE OR THE OTHER) Design an Employee class that fields for the following pieces of information: 1) Employee name 2) Employee number Next design a class named ProductionWorker that extends the Employee class. The ProductionWorker class should have fields to hold the following information: 1) Shift number (an integer, such as 1, 2, or 3) 2)Hourly pay The workday is divided into two shifts day...

  • (PLEASE UPLOAD ALL PARTS TO THE QUESTION) (IE: PSEUDO CODE AND JAVA CODE TOGETHER NOT ONE...

    (PLEASE UPLOAD ALL PARTS TO THE QUESTION) (IE: PSEUDO CODE AND JAVA CODE TOGETHER NOT ONE OR THE OTHER) Design an Employee class that fields for the following pieces of information: 1) Employee name 2) Employee number Next design a class named ProductionWorker that extends the Employee class. The ProductionWorker class should have fields to hold the following information: 1) Shift number (an integer, such as 1, 2, or 3) 2)Hourly pay The workday is divided into two shifts day...

  • #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...

  • guys can you please help me to to write a pseudo code for this program and...

    guys can you please help me to to write a pseudo code for this program and write the code of the program in visual studio in.cpp. compile the program and run and take screenshot of the output and upload it. please help is really appreciated. UTF-8"CPP Instruction SU2019 LA X 119SU-COSC-1436- C Get Homework Help With Che X Facebook -1.amazonaws.com/blackboard.learn.xythos.prod/584b1d8497c84/98796290? response-content-dis 100% School of Engineering and Technology COSC1436-LAB1 Note: in the instruction of the lab change "yourLastName" to your last...

  • 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...

  • .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...

  • 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...

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