Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please read the instructions and finish the code. Please read the comments as well as you code :) All the info is pasted here for

Please read the instructions and finish the code. Please read the comments as well as you code :) All the info is pasted here for you.

Thank you for your help!

image text in transcribed

image text in transcribed

This class is complete. It does not need anything.

/**

* Salary for baseball players is stored.

*

*/public class PlayerSalary

{

//Constructor for objects of class PlayerSalary

int yearID;

String teamID;

String leagueID;

String playerID;

int salary;

public PlayerSalary(int yearID, String teamID, String leagueID, String playerID, int salary)

{

// initialize instance variables

this.yearID = yearID;

this.teamID = teamID;

this.leagueID = leagueID;

this.playerID = playerID;

this.salary = salary;

}

/**

* returns a String representation of a PlayerSalary object

*/

public String toString(){

return "Players information " +

" Year : " + yearID +

" Team : " + teamID +

" League : " + leagueID +

" Player : " + playerID +

" Salary : " + salary ; // this is the format with info

}

// Add getter methods below

public int getYearID() { return yearID; }

public String getTeamID() { return teamID; }

public String getLeagueID() { return leagueID; }

public String getPlayerID() { return playerID; }

public int getSalary() { return salary; }

// Add a main method here to test this class

public static void main(String [] args){

PlayerSalary info$ = new PlayerSalary(2015,"Lakers","NBA","Some",60000) ;

System.out.println(info$.getPlayerID());

System.out.println(info$.getYearID());

System.out.println(info$.getLeagueID());

}

}

// edn of class

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

This is where the playerSalary class is going to be used.

import java.io.File;

import java.io.FileNotFoundException;

import java.util.*;

/*

* PlayerSalaries database

*/

public class PlayerSalaries

{

ArrayList salaries = new ArrayList(); // I added the Played

public PlayerSalaries(String filename) throws FileNotFoundException

{

//Get scanner instance - this will read lines from file

Scanner scanner = new Scanner(new File(filename));

// Process CSV file -

// reading line of text, then scanning the text for tokens

// delimited by comma or end of line

// Read the first int in file - it indicates how many

// records follow

int howMany = scanner.nextInt();

// Instantiate/allocate salaries list - use

// first number in file to set list capacity

// YOUR CODE to instantiate/allocate salaries list GOES HERE

salaries = new ArrayList(howMany);

// Consume rest of line 1

scanner.nextLine();

scanner.nextLine();// And consume line 2

// Read each line/record in file

// currenlty only reads 2 lines so you can see what is happening.

// When you are comfortable processing all data in file,

// change 3 to howMany

for(int lineNum = 1; lineNum

{

// Read entire line into a String

String line = scanner.nextLine();

// Associate a Scanner with the String

Scanner lineScanner = new Scanner(line);

// State that commas will be the delimiter/separator -

// since the data in a CSV file

lineScanner.useDelimiter(",");

// The following code domonstrates how to pull words out of file

System.out.println(" This is what is on line " + lineNum);

while(lineScanner.hasNext()){ // parse line

// Read a word and print it

System.out.println(lineScanner.next().get(4));

//System.out.println(lineScanner.nextLine());

}

// ADD CODE to create a PlayerSalary object and add it to the database

}

}

public int averageSalaryInYear(int year)

{

int salaries, count, i ;

double avg;

// for ( i = ; i

//placeholder return, this should return average salary int

return -1;

}

public PlayerSalary findPlayerInYear(String player, int year)

{

//placeholder return, this should return PlayerSalary Object

return null ;

}

public PlayerSalary highestSalaryInYear(int year)

{

//placeholder return, this should return PlayerSalary Object

return null;

}

public PlayerSalary lowestSalaryInYear(int year)

{

//placeholder return, this should return PlayerSalary Object

return null;

}

public PlayerSalary highestSalaryInTeamInYear(String team, int year)

{

//placeholder return, this should return PlayerSalary Object

return null;

}

public PlayerSalary lowestSalaryInTeamInYear(String team, int year)

{

//placeholder return, this should return PlayerSalary Object

return null;

}

public PlayerSalary highestSalaryInLeagueInYear(String team, int year)

{

//placeholder return, this should return PlayerSalary Object

return null;

}

public PlayerSalary lowestSalaryInLeagueInYear(String team, int year)

{

//placeholder return, this should return PlayerSalary Object

return null;

}

public ArrayList comparePlayersInYear(String player1, String player2, int year)

{

//placeholder return, this should return PlayerSalary ArrayList

return null;

}

public void displayAllSalaries(){

for (int i = 0; i

// Note, this depends on the PlayerSalary class

// having a toString method

System.out.println(salaries.get(i));

}

}

// end of class

*****************************************************************************************************************

This is the main where everything is going to done.

import java.io.*;

import java.util.Scanner;

public class SalaryLookUp

{

public static void main(String[] args) throws FileNotFoundException

{

//PlayerSalaries ps1 = new PlayerSalaries("Salaries.csv");

displayMenu();

}

public static void displayMenu(){

System.out.println("1: See average salary in a specific year");

System.out.println("2: See a specific players salary in a specific year");

System.out.println("3: See the highest salary in a specific year");

System.out.println("4: See the lowest salary in a specific year");

System.out.println("5: See the highest salary on a specific team in a specific year");

System.out.println("6: See the lowest salary on a specific team in a specific year");

System.out.println("8: See the lowest salary in league in a specific year");

System.out.println("9: Compare salaries of two specific players in a specific year");

System.out.println();

System.out.println("10: Quit");

}

}

Programming Assignment Overview: Let's Play Ball! Collaboration policy : same as HW 4 There is a HW5 download folder for you on OAKS. In this assignment, you will write a program to reads in the salary data from baseball players, store the data in a list (ArrayList) of objects, and provides several methods to query the data. The data is provided to you in a comma- delimited text file which is part of a bigger database. We will only use the Salaries.csv file provided. You need to implement the following UML: The Constructor provided reads in the comma-delimited data file. Player Salaries You must add the code to create a list of Player Salary objects, - Salaries: ArrayList and store the data in it. comparePlayers In Year returns a PlayerSalary array of size two in which the highest paid player is in position 0 of the list. +PlayerSalaries(String filename) taverageSalary In Year(int year): int +findPlayerIn Year(String player, int year): Player Salary +highestSalaryIn Year(int year): Player Salary +lowestSalary In Year(int year): Player Salary +highestSalaryInTeamin Year(String team, int year): PlayerSalary +lowestSalaryIn TeamIn Year(String team, int year): PlayerSalary +highestSalaryInLeagueIn Year(String team, int year): Player Salary +lowestSalary InLeagueIn Year(String team, int year): Player Salary The other methods should be intuitive. PlayerSalary -yearID: int - teamID: String - leagueID: String - playerID: String - salary: int Salary LookUp +toString, getter methods for each instance variable +main(String args[]): static void The main method creates the Player Salary database by calling the constructor with the file name and, then, provides a user interface via the console. presents menu of numbered options (reflecting the methods in Player Salaries) to the user (see menu expected next page). Whichever option the user chooses, the program then asks for year, player, and/or team info as needed. prints the returned into using toString in the Player Salary object when needed if good data is returned (see below). If any method is asked for data that is not known (example a year that is incorrect or out of range, or a team or player ID that does not exist) that method should print an error message, return null for the Player Salary, or -1 for an int. The main method should ignore the ERROR result and not print it, and the menu loop should continue until the user chooses to quit the program. If the user chooses a menu number out of range, the program should print an appropriate message and the menu loop should continue. The program terminates when the user chooses the Quit option. You MAY assume that the data entered are of the appropriate type - example, when an int is expected, an int is entered. Please enter your choice: 1: See average salary in a specific year 2: See a specific player's salary in a specific year 3: See the highest salary in a specific year 4: See the lowest salary in a specific year 5: See the highest salary on a specific team in a specific year 6: See the lowest salary on a specific team in a specific year 7: See the highest salary in the league in a specific year 8: See the lowest salary in league in a specific year 9: Compare salaries of two specific players in a specific year 10: Quit. Guidance for completing this assignment. Part I: Do by Tuesday, February 25. Complete the toString method of PlayerSalary class. The constructor is written, you should complete the toString and getter methods, and a main method that verifies that the PlayerSalary class works properly. Do before class on Wednesday, February 26. Part 2: Complete the PlayerSalaries constructor by storing the data for each player into a PlayerSalary instance and storing that instance into the Player Salaries instance variable (salaries) in the Player Salaries class. Do by end of Thursday, February 27 Part 3: Implement all of the Player Salaries methods, assume data sent to methods is valid. Do by Saturday, February 29 Complete the SalaryLookUp class by writing the main method to generate the menu, prompt for input, and print results. Programming Assignment Overview: Let's Play Ball! Collaboration policy : same as HW 4 There is a HW5 download folder for you on OAKS. In this assignment, you will write a program to reads in the salary data from baseball players, store the data in a list (ArrayList) of objects, and provides several methods to query the data. The data is provided to you in a comma- delimited text file which is part of a bigger database. We will only use the Salaries.csv file provided. You need to implement the following UML: The Constructor provided reads in the comma-delimited data file. Player Salaries You must add the code to create a list of Player Salary objects, - Salaries: ArrayList and store the data in it. comparePlayers In Year returns a PlayerSalary array of size two in which the highest paid player is in position 0 of the list. +PlayerSalaries(String filename) taverageSalary In Year(int year): int +findPlayerIn Year(String player, int year): Player Salary +highestSalaryIn Year(int year): Player Salary +lowestSalary In Year(int year): Player Salary +highestSalaryInTeamin Year(String team, int year): PlayerSalary +lowestSalaryIn TeamIn Year(String team, int year): PlayerSalary +highestSalaryInLeagueIn Year(String team, int year): Player Salary +lowestSalary InLeagueIn Year(String team, int year): Player Salary The other methods should be intuitive. PlayerSalary -yearID: int - teamID: String - leagueID: String - playerID: String - salary: int Salary LookUp +toString, getter methods for each instance variable +main(String args[]): static void The main method creates the Player Salary database by calling the constructor with the file name and, then, provides a user interface via the console. presents menu of numbered options (reflecting the methods in Player Salaries) to the user (see menu expected next page). Whichever option the user chooses, the program then asks for year, player, and/or team info as needed. prints the returned into using toString in the Player Salary object when needed if good data is returned (see below). If any method is asked for data that is not known (example a year that is incorrect or out of range, or a team or player ID that does not exist) that method should print an error message, return null for the Player Salary, or -1 for an int. The main method should ignore the ERROR result and not print it, and the menu loop should continue until the user chooses to quit the program. If the user chooses a menu number out of range, the program should print an appropriate message and the menu loop should continue. The program terminates when the user chooses the Quit option. You MAY assume that the data entered are of the appropriate type - example, when an int is expected, an int is entered. Please enter your choice: 1: See average salary in a specific year 2: See a specific player's salary in a specific year 3: See the highest salary in a specific year 4: See the lowest salary in a specific year 5: See the highest salary on a specific team in a specific year 6: See the lowest salary on a specific team in a specific year 7: See the highest salary in the league in a specific year 8: See the lowest salary in league in a specific year 9: Compare salaries of two specific players in a specific year 10: Quit. Guidance for completing this assignment. Part I: Do by Tuesday, February 25. Complete the toString method of PlayerSalary class. The constructor is written, you should complete the toString and getter methods, and a main method that verifies that the PlayerSalary class works properly. Do before class on Wednesday, February 26. Part 2: Complete the PlayerSalaries constructor by storing the data for each player into a PlayerSalary instance and storing that instance into the Player Salaries instance variable (salaries) in the Player Salaries class. Do by end of Thursday, February 27 Part 3: Implement all of the Player Salaries methods, assume data sent to methods is valid. Do by Saturday, February 29 Complete the SalaryLookUp class by writing the main method to generate the menu, prompt for input, and print results

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Mylab Accounting With Pearson -- Access Card -- For Managerial Accounting

Authors: Karen W. Braun, Wendy M. Tietz

5th Edition

0134161645, 9780134161648

More Books

Students also viewed these Accounting questions

Question

What is a verb?

Answered: 1 week ago

Question

=+What would you say if the person were in front of you?

Answered: 1 week ago

Question

=+ How could you make it more engaging and entertaining?

Answered: 1 week ago