fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. public static void main (String[] args) throws java.lang.Exception
  11. {
  12. Student[] students = new Student[5];
  13.  
  14. students[0] = new Student("Andrey","Kosyak","in-73");
  15. students[1] = new Student("Daniil","Shilov","in-73");
  16. students[2] = new Student("Alexandr","Grinenko","in-73");
  17. students[3] = new Student("Yuriy","Svityuk","in-73");
  18. students[4] = new Student("Maxim","Mazhuga","in-73");
  19.  
  20. for(int i = 0; i < 5; i++){
  21. System.out.println(students[i].getId() + " " + students[i].getName() + " " + students[i].getSurname() + " " + students[i].getGroup());
  22. for(int j = 0; j < 5; j++){
  23. System.out.println(students[j].getSubjects());
  24. }
  25. }
  26. }
  27. }
  28.  
  29. public class Student
  30. {
  31. private int id;
  32. private static int nextId = 1;
  33. private String name;
  34. private String surname;
  35. private String group;
  36. private Subject [] subjects;
  37.  
  38. //getters
  39. public int getId(){
  40. return id;
  41. }
  42. public int getNextId(){
  43. return nextId;
  44. }
  45. public String getName(){
  46. return name;
  47. }
  48. public String getSurname(){
  49. return surname;
  50. }
  51. public String getGroup(){
  52. return group;
  53. }
  54. public Subject[] getSubjects(){
  55. return subjects;
  56. }
  57.  
  58. //setters
  59. public void setId(int id){
  60. this.id=id;
  61. }
  62. public void setNextId(int nextId){
  63. this.nextId=nextId;
  64. }
  65. public void setName(String name){
  66. this.name=name;
  67. }
  68. public void setSurname(String surname){
  69. this.surname=surname;
  70. }
  71. public void setGroup(String group){
  72. this.group=group;
  73. }
  74. public void setSubject(Subject[] subjects) {
  75. this.subjects = subjects;
  76. }
  77.  
  78. //constructor
  79. public Student(String name, String surname, String group){
  80. this.id = nextId++;
  81. this.name = name;
  82. this.surname = surname;
  83. this.group = group;
  84. this.subjects = new Subject[5];
  85. for(int i = 0; i < this.subjects.length; i++){
  86. this.subjects[i] = new Subject();
  87. }
  88. }
  89. }
  90. public class Subject {
  91. private String nameSubject;
  92. private float mark;
  93. private boolean passed;
  94.  
  95. String[] nameSubjects = new String[]{"Mathematics", "Physics", "Computer science", "English", "Biology"};
  96.  
  97. public Subject(){
  98. for(int i = 0; i < this.nameSubjects.length; i++){
  99. this.nameSubject = nameSubjects[i];
  100. this.mark = (float)(Math.random()*(5-2))+2;
  101. }
  102. }
  103.  
  104.  
  105. public void check(){
  106. if(mark > 2 && mark <= 5){
  107. passed = true;
  108. }
  109. }
  110.  
  111. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
Main.java:29: error: class Student is public, should be declared in a file named Student.java
public class Student
       ^
Main.java:90: error: class Subject is public, should be declared in a file named Subject.java
public class Subject {
       ^
2 errors
stdout
Standard output is empty