Advertisement
Guest User

Untitled

a guest
Sep 18th, 2019
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.56 KB | None | 0 0
  1. package com.company;
  2.  
  3. public class Main {
  4.  
  5. public static void main(String[] args) {
  6. Student firstStudent = new Student();
  7. Student secondStudent = new Student();
  8. Student thirdStudent = new Student();
  9. Student fourthStudent = new Student();
  10.  
  11. University utm = new University();
  12. University usm = new University();
  13.  
  14. firstStudent.age = 20;
  15. secondStudent.age = 20;
  16. thirdStudent.age = 20;
  17. fourthStudent.age = 20;
  18.  
  19. firstStudent.mark = 10;
  20. secondStudent.mark = 9.5f;
  21. thirdStudent.mark = 8.7f;
  22. fourthStudent.mark = 3.2f;
  23.  
  24. Student[] utmStudents = {firstStudent, secondStudent};
  25. Student[] usmStudents = {thirdStudent, fourthStudent};
  26.  
  27. utm.students = utmStudents;
  28. utm.name = "Technical University of Moldova";
  29. utm.foundationYear = 1337;
  30.  
  31. usm.students = usmStudents;
  32. usm.name = "State University of Moldova";
  33. usm.foundationYear = 1488;
  34.  
  35. float commonAverage = (usm.findAverage() + utm.findAverage()) / 2;
  36.  
  37. System.out.println(commonAverage);
  38. }
  39.  
  40. }
  41.  
  42. class University {
  43. String name;
  44. int foundationYear;
  45. Student[] students;
  46.  
  47.  
  48. float findAverage() {
  49. float average = 0;
  50. float sum = 0;
  51.  
  52. for (int i = 0; i < students.length; i++) {
  53. sum += students[i].mark;
  54. }
  55.  
  56. average = sum / students.length;
  57.  
  58. return average;
  59. }
  60. }
  61.  
  62. class Student {
  63. String name;
  64. int age;
  65. float mark;
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement