Add: assignment 2 close #2
This commit is contained in:
43
assignment2/Question1/Marathon.java
Normal file
43
assignment2/Question1/Marathon.java
Normal 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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user