Add: assignment 2 close #2

This commit is contained in:
2022-04-03 17:23:02 +08:00
parent 80ae76b597
commit 5e9fc07694
13 changed files with 448 additions and 0 deletions

View File

@@ -0,0 +1,43 @@
/*
* Author: CHEN Yongyuan (Walter) 1930006025 from OOP(1007)
* Date: 2022/03/04
* Description: This is the Running class which is the subclass of the Sport class
*/
public class Marathon extends Running {
/**
* Constructor.
*
* @param playerNumber
* the player number
* @param length
* the length of the marathon
*/
public Marathon(int playerNumber, double length) {
super(playerNumber, length);
}
/**
* Constructor. Always set the length to 42.195
*
* @param playerNumber
*/
public Marathon(int playerNumber) {
this(playerNumber, 42.195);
}
/**
* Test.
*/
public static void testMarathon() {
Marathon m1 = new Marathon(1, 39.39);
System.out.println(m1.getLength() == 39.39);
System.out.println(m1.getPlayerNumber() == 1);
System.out.println(m1.isFun() == false);
Marathon m2 = new Marathon(2);
System.out.println(m2.getLength() == 42.195);
System.out.println(m2.getPlayerNumber() == 2);
System.out.println(m2.isFun() == false);
}
}