57 lines
897 B
Java
57 lines
897 B
Java
/*
|
|
* Author: CHEN Yongyuan (Walter) 1930006025 from OOP(1007)
|
|
* Date: 2022/03/19
|
|
* Description: Student class
|
|
*/
|
|
|
|
public class Student {
|
|
/**
|
|
* Student's name
|
|
*/
|
|
private String name;
|
|
|
|
/**
|
|
* Student's pet
|
|
*/
|
|
private Cat pet;
|
|
|
|
/**
|
|
* Constructor
|
|
*/
|
|
public Student(String name, Cat pet) {
|
|
this.name = name;
|
|
this.pet = pet;
|
|
}
|
|
|
|
/**
|
|
* Getter for name
|
|
*
|
|
* @return String
|
|
*/
|
|
public String getName() {
|
|
return name;
|
|
}
|
|
|
|
/**
|
|
* Getter for pet
|
|
*
|
|
* @return Cat
|
|
*/
|
|
public Cat getPet() {
|
|
return pet;
|
|
}
|
|
|
|
/**
|
|
* Test
|
|
*/
|
|
public static void testStudent() {
|
|
Cat cat = new Cat("Tom", 1.0);
|
|
Student student = new Student("Walter", cat);
|
|
System.out.println(student.getName() == "Walter");
|
|
System.out.println(student.getPet() == cat);
|
|
System.out.println(student.getPet().getName() == "Tom");
|
|
System.out.println(student.getPet().getWeight() == 1.0);
|
|
}
|
|
|
|
}
|