BetinaUKTC

temo04

Oct 17th, 2021
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.49 KB | None | 0 0
  1. import java.util.Random;
  2.  
  3. public class Starter {
  4. public static void main(String[] args) {
  5.  
  6. Random rnd = new Random();
  7. String[] names = {"Georgi", "Petar", "Stefan", "Ivan", "Mariq"};
  8. String[] family = {"Georgiev", "Petrov", "Stefanov", "Ivanov", "Marinova"};
  9.  
  10. Students[] studentList = new Students[5];
  11. Scores[] scoreList = new Scores[5];
  12.  
  13. //СЪЗДАВАНЕ НА ОБЕКТИТЕ STUDENTS И SCORES
  14. for (int i = 0; i < 5; i++) {
  15. studentList[i] = new Students(names[i], family[i], String.valueOf(10000 + rnd.nextInt(20000)));
  16. double gradeM = 2.00 + (6.00 - 2.00) * rnd.nextDouble(); //произволно число межу 2.00 и 6.00
  17. double gradeP = 2.00 + (6.00 - 2.00) * rnd.nextDouble();
  18. double gradePro = 2.00 + (6.00 - 2.00) * rnd.nextDouble();
  19. scoreList[i] = new Scores(gradeM, gradeP, gradePro);
  20. }
  21.  
  22.  
  23. //ОТПЕЧАТВАНЕ НА ДАННИТЕ ЗА УЧНИЦИТЕ И ОЦЕНКИТЕ
  24. for (int j = 0; j < 5; j++) {
  25. studentList[j].info();
  26. System.out.printf("Math grade: %.2f \n", scoreList[j].gradeMath);
  27. System.out.printf("Physics grade:%.2f \n", scoreList[j].gradePhysics);
  28. System.out.printf("Programming grade: %.2f \n", scoreList[j].gradeProgramming);
  29. System.out.printf("Avg grade: %.2f \n", scoreList[j].avgGrade());
  30. System.out.println("---------");
  31. }
  32. }
  33. }
  34.  
  35.  
  36. public class Students {
  37. //Полета
  38. String name;
  39. String family;
  40. String number;
  41.  
  42. //Конструктор
  43. public Students(String name , String family, String number){
  44. this.name = name;
  45. this.family= family;
  46. this.number = number;
  47. }
  48.  
  49. //Custom method
  50. public void info(){
  51. System.out.println("Name: " + name);
  52. System.out.println("Family name: " + name);
  53. System.out.println("Number: " + number);
  54. }
  55. }
  56. public class Scores {
  57. //Полета
  58. double gradeMath;
  59. double gradePhysics;
  60. double gradeProgramming;
  61.  
  62. //Конструктор
  63. public Scores(double gradeMath, double gradePhysics, double gradeProgramming) {
  64. this.gradeMath = gradeMath;
  65. this.gradePhysics = gradePhysics;
  66. this.gradeProgramming = gradeProgramming;
  67. }
  68.  
  69. //Custom method
  70. public double avgGrade() {
  71. return (gradeMath + gradePhysics + gradeProgramming) / 3;
  72. }
  73. }
Advertisement
Add Comment
Please, Sign In to add comment