Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Create a main program class called AllStarRoster AllStarRoster should have the f

ID: 3884830 • Letter: C

Question

Create a main program class called AllStarRoster

                                AllStarRoster should have the following specs:

                                                A main method that creates and array of HockeyPlayer objects of size 6

                                                Populate the 6 indexes with hockey player objects

                                                Create a for each loop that will print all the player info you entered.

ProPlayer.java

public abstract class ProPlayer

{

protected String name;

private float baseSalary=0;

public ProPlayer(String name) {

this.name = name;

}

public float getBaseSalary() {

return baseSalary;

}

  

public void printName(){

System.out.println(name);

}

  

abstract float computePay();

}

HockeyPlayer.java

public class HockeyPlayer extends ProPlayer {

String teamName;
float bonusPay;

public HockeyPlayer(String teamName, float bonusPay, String name) {
super(name);
this.teamName = teamName;
this.bonusPay = bonusPay;
}
  
public float calculatedPay(){
return this.bonusPay + super.getBaseSalary();
}


public void printName(){
System.out.println("Player : "+super.name );
System.out.println("Team Name : "+teamName);
System.out.println("Salary : "+this.computePay());
}
  
  

float computePay() {
return this.bonusPay + super.getBaseSalary();
}
  
}

Explanation / Answer

Explanation::

Code in JAVA::

class AllStarRoster{

public static void main(String[] args){

/*

* Creating Array of objects of class HockeyPlayer class.

* Size of the array is 6.

* Name of the object array is hp.

*/

HockeyPlayer[] hp = new HockeyPlayer[6];

/*

* Following we populate each object of the array manually.

* Array index starts at 0 so first object has index 0.

* See how objects are created by passing three parameters

* as in constructor of HockeyPlayer class.

* Note :: To pass float value we must append f at the end of

* the value because by default value id double.

* So suppose bonusPay=232.45 then to pass it as float we

* append f and write value as 232.45f

*/

hp[0]=new HockeyPlayer("Team A",232.45f,"Tyrion");

hp[1]=new HockeyPlayer("Team B",123.33f,"Theon Greyjoy");

hp[2]=new HockeyPlayer("Team C",455.45f,"Jon Snow");

hp[3]=new HockeyPlayer("Team D",500.23f,"Jaime Lannister");

hp[4]=new HockeyPlayer("Team E",300.23f,"Eddard Stark");

hp[5]=new HockeyPlayer("Team F",600.56f,"Robb Stark");

/*

* Now to print the objects that are created with values,

* an for loop is used that runs from 0 to 5(both inclusive).

* In each iteraion we call the method of HockeyPlayer class

* named printName() using object hp[i] where i is 0<=i<6

*

*/

for(int i=0;i<6;i++){

System.out.println(" Player :: "+(i+1));

hp[i].printName();

}

}//main ends

}//class ends

Output::


C:CheggJava>javac AllStarRoster.java

C:CheggJava>java AllStarRoster


Player :: 1
Player : Tyrion
Team Name : Team A
Salary : 232.45


Player :: 2
Player : Theon Greyjoy
Team Name : Team B
Salary : 123.33


Player :: 3
Player : Jon Snow
Team Name : Team C
Salary : 455.45


Player :: 4
Player : Jaime Lannister
Team Name : Team D
Salary : 500.23


Player :: 5
Player : Eddard Stark
Team Name : Team E
Salary : 300.23


Player :: 6
Player : Robb Stark
Team Name : Team F
Salary : 600.56

C:CheggJava>

=============================== Java code where program prompts user to enter data================

Code in Java::

import java.util.Scanner;

class AllStarRoster{

public static void main(String[] args){

Scanner sc=new Scanner(System.in);

/*

* Creating Array of objects of class HockeyPlayer class.

* Size of the array is 6.

* Name of the object array is hp.

*/

HockeyPlayer[] hp = new HockeyPlayer[6];

/*

* In following for loop we prompt user to enter

* team name, bonus pay and player name individually.

*/

for(int i=0;i<6;i++){

System.out.print(" Please enter team name::");

String teamName=sc.nextLine();

System.out.print("Please enter bonus pay::");

float bonusPay=sc.nextFloat();

/* sc.nextLine() is used to avoid problem of buffer*/

sc.nextLine();

System.out.print("Please enter player name::");

String playerName=sc.nextLine();

/*

* Passing all the values scanned into HockeyPlayer

* constructor.

*/

hp[i]=new HockeyPlayer(teamName,bonusPay,playerName);

}

/*

* Now to print the objects that are created with values,

* an for loop is used that runs from 0 to 5(both inclusive).

* In each iteraion we call the method of HockeyPlayer class

* named printName() using object hp[i] where i is 0<=i<6

*

*/

for(int i=0;i<6;i++){

System.out.println(" Player :: "+(i+1));

hp[i].printName();

}

}//main ends

}//class ends

Output::


C:CheggJava>javac AllStarRoster.java

C:CheggJava>java AllStarRoster

Please enter team name::Montreal Canadiens
Please enter bonus pay::123.45
Please enter player name::The Rock

Please enter team name::Toronto Maple Leafs
Please enter bonus pay::200.34
Please enter player name::John Cena

Please enter team name::Boston Bruins
Please enter bonus pay::160.34
Please enter player name::Sheamus

Please enter team name::New York Rangers
Please enter bonus pay::180.2
Please enter player name::The Undertaker

Please enter team name::Buffalo Sabres
Please enter bonus pay::130.34
Please enter player name::Kane

Please enter team name::Montreal Maroons
Please enter bonus pay::145.56
Please enter player name::The Great Khali


Player :: 1
Player : The Rock
Team Name : Montreal Canadiens
Salary : 123.45


Player :: 2
Player : John Cena
Team Name : Toronto Maple Leafs
Salary : 200.34


Player :: 3
Player : Sheamus
Team Name : Boston Bruins
Salary : 160.34


Player :: 4
Player : The Undertaker
Team Name : New York Rangers
Salary : 180.2


Player :: 5
Player : Kane
Team Name : Buffalo Sabres
Salary : 130.34


Player :: 6
Player : The Great Khali
Team Name : Montreal Maroons
Salary : 145.56

C:CheggJava>

Thank you!!

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote