Adding amount of salary of 5 arrays of player objects inside 5 arrays of team ob
ID: 3904799 • Letter: A
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 = input.nextDouble(); // user enters player's salary (user is creating each individual player object here into array slots)
Team class:
private double sum; //the total sum of 5 player's salary under a team
Player class:
private double salary; //salary of an individual
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();)
Explanation / Answer
//method to add the sum of each Player's salary from the Player's class into the variable"sum" in the Team class int playerSalarySum(){ int sum = 0; for(int i = 0;iRelated Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.