Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //main.java
- import java.util.ArrayList;
- import java.util.Arrays;
- import java.util.List;
- public class Main {
- public static void main(String[] args) {
- IndividComp indComp1 = new IndividComp("16.02.2022", 10, "andrew", "watches");
- IndividComp indComp2 = new IndividComp("17.02.2022", 15, "valeron", "phone");
- TeamComp teamComp1 = new TeamComp("17.02.2022", 20, "denis", "Ufa");
- TeamComp teamComp2 = new TeamComp("12.01.2022", 33, "Vityaz'", "Surgut");
- indComp1.allData();
- List<TeamComp> listTc = new ArrayList<>(Arrays.asList(teamComp1));
- List<IndividComp> listIc = new ArrayList<>(Arrays.asList(indComp1));
- listTc.add(teamComp2);
- listIc.add(indComp2);
- Championship championships = new Championship(listTc, listIc);
- Championship.everyone(listTc, listIc);
- championships.IndividCompAm();
- championships.TeamCompAm();
- }
- }
- //Compettition.java
- import java.util.List;
- public class Competition {
- private String date;
- private int participants;
- private String winner;
- int toCount(){
- return participants;
- }
- void allData(){
- System.out.println("Соревнование было: " + date + ", Участвовало: " + participants + " человек, Победил: " + winner);
- }
- public Competition(String date, int participants, String winner) {
- this.date = date;
- this.participants = participants;
- this.winner = winner;
- }
- }
- class TeamComp extends Competition {
- private String city;
- public TeamComp(String date, int participants, String winner, String city) {
- super(date, participants, winner);
- this.city = city;
- }
- }
- class IndividComp extends Competition{
- private String gift;
- public IndividComp(String date, int participants, String winner, String gift) {
- super(date, participants, winner);
- this.gift = gift;
- }
- }
- //Championship
- import java.util.List;
- public class Championship {
- private List<TeamComp> listT;
- private List<IndividComp> listC;
- void IndividCompAm(){
- System.out.println("кол-во индивидуальных: " + listC.size());
- }
- void TeamCompAm(){
- System.out.println("кол-во командных: " + listT.size());
- }
- static void everyone(List<TeamComp> ss1, List<IndividComp> ss2){
- int all = 0;
- for (TeamComp s: ss1) {
- all += s.toCount();
- }
- for (IndividComp s: ss2) {
- all += s.toCount();
- }
- System.out.println("Всего человек участвовало: " + all);
- System.out.println("Количество командных соревнований: " + ss1.size());
- System.out.println("Количество индивидуальных соревнований: " + ss2.size());
- }
- public Championship(List<TeamComp> listT, List<IndividComp> listC) {
- this.listT = listT;
- this.listC = listC;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement