Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.company;
- import java.util.ArrayList;
- public class Student {
- private String studentName;
- private int studentLevel;
- private int studentGrade;
- private Course course;
- static ArrayList<Student> students = new ArrayList<>();
- //Constructions
- public Student(String sn, int sl, int sg, String cn, int ch, String cg){
- setStudentName(sn);
- setStudentLevel(sl);
- setStudentGrade(sg);
- course = new Course(cn, ch, cg);
- }
- public Student(){
- }
- //Setters and Getters
- public void setStudentName(String sn){
- studentName = sn;
- }
- public void setStudentLevel(int sl){
- studentLevel = sl;
- }
- public void setStudentGrade(int sg){
- studentGrade = sg;
- }
- public String getStudentName(){
- return studentName;
- }
- public int getStudentLevel(){
- return studentLevel;
- }
- public int getStudentGrade(){
- return studentGrade;
- }
- //Used methods
- public void addStudent(Student student){ //1
- students.add(student);
- }
- public void update(int index, String name, int level, int grade, String courseName, int hours, String courseGrade){
- //3
- students.get(index).setStudentName(name);
- students.get(index).setStudentLevel(level);
- students.get(index).setStudentGrade(grade);
- students.get(index).course.setCourseName(courseName);
- students.get(index).course.setCourseHours(hours);
- students.get(index).course.setCourseGrade(courseGrade);
- }
- public void remove(int index){ //4
- students.remove(index);
- }
- public void view(String name){ //2
- for(int i=0; i < students.size(); i++){
- if(name.equals(students.get(i).getStudentName())){
- System.out.println("Name " + students.get(i).getStudentName());
- System.out.println("Level: " + students.get(i).getStudentLevel());
- System.out.println("Grade: " + students.get(i).getStudentGrade());
- System.out.println("Course Name: " + students.get(i).course.getCourseName());
- System.out.println("Course Hours: " + students.get(i).course.getCourseHours());
- System.out.println("Course Grade: " + students.get(i).course.getCourseGrade());
- }
- }
- }
- public void studentsInCourse(String courseName){
- for (int i=0; i<studentsNumber(); i++) {
- if(courseName.equals(students.get(i).course.getCourseName())){
- System.out.println(students.get(i).getStudentName() + " takes the " + courseName + " course.");
- }
- }
- }
- public int studentsNumber() {
- return students.size();
- }
- }
Add Comment
Please, Sign In to add comment