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;
- static ArrayList<Student> students = new ArrayList<>();
- public Student(String sn, int sl, int sg){
- setStudentName(sn);
- setStudentLevel(sl);
- setStudentGrade(sg);
- }
- public Student(){
- }
- 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;
- }*/
- public void addStudent(Student student){ //1
- students.add(student);
- }
- public void update(int index, String name, int level, int grade){ //3
- students.get(index).setStudentName(name);
- students.get(index).setStudentLevel(level);
- students.get(index).setStudentGrade(grade);
- }
- 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).studentName)){
- System.out.println("Name " + students.get(i).studentName);
- System.out.println("Level: " + students.get(i).studentLevel);
- System.out.println("Grade: " + students.get(i).studentGrade);
- }
- }
- }
- public int studentsNumber() {
- return students.size();
- }
- }
Add Comment
Please, Sign In to add comment