SHARE
TWEET

Untitled

a guest Nov 21st, 2019 136 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public class Students {
  2.     private String name;
  3.     private String surname;
  4.     private int years;
  5.  
  6.     public Students(String name, String surname, int years) {
  7.         this.name = name;
  8.         this.surname = surname;
  9.         this.years = years;
  10.     }
  11.  
  12.     public String getName() {
  13.         return name;
  14.     }
  15.  
  16.     public String getSurname() {
  17.         return surname;
  18.     }
  19.  
  20.     public int getYears() {
  21.         return years;
  22.     }
  23.  
  24.     @Override
  25.     public boolean equals(Object o) {
  26.         if (this == o) return true;
  27.         if (o == null || getClass() != o.getClass()) return false;
  28.         Students students = (Students) o;
  29.         return years == students.years &&
  30.                 Objects.equals(name, students.name) &&
  31.                 Objects.equals(surname, students.surname);
  32.     }
  33.  
  34.     @Override
  35.     public int hashCode() {
  36.         return Objects.hash(name, surname, years);
  37.     }
  38.  
  39.     @Override
  40.     public String toString() {
  41.         return "Students{" +
  42.                 "name='" + name + '\'' +
  43.                 ", surname='" + surname + '\'' +
  44.                 ", years=" + years +
  45.                 '}';
  46.     }
  47. }
  48.  
  49. class Numbers {
  50.  
  51.  
  52.     public Numbers() {
  53.  
  54.     }
  55.  
  56.  
  57.     public double sredniaOcen() {
  58.         int sum = 0;
  59.         for (int i = 0; i < arrayList.size(); i++) {
  60.             sum += arrayList.get(i);
  61.         }
  62.         double avg = sum / arrayList.size();
  63.         return avg;
  64.     }
  65.  
  66.     ArrayList<Integer> arrayList = new ArrayList<Integer>();
  67.  
  68.     public boolean addToArrayList(int number) {
  69.  
  70.         return arrayList.add(number);
  71.  
  72.     }
  73.  
  74. }
  75.  
  76. class App10 {
  77.     public static void main(String[] args) {
  78.         Students students1 = new Students("aaa", "kowalski", 1992);
  79.         Students students2 = new Students("Kasia", "alski", 1992);
  80.         Students students3 = new Students("Basia", "ski", 1992);
  81.         Students students4 = new Students("aaaTOmasz", "kow", 1992);
  82.  
  83.  
  84.         Numbers numbers1 = new Numbers();
  85.         numbers1.addToArrayList(1);
  86.         numbers1.addToArrayList(2);
  87.         numbers1.addToArrayList(5);
  88.         numbers1.addToArrayList(6);
  89.  
  90.         Numbers numbers2 = new Numbers();
  91.         numbers2.addToArrayList(5);
  92.         numbers2.addToArrayList(5);
  93.         numbers2.addToArrayList(5);
  94.         numbers2.addToArrayList(5);
  95.  
  96.  
  97.         Numbers numbers3 = new Numbers();
  98.         numbers3.addToArrayList(3);
  99.         numbers3.addToArrayList(4);
  100.         numbers3.addToArrayList(6);
  101.         numbers3.addToArrayList(1);
  102.  
  103.         Numbers numbers4 = new Numbers();
  104.         numbers4.addToArrayList(6);
  105.         numbers4.addToArrayList(6);
  106.         numbers4.addToArrayList(1);
  107.         numbers4.addToArrayList(6);
  108.         numbers4.addToArrayList(2);
  109.         numbers4.addToArrayList(6);
  110.         numbers4.addToArrayList(1);
  111.  
  112.  
  113.         List<Integer> oceny = new LinkedList<Integer>();
  114.  
  115.         Map<Students, Numbers> studentsNumbersMap = new HashMap<Students, Numbers>();
  116.  
  117.         studentsNumbersMap.put(students1, numbers1);
  118.         studentsNumbersMap.put(students2, numbers2);
  119.         studentsNumbersMap.put(students3, numbers3);
  120.         studentsNumbersMap.put(students4, numbers4);
  121.  
  122.         for (Map.Entry<Students, Numbers> entry : studentsNumbersMap.entrySet()) {
  123.             System.out.println("Uczen nazwya sie : " + entry.getKey().toString() +
  124.                     " a jego średnia to : " + entry.getValue().sredniaOcen());
  125.  
  126.         }
  127.  
  128.     }
  129. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top