ZazoTazo

Updated Students Class

Jul 6th, 2019
261
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.78 KB | None | 0 0
  1. package com.company;
  2.  
  3. import java.util.ArrayList;
  4.  
  5.     public class Student {
  6.         private String studentName;
  7.         private int studentLevel;
  8.         private int studentGrade;
  9.         private Course course;
  10.         static ArrayList<Student> students = new ArrayList<>();
  11.  
  12.     //Constructions
  13.     public Student(String sn, int sl, int sg, String cn, int ch, String cg){
  14.         setStudentName(sn);
  15.         setStudentLevel(sl);
  16.         setStudentGrade(sg);
  17.         course = new Course(cn, ch, cg);
  18.     }
  19.     public Student(){
  20.  
  21.     }
  22.  
  23.     //Setters and Getters
  24.     public void setStudentName(String sn){
  25.         studentName = sn;
  26.     }
  27.     public void setStudentLevel(int sl){
  28.         studentLevel = sl;
  29.     }
  30.     public void setStudentGrade(int sg){
  31.         studentGrade = sg;
  32.     }
  33.     public String getStudentName(){
  34.         return studentName;
  35.     }
  36.     public int getStudentLevel(){
  37.         return studentLevel;
  38.     }
  39.     public int getStudentGrade(){
  40.         return studentGrade;
  41.     }
  42.  
  43.     //Used methods
  44.     public void addStudent(Student student){ //1
  45.         students.add(student);
  46.     }
  47.     public void update(int index, String name, int level, int grade, String courseName, int hours, String courseGrade){
  48.         //3
  49.         students.get(index).setStudentName(name);
  50.         students.get(index).setStudentLevel(level);
  51.         students.get(index).setStudentGrade(grade);
  52.         students.get(index).course.setCourseName(courseName);
  53.         students.get(index).course.setCourseHours(hours);
  54.         students.get(index).course.setCourseGrade(courseGrade);
  55.     }
  56.     public void remove(int index){ //4
  57.         students.remove(index);
  58.     }
  59.     public void view(String name){ //2
  60.         for(int i=0; i < students.size(); i++){
  61.             if(name.equals(students.get(i).getStudentName())){
  62.                 System.out.println("Name " + students.get(i).getStudentName());
  63.                 System.out.println("Level: " + students.get(i).getStudentLevel());
  64.                 System.out.println("Grade: " + students.get(i).getStudentGrade());
  65.                 System.out.println("Course Name: " + students.get(i).course.getCourseName());
  66.                 System.out.println("Course Hours: " + students.get(i).course.getCourseHours());
  67.                 System.out.println("Course Grade: " + students.get(i).course.getCourseGrade());
  68.             }
  69.         }
  70.     }
  71.  
  72.     public void studentsInCourse(String courseName){
  73.         for (int i=0; i<studentsNumber(); i++) {
  74.             if(courseName.equals(students.get(i).course.getCourseName())){
  75.                 System.out.println(students.get(i).getStudentName() + " takes the " + courseName + " course.");
  76.             }
  77.         }
  78.     }
  79.     public int studentsNumber() {
  80.         return students.size();
  81.     }
  82. }
Add Comment
Please, Sign In to add comment