a3 part 1

This commit is contained in:
2022-04-11 11:02:56 +08:00
parent 5e9fc07694
commit 72874e2cc3
3 changed files with 91 additions and 0 deletions

33
assignment3/Human.java Normal file
View File

@@ -0,0 +1,33 @@
/*
* Author: CHEN Yongyuan (Walter) 1930006025 from OOP(1007)
* Date: 2022-04-11
* Description: Human class
*/
public class Human extends Mammal {
/**
* Constructor.
*
* The Constructor take no argument. All human are named "Alice"
*/
public Human() {
super("Alice");
}
/**
* Human cannot be cooked.
*
* @return false
*/
@Override
public boolean isCookable() {
return false;
}
/**
* Test.
*/
public static void testHuman() {
}
}

53
assignment3/Mammal.java Normal file
View File

@@ -0,0 +1,53 @@
/*
* Author: CHEN Yongyuan (Walter) 1930006025 from OOP(1007)
* Date: 2022-04-11
* Description: Mammal class
*/
public class Mammal {
/**
* Name of the mammal
*/
private String name;
/**
* Constructor
*
* @param name
* name of the mammal
*/
public Mammal(String name) {
this.name = name;
}
/**
* Get the name of the mammal
*
* @return name of the mammal
*/
public String getName() {
return name;
}
/**
* Whether the mammal is can be cooked.
* Some mammals can be cooked and some mammals cannot be cooked so for safety
* reason the isCookable method just prints a message "Do not cook this!" and
* returns false.
*
* @return false
*/
public boolean isCookable() {
System.out.println("Do not cook this!");
return false;
}
/**
* Test.
*/
public static void testMammal() {
Mammal mammal = new Mammal("Mammal 1");
System.out.println(mammal.getName() == "Mammal 1");
System.out.println(mammal.isCookable() == false);
}
}

5
assignment3/Start.java Normal file
View File

@@ -0,0 +1,5 @@
public class Start {
public static void main(String[] args) {
Mammal.testMammal();
}
}