lab5
This commit is contained in:
56
lab/lab5/Question3/Student.java
Normal file
56
lab/lab5/Question3/Student.java
Normal file
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
* 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);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user