Advertisement
Teammasik

prac_1_oop

Oct 5th, 2023
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.07 KB | Cryptocurrency | 0 0
  1. //main.java
  2. import java.util.ArrayList;
  3. import java.util.Arrays;
  4. import java.util.List;
  5.  
  6. public class Main {
  7.     public static void main(String[] args) {
  8.         IndividComp indComp1 = new IndividComp("16.02.2022", 10, "andrew", "watches");
  9.         IndividComp indComp2 = new IndividComp("17.02.2022", 15, "valeron", "phone");
  10.         TeamComp teamComp1 = new TeamComp("17.02.2022", 20, "denis", "Ufa");
  11.         TeamComp teamComp2 = new TeamComp("12.01.2022", 33, "Vityaz'", "Surgut");
  12.  
  13.         indComp1.allData();
  14.  
  15.  
  16.         List<TeamComp> listTc = new ArrayList<>(Arrays.asList(teamComp1));
  17.         List<IndividComp> listIc = new ArrayList<>(Arrays.asList(indComp1));
  18.  
  19.         listTc.add(teamComp2);
  20.         listIc.add(indComp2);
  21.  
  22.         Championship championships = new Championship(listTc, listIc);
  23.         Championship.everyone(listTc, listIc);
  24.  
  25.         championships.IndividCompAm();
  26.         championships.TeamCompAm();
  27.     }
  28. }
  29.  
  30. //Compettition.java
  31. import java.util.List;
  32.  
  33. public class Competition {
  34.     private String date;
  35.     private int participants;
  36.     private String winner;
  37.  
  38.     int toCount(){
  39.         return participants;
  40.     }
  41.  
  42.     void allData(){
  43.         System.out.println("Соревнование было: " + date + ", Участвовало: " + participants + " человек, Победил: " + winner);
  44.     }
  45.     public Competition(String date, int participants, String winner) {
  46.         this.date = date;
  47.         this.participants = participants;
  48.         this.winner = winner;
  49.     }
  50. }
  51.  
  52. class TeamComp extends  Competition {
  53.     private String city;
  54.  
  55.  
  56.     public TeamComp(String date, int participants, String winner, String city) {
  57.         super(date, participants, winner);
  58.         this.city = city;
  59.     }
  60. }
  61.  
  62. class IndividComp extends  Competition{
  63.     private String gift;
  64.     public IndividComp(String date, int participants, String winner, String gift) {
  65.         super(date, participants, winner);
  66.         this.gift = gift;
  67.     }
  68.  
  69. }
  70.  
  71. //Championship
  72. import java.util.List;
  73.  
  74. public class Championship {
  75.     private List<TeamComp> listT;
  76.     private List<IndividComp> listC;
  77.  
  78.     void IndividCompAm(){
  79.         System.out.println("кол-во индивидуальных: " + listC.size());
  80.     }
  81.     void TeamCompAm(){
  82.         System.out.println("кол-во командных: " + listT.size());
  83.     }
  84.     static void everyone(List<TeamComp> ss1, List<IndividComp> ss2){
  85.         int all = 0;
  86.         for (TeamComp s: ss1) {
  87.             all += s.toCount();
  88.         }
  89.         for (IndividComp s: ss2) {
  90.             all += s.toCount();
  91.         }
  92.         System.out.println("Всего человек участвовало: " + all);
  93.         System.out.println("Количество командных соревнований: " + ss1.size());
  94.         System.out.println("Количество индивидуальных соревнований: " + ss2.size());
  95.     }
  96.     public Championship(List<TeamComp> listT, List<IndividComp> listC) {
  97.         this.listT = listT;
  98.         this.listC = listC;
  99.     }
  100. }
  101.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement