Files
oop/assignment3/Question2/StartGrading.java
2022-04-17 11:41:41 +08:00

100 lines
3.6 KiB
Java
Raw Blame History

public class StartGrading {
public static void testMammal() {
Mammal m = new Mammal("some name");
System.out.println(m.getName() == "some name");
System.out.println(m.isCookable() == false); // Message printed too.
}
public static void testHuman() {
Human h = new Human();
// getName is inherited from Mammal.
System.out.println(h.getName() == "Alice");
System.out.println(h.isCookable() == false); // No message printed.
}
public static void testRabbit() {
Rabbit r = new Rabbit("Bugs Bunny", 20.0);
// getName is inherited from Mammal.
System.out.println(r.getName() == "Bugs Bunny");
System.out.println(r.getWeight() == 20.0);
System.out.println(r.isCookable() == true);
}
public static void testEuropeanRabbit() {
// Testing the first constructor.
EuropeanRabbit er1 = new EuropeanRabbit("black bunny", 3.0);
// getName is inherited from Mammal.
System.out.println(er1.getName() == "black bunny");
// getWeight is inherited from Rabbit.
System.out.println(er1.getWeight() == 3.0);
// isCookable is inherited from Rabbit.
System.out.println(er1.isCookable() == true);
// Testing the second constructor.
EuropeanRabbit er2 = new EuropeanRabbit("white rabbit");
// getName is inherited from Mammal.
System.out.println(er2.getName() == "white rabbit");
// getWeight is inherited from Rabbit.
System.out.println(er2.getWeight() == 2.0);
// isCookable is inherited from Rabbit.
System.out.println(er2.isCookable() == true);
}
public static void testEuropeanRabbit() {
// Testing the first constructor.
EuropeanRabbit er1 = new EuropeanRabbit("black bunny", 3.0);
// getName is inherited from Mammal.
System.out.println(er1.getName() == "black bunny");
// getWeight is inherited from Rabbit.
System.out.println(er1.getWeight() == 3.0);
// isCookable is inherited from Rabbit.
System.out.println(er1.isCookable() == true);
// Testing the second constructor.
EuropeanRabbit er2 = new EuropeanRabbit("white rabbit");
// getName is inherited from Mammal.
System.out.println(er2.getName() == "white rabbit");
// getWeight is inherited from Rabbit.
System.out.println(er2.getWeight() == 2.0);
// isCookable is inherited from Rabbit.
System.out.println(er2.isCookable() == true);
}
public static void testFrankTheRabbit() {
FrankTheRabbit ftr = new FrankTheRabbit();
// getName is inherited from Mammal.
System.out.println(ftr.getName() == "Frank");
// getWeight is inherited from Rabbit.
System.out.println(ftr.getWeight() == 100.0);
// isCookable is from FrankTheRabbit itself.
System.out.println(ftr.isCookable() == false);
}
public static void testCastIronPot() {
// In the testCastIronPot method, create a lapin saut<75><74> chasseur called lsc1...
LapinSaut<EFBFBD><EFBFBD>Chasseur lsc1 = new LapinSaut<EFBFBD><EFBFBD>Chasseur();
// then create a cast iron pot with this lapin saut<75><74> chasseur in it.
CastIronPot cip = new CastIronPot(lsc1); // Implicit upcast from LapinSaut<75><74>Chasseur to Rabbit.
// Then get the lapin saut<75><74> chasseur from the cast iron pot...
Rabbit r = cip.getRabbit();
// and store it into a local variable called lsc2 of type LapinSaut<75><74>Chasseur.
LapinSaut<EFBFBD><EFBFBD>Chasseur lsc2 = (LapinSaut<EFBFBD><EFBFBD>Chasseur)r; // Downcast mandatory!
// Use the == operator to check that lsc1 and lsc2 are the same lapin saut<75><74> chasseur.
System.out.println(lsc1 == lsc2);
}
public static void main(String[] args) {
testMammal();
testHuman();
testRabbit();
testEuropeanRabbit();
testLapinSaut<EFBFBD><EFBFBD>Chasseur();
testFrankTheRabbit();
testCastIronPot();
}
}