How can this be written in Java ? For this assignment, we are going to explore h
ID: 3588248 • Letter: H
Question
How can this be written in Java?
For this assignment, we are going to explore how we can use objects to build more expressive and cleaner programs. In honor of football season we are going to be creating Players for our IUPUI football team (Undefeated since 1969). We will need to create and store these Players in memory and allow the user to view an entire "roster" of Players. We will make the following assumptions · . . . No two Players will have the same name (e.g., #1 Test Testerson, #2 Test Testerson) No two Players can have the same number (eg., #1 Jane Testerson, #2 Jane Testerson) Each Player MUST have at-least a first name, last name, and jersey number In the basic submission there will only be, at maximum, eleven (11) Players on our team. Your goal is to create a program that will allow for creation and viewing of Players from our "team." You are required to implement the following items as part of this assignment Your C++ program must contain three files (2 cpp and 1 h file). These files should be named as such: Driver.cpp, Player.cpp, Player.h Your Java program must contain the following two files: Driver.java and Player.java Your Driver class must store any and all created Players in an Array on the Heap . This Array must make use of dynamic memory allocation. . In the C++ version we will need to manage our memory accordingly - no memory leaks! o You can use Valgrind to check our program for memory leaks - any leaks in memory will result in a deduction of points. When you start the program, you should provide the user with a menu choice to do one of the following: . 1. Add New Player 2. View Players 3. Exit Program Upon completion of Options #1 or #2 the menu should once again be displayed to the user-thus allowing them to make another selection. This process should continue to loop until the user selections Option #3. Once/If eleven (11) Players have been entered the program should print the roster and terminate ·Explanation / Answer
import java.util.*;
public class Player
{
private String firstName ,lastName;
private int jerseyNumber;
public Player(String firstName,String lastName,int jerseyNumber) //argument constructor
{
this.firstName = firstName;
this.lastName = lastName;
this.jerseyNumber = jerseyNumber;
}
public String toString() //override toString() method
{
return " "+jerseyNumber +") "+ firstName +" "+lastName;
}
}
public class Driver
{
public static void main (String[] args)
{
Player[] players = new Player[11]; //array of 11 objects of Player class
Scanner sc = new Scanner(System.in);
int selection,jerseyNumber,i;
i = 0;
String firstName,lastName;
System.out.println("Welcome to our CSCI 240 Roster Editor!");
do
{
System.out.println(" 1)Add new Player");
System.out.println(" 2)View Player(s)");
System.out.println(" 3)Exit Program");
System.out.println(" Please enter your selection : ");
selection = sc.nextInt();
switch(selection)
{
case 1: System.out.println(" Please enter a first name : ");
firstName = sc.next();
System.out.println(" Please enter a last name : ");
lastName = sc.next();
System.out.println(" Please enter a number (1-99) : ");
jerseyNumber = sc.nextInt();
players[i] = new Player(firstName,lastName,jerseyNumber); //create new Player
i++;
System.out.println(" **Player created**");
break;
case 2: System.out.println("** IUPUI Football Roster **");
System.out.println(players[i-1]);//display Player details using toString() method
System.out.println(" ********************************");
break;
case 3: System.out.println(" Thank you for using our program. GoodBye!!!");
break;
default : System.out.println(" Invalid Choice. Please select option #1,#2 or #3");
break;
}
if(selection == 3)
break;
}while(selection != 3);
}
}
Output:
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.