Files
oop/lab/lab3/Question1/Student.java
2022-03-10 17:18:03 +08:00

48 lines
1.0 KiB
Java

/*
* Author: CHEN Yongyuan (Walter) 1930006025 from OOP(1007)
* Date: 2022/03/03
* Description: Student class
*/
public class Student {
/**
* Student's ID number
*/
private int ID;
/**
* Constructor A public constructor with one parameter
*
* @param id the ID of the student, only accept positive integer if the id is
* not positive, it will be set to 0
*/
public Student(int ID) {
this.ID = ID;
}
/**
* Getter A public getter for the ID.
*
* @return the ID of the student
*/
public int getID() {
return ID;
}
/**
* Test method A public method to test the class
*
* @return void
*/
public static void testStudent() {
Student s1 = new Student(-39);
Student s2 = new Student(114514);
Student s3 = new Student(0);
// print true
System.out.println(s1.getID() == -39);
System.out.println(s2.getID() == 114514);
System.out.println(s3.getID() == 0);
}
}