Question
Adding amount of salary of 5 arrays of player objects inside 5 arrays of team objects ? Main: System.out.print(Enter player's salary: ); double salary =
Adding amount of salary of 5 arrays of player objects inside 5 arrays of team objects?
Main:
System.out.print("Enter player's salary: ");
double salary = input.nextDouble(); // user enters player's salary (user is creating each individual player object here into array slots)
Team[] teams = new Team[5];
Team class:
private double sum; //the total sum of 5 player's salary under a team
Player[] players = new Player[5];
Player class:
private double salary; //salary of an individual
Player(String fN, String lN, int h, int w, int a, double sal){ first_name = fN; last_name = lN; height = h; weight = w; age = a; salary = sal; } //constructor
Player public void setSalary(double sal) {
salary = sal;
}
and
public double getSalary() {
return salary;
}
How would I create the method to add the sum of each Player's salary from the Player's class into the variable "sum" in the Team class? (like using a for loop in a mutator or something?)
A note that the Player array is created in the Team file and Team array is created in the main file. (somewhere in the lines of teams[i].players[i].getSalary or sum += players[i].getSalary();)
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started