Question

This java assignment will give you practice with classes, methods, and arrays. Part 1: Player Class...


This java assignment will give you practice with classes, methods, and arrays.

Part 1: Player Class
Write a class named Player that stores a player’s name and the player’s high score.
A player is described by:
 player’s name
 player’s high score
In your class, include:
 instance data variables
 two constructors
 getters and setters
 include appropriate value checks when applicable
 a toString method
Part 2: PlayersList Class
Write a class that manages a list of up to 10 players and their high scores. Create a single array of type
Player that stores the players’ names and scores.
In your class, include:
 a single array of type Player to hold player name and score.
 a constructor
Your class should support the following features:
 Add a new player and score (up to 10 players).
method header: public void addPlayer()
 Print all the players’ names and their scores to the screen.
method header: public void printPlayers()
 Allow the user to enter a player’s name and output that player’s score or a message if that
player’s name has not been entered.
method header: public void lookupPlayer()
Notes
 You can include additional instance data variables if it is helpful. If you include additional
variables, include additional getters and setters as appropriate.
 I have provided a driver program ScoreManagementSystem.java you can use to test your code and sample output, of which yours should be the exact same.

//SAMPLE RUN   

Score Management System
Choose:
A)dd new player
P)rint all players
L)ookup a player's score
Q)uit
A
Enter name:
Alexander
Enter score:
300
Score Management System
Choose:
A)dd new player
P)rint all players
L)ookup a player's score
Q)uit
A
Enter name:
Michael
Enter score:
200
Score Management System
Choose:
A)dd new player
P)rint all players
L)ookup a player's score
Q)uit
P
Score Name
300 Alexander
200 Michael
Score Management System
Choose:
A)dd new player
P)rint all players
L)ookup a player's score
Q)uit
L
Enter name to look up.
George
Name not found.

Score Management System
Choose:
A)dd new player
P)rint all players
L)ookup a player's score
Q)uit
P
Score Name
300 Alexander
200 Michael
Score Management System
Choose:
A)dd new player
P)rint all players
L)ookup a player's score
Q)uit
L
Enter name to look up.
Michael
Michael's score = 200
Score Management System
Choose:
A)dd new player
P)rint all players
L)ookup a player's score
Q)uit
Q

Submission Instructions
 Execute the program and copy/paste the output that is produced by your program into the bottom
of the source code file, making it into a comment. I will run the programs myself to see the
output.
 Make sure the run "matches" your source. If the run you submit could not have come from the
source you submit, it will be graded as if you did not hand in a run.
 Use the Assignment Submission link to submit the source code file.
 Submit the following files:
Player.java
PlayersList.java
ScoreManagementSystem.java


//Here is the prototype for ScoreManagementSystem.java
import java.util.Scanner;

public class ScoreManagementSystem{
public static void main(String[] args)
   {
       Scanner input;
PlayerManager highScores = new PlayerManager();
input = new Scanner(System.in);
       String choice = "";

       // Main menu
       do
       {
           System.out.println();
           System.out.println();
           System.out.println("Score Management System");
           System.out.println("Choose:");
           System.out.println();
           System.out.println("A)dd new player");
           System.out.println("P)rint all players");
           System.out.println("L)ookup a player's score");
           System.out.println("Q)uit");
           System.out.println();
           choice = input.next();
       input.nextLine(); // Discard newline
          
if (choice.equalsIgnoreCase("A"))
               highScores.addPlayer();
           else if (choice.equalsIgnoreCase("P"))
               highScores.printPlayers();
           else if (choice.equalsIgnoreCase("L"))
               highScores.lookupPlayer();
           System.out.println();

       } while (!choice.equalsIgnoreCase("q"));
   }
}

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

//packages
import java.util.*;
//PlayerList class
public class ScoreManagementSystem{
   public static void main(String[] args)
    {
           Scanner input;
           PlayerManager highScores = new PlayerManager();
           input = new Scanner(System.in);
           String choice = "";

        // Main menu
           do
           {
               System.out.println();
               System.out.println();
               System.out.println("Score Management System");
               System.out.println("Choose:");
               System.out.println();
               System.out.println("A)dd new player");
               System.out.println("P)rint all players");
               System.out.println("L)ookup a player's score");
               System.out.println("Q)uit");
               System.out.println();
               choice = input.next();
               input.nextLine(); // Discard newline
              
           if (choice.equalsIgnoreCase("A"))
                   highScores.addPlayer();
               else if (choice.equalsIgnoreCase("P"))
                   highScores.printPlayers();
               else if (choice.equalsIgnoreCase("L"))
                   highScores.lookupPlayer();
               System.out.println();
          
           } while (!choice.equalsIgnoreCase("q"));
   }
  
}
class PlayerManager{
   //instatnce varaibles
   Player players[]; //array holds players
   int index; //index keep tracking palyers
   String name;
   int score;
   Scanner sc;
   //construcer
   public PlayerManager(){
       players=new Player[10];
       index=0;
       sc=new Scanner(System.in);
   }
   //addplayer method
   public void addPlayer(){
       System.out.println("Enter name:");
       name=sc.next();
       System.out.println("Enter score:");
       score=sc.nextInt();
       players[index++]=new Player(name,score);
   }
   //printplayer method
   public void printPlayers(){
       System.out.println("Score \t Name");
       for(int i=0;i<index;i++){
           System.out.println(players[i].getName()+" \t "+players[i].getHighScore());
       }
       System.out.println();
   }
   //lookup method
   public void lookupPlayer(){
       System.out.println(" Enter name to look up.");
       name=sc.next();
       boolean found=false;
       for(int i=0;i<index;i++){
           //player found
           if(players[i].getName().equals(name)){
               found=true;
               System.out.println(players[i].getName()+"\'s Score ="+players[i].getHighScore());
           }
       }
       //palyer not found
       if(!found){
           System.out.println("Name not Found");
       }
   }
   //rules
   public static void main(String args[]){
   }
}
class Player{
   //instance variables
   private String name;
   private int highScore;
   //default constructer
   public Player(){
       name=null;
       highScore=0;
   }
   //constructer takes name and score values
   public Player(String name,int highScore){
       this.name=name;
       this.highScore=highScore;
   }
   //set Methods
   public void setName(String name){
       this.name=name;
   }
   public void setHighScore(int score){
       this.highScore=score;
   }
   //get methods
   public String getName(){
       return name;
   }
   public int getHighScore(){
       return this.highScore;
   }
}

Score Hanagement System hoose Add new player Print all players Lookup a players score Entername Enter score: 200 Score Manag
Score Management System Choose: Add new player Print all players Lookup a players score Quit Enter name to look up hai Name
Add a comment
Know the answer?
Add Answer to:
This java assignment will give you practice with classes, methods, and arrays. Part 1: Player Class...
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
  • You will write a two-class Java program that implements the Game of 21. This is a...

    You will write a two-class Java program that implements the Game of 21. This is a fairly simple game where a player plays against a “dealer”. The player will receive two and optionally three numbers. Each number is randomly generated in the range 1 to 11 inclusive (in notation: [1,11]). The player’s score is the sum of these numbers. The dealer will receive two random numbers, also in [1,11]. The player wins if its score is greater than the dealer’s...

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

  • Answer in eclispe please!!! Do the following: 1. Create a package named, “prob3” and a class...

    Answer in eclispe please!!! Do the following: 1. Create a package named, “prob3” and a class named, “Games2”. 2. Create a Player class and add this code: public class Player { private String name; private int points; public Player(String name, int points) { this.name = name; this.points = points; } public String getName() { return name; } public int getPoints() { return points; } @Override public String toString() { return "name=" + name + ", points=" + points; } }...

  • in java coorect this code & screenshoot your output ---------------------------------------------------------------------- public class UNOGame {     /**...

    in java coorect this code & screenshoot your output ---------------------------------------------------------------------- public class UNOGame {     /**      * @param args the command line arguments      */         public static void main(String[] args) {       Scanner input=new Scanner(System.in);          Scanner input2=new Scanner(System.in);                             UNOCard c=new UNOCard ();                UNOCard D=new UNOCard ();                 Queue Q=new Queue();                           listplayer ll=new listplayer();                           System.out.println("Enter Players Name :\n Click STOP To Start Game..");        String Name = input.nextLine();...

  • java This lab is intended to give you practice creating a class with a constructor method,...

    java This lab is intended to give you practice creating a class with a constructor method, accessor methods, mutator methods, equals method , toString method and a equals method. In this lab you need to create two separate classes, one Student class and other Lab10 class. You need to define your instance variables, accessor methods, mutator methods, constructor, toString method and equals method in Student class. You need to create objects in Lab10 class which will have your main method...

  • This is my code for my game called Reversi, I need to you to make the...

    This is my code for my game called Reversi, I need to you to make the Tester program that will run and complete the game. Below is my code, please add comments and Javadoc. Thank you. public class Cell { // Displays 'B' for the black disk player. public static final char BLACK = 'B'; // Displays 'W' for the white disk player. public static final char WHITE = 'W'; // Displays '*' for the possible moves available. public static...

  • Problem Statement: A company intends to offer various versions of roulette game and it wants you...

    Problem Statement: A company intends to offer various versions of roulette game and it wants you to develop a customized object-oriented software solution. This company plans to offer one version 100A now (similar to the simple version in project 2 so refer to it for basic requirements, but it allows multiple players and multiple games) and it is planning to add several more versions in the future. Each game has a minimum and maximum bet and it shall be able...

  • Assignment Overview In Part 1 of this assignment, you will write a main program and several...

    Assignment Overview In Part 1 of this assignment, you will write a main program and several classes to create and print a small database of baseball player data. The assignment has been split into two parts to encourage you to code your program in an incremental fashion, a technique that will be increasingly important as the semester goes on. Purpose This assignment reviews object-oriented programming concepts such as classes, methods, constructors, accessor methods, and access modifiers. It makes use of...

  • PRG/421 Week One Analyze Assignment – Analyzing a Java™Program Containing Abstract and Derived Classes 1.    What is...

    PRG/421 Week One Analyze Assignment – Analyzing a Java™Program Containing Abstract and Derived Classes 1.    What is the output of the program as it is written? (Program begins on p. 2) 2. Why would a programmer choose to define a method in an abstract class (such as the Animal constructor method or the getName()method in the code example) vs. defining a method as abstract (such as the makeSound()method in the example)? /********************************************************************** *           Program:          PRG/421 Week 1 Analyze Assignment *           Purpose:         Analyze the coding for...

  • You will be writing some methods that will give you some practice working with Lists. Create...

    You will be writing some methods that will give you some practice working with Lists. Create a new project and create a class named List Practice in the project. Then paste in the following code: A program that prompts the user for the file names of two different lists, reads Strings from two files into Lists, and prints the contents of those lists to the console. * @author YOUR NAME HERE • @version DATE HERE import java.util.ArrayList; import java.util.List; import...

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