Advertisement
VelizarAng

KRasi tema4

Oct 17th, 2021
742
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.20 KB | None | 0 0
  1. //CLASS STARTER
  2. package Tema4;
  3.  
  4. public class Starter {
  5.     public static void main(String[] args) {
  6.         Utilities.Input();
  7.  
  8.         Utilities.Processing_1();
  9.  
  10.         Utilities.Output();
  11.     }
  12. }
  13.  
  14. //CLASS UTILITIES
  15. package Tema4;
  16. import java.util.Scanner;
  17.  
  18. public class Utilities{
  19.     private static Students student1;
  20.     private static Students student2;
  21.     private static Students student3;
  22.     private static Students student4;
  23.     private static Students student5;
  24.  
  25.     public static void Input(){
  26.         Scanner scan = new Scanner(System.in);
  27.         double mat;
  28.         double physics;
  29.         double programing;
  30.  
  31.         //Entering marks
  32.         System.out.println("Моля въведете оценка по математика: ");
  33.         mat = scan.nextDouble();
  34.         System.out.println("Моля въведете оценка по физика: ");
  35.         physics = scan.nextDouble();
  36.         System.out.println("Моля въведете оценка по програмиране: ");
  37.         programing = scan.nextDouble();
  38.  
  39.         student1.Marks.enterMarks(mat, physics, programing);
  40.         student2.Marks.enterMarks(mat, physics, programing);
  41.         student3.Marks.enterMarks(mat, physics, programing);
  42.         student4.Marks.enterMarks(mat, physics, programing);
  43.         student5.Marks.enterMarks(mat, physics, programing);
  44.     }
  45.  
  46.     public static void Processing_1(){
  47.         //Creating 5 students
  48.         Students student1 = new Students("Velizar", "Angelov", 18406);
  49.         Students student2 = new Students("Boqn", "Gyurov", 18404);
  50.         Students student3 = new Students("Georgi",  "Georgiev", 18409);
  51.         Students student4 = new Students("Tsvetelin", "Goranov", 18426);
  52.         Students student5 = new Students("Viktor", "Valentinov", 18307);
  53.  
  54.         student1.printInfo();
  55.         student2.printInfo();
  56.         student3.printInfo();
  57.         student4.printInfo();
  58.         student5.printInfo();
  59.     }
  60.  
  61.     public static void Output(){
  62.         //Printing info
  63.         student1.printInfo();
  64.         student2.printInfo();
  65.         student3.printInfo();
  66.         student4.printInfo();
  67.         student5.printInfo();
  68.     }
  69.  
  70. }
  71.  
  72. //CLASS STUDENTS
  73. package Tema4;
  74.  
  75. public class Students {
  76.     //Fields
  77.     public String name;
  78.     public String family;
  79.     public int number;
  80.     public Tema4.Marks Marks;
  81.  
  82.     //Constructor with parameters
  83.     public Students(String name, String family, int number){
  84.         this.name = name;
  85.         this.family = family;
  86.         this.number = number;
  87.     }
  88.  
  89.     public Students(){
  90.         this.name = " ";
  91.         this.family = " ";
  92.         this.number = 0;
  93.     }
  94.  
  95.     //Method to print
  96.     public void printInfo(){
  97.         System.out.println("Име: " + this.name);
  98.         System.out.println("Фамилия: " + this.family);
  99.         System.out.println("Курсов номер: " + this.number);
  100.         System.out.println("Оценка по математика: " + this.Marks.mathemathicsMark);
  101.         System.out.println("Оценка по физика: " + this.Marks.physicsMark);
  102.         System.out.println("Оценка по програмиране: " + this.Marks.programingMark);
  103.         System.out.println("Среден успех: " + Marks.averageGrade(this.Marks.mathemathicsMark, this.Marks.physicsMark, this.Marks.programingMark));
  104.     }
  105. }
  106.  
  107. //CLASS MARKS
  108. package Tema4;
  109.  
  110. public class Marks {
  111.     //Fields
  112.     public double mathemathicsMark;
  113.     public double physicsMark;
  114.     public double programingMark;
  115.  
  116.     //Constructors
  117.     public Marks(){
  118.         this.mathemathicsMark = 2.0;
  119.         this.physicsMark = 2.0;
  120.         this.programingMark = 2.0;
  121.     }
  122.  
  123.     //Method to enter marks
  124.     public void enterMarks(double mathemathicsMark, double physicsMark, double programingMark){
  125.         this.mathemathicsMark = mathemathicsMark;
  126.         this.physicsMark = physicsMark;
  127.         this.programingMark = programingMark;
  128.     }
  129.  
  130.     //Method to find average grade
  131.     public double averageGrade(double mathemathicsMark, double physicsMark, double programingMark){
  132.         double avg;
  133.         avg = (mathemathicsMark + physicsMark + programingMark) / 3;
  134.         return avg;
  135.     }
  136. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement