PP 7.3 Write a class called SalesTeam that represents a team of salespeople. Each salesperson on the team is represented by the SalesPerson class of PP 7.2. Each team has a name, and the constructor needs only to accept the name of the team. Use an ArrayList to store the team members. Provide a method called addSalesPerson that accepts a SalesPerson object. Provide a method called weeklyReport that prints the name and the total sale amount of each team member and the total amount for the entire team. Write a driver class that fully exercises the SalesTeam class.
import java.util.ArrayList;
class SalesTeam {
private String teamName;
private ArrayList<SalesPerson> teamMembers;
public SalesTeam(String teamName) {
this.teamName = teamName;
this.teamMembers = new ArrayList<>();
}
public void addSalesPerson(SalesPerson salesPerson) {
teamMembers.add(salesPerson);
}
public void weeklyReport() {
double totalTeamSales = 0.0;
System.out.println("Weekly Report for Team: " + teamName);
System.out.println("=============================================");
for (SalesPerson salesPerson : teamMembers) {
double personTotalSales = salesPerson.total();
totalTeamSales += personTotalSales;
System.out.println("Salesperson: " + salesPerson.getName());
System.out.println("Total Sales: $" + personTotalSales);
System.out.println("---------------------------------------------");
}
System.out.println("Total Team Sales: $" + totalTeamSales);
}
}
public class PP7_3 {
public static void main(String[] args) {
SalesPerson john = new SalesPerson("John", "123-456-7890", "District A");
john.setDailyAmount(0, 100.0);
john.setDailyAmount(1, 200.0);
john.setDailyAmount(2, 150.0);
john.setDailyAmount(3, 300.0);
john.setDailyAmount(4, 250.0);
john.setDailyAmount(5, 180.0);
john.setDailyAmount(6, 210.0);
SalesPerson jane = new SalesPerson("Jane", "234-567-8901", "District B");
jane.setDailyAmount(0, 150.0);
jane.setDailyAmount(1, 250.0);
jane.setDailyAmount(2, 180.0);
jane.setDailyAmount(3, 280.0);
jane.setDailyAmount(4, 220.0);
jane.setDailyAmount(5, 200.0);
jane.setDailyAmount(6, 190.0);
SalesTeam team1 = new SalesTeam("Team 1");
team1.addSalesPerson(john);
team1.addSalesPerson(jane);
team1.weeklyReport();
}
}
< Console >
Weekly Report for Team: Team 1
=============================================
Salesperson: John
Total Sales: $1390.0
---------------------------------------------
Salesperson: Jane
Total Sales: $1470.0
---------------------------------------------
Total Team Sales: $2860.0
'[JAVA] 개발' 카테고리의 다른 글
[우아한테크코스] 1주차 문자열 덧셈 계산기 (0) | 2024.10.17 |
---|---|
[JAVA] JDK 21 설치, 환경 변수 설정 (1) | 2024.10.17 |
Java Software Solution Ch7_PP2 (0) | 2024.05.01 |
Java Software Soution Ch7_PP8 (0) | 2024.05.01 |
Java Software Solution Ch11_PP3 ; Exception Class (0) | 2024.04.28 |