ZazoTazo

Students class

Jun 22nd, 2019
235
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.74 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.     static ArrayList<Student> students = new ArrayList<>();
  10.  
  11.     public Student(String sn, int sl, int sg){
  12.         setStudentName(sn);
  13.         setStudentLevel(sl);
  14.         setStudentGrade(sg);
  15.     }
  16.     public Student(){
  17.  
  18.     }
  19.  
  20.     public void setStudentName(String sn){
  21.         studentName = sn;
  22.     }
  23.     public void setStudentLevel(int sl){
  24.         studentLevel = sl;
  25.     }
  26.     public void setStudentGrade(int sg){
  27.         studentGrade = sg;
  28.     }
  29.     /*public String getStudentName(){
  30.         return studentName;
  31.     }
  32.     public int getStudentLevel(){
  33.         return studentLevel;
  34.     }
  35.     public int getStudentGrade(){
  36.         return studentGrade;
  37.     }*/
  38.     public void addStudent(Student student){ //1
  39.         students.add(student);
  40.     }
  41.     public void update(int index, String name, int level, int grade){ //3
  42.             students.get(index).setStudentName(name);
  43.             students.get(index).setStudentLevel(level);
  44.             students.get(index).setStudentGrade(grade);
  45.     }
  46.     public void remove(int index){ //4
  47.             students.remove(index);
  48.     }
  49.     public void view(String name){ //2
  50.         for(int i=0; i < students.size(); i++){
  51.             if(name.equals(students.get(i).studentName)){
  52.                 System.out.println("Name " + students.get(i).studentName);
  53.                 System.out.println("Level: " + students.get(i).studentLevel);
  54.                 System.out.println("Grade: " + students.get(i).studentGrade);
  55.             }
  56.         }
  57.     }
  58.     public int studentsNumber() {
  59.         return students.size();
  60.     }
  61. }
Add Comment
Please, Sign In to add comment