Add: assignment 2 close #2
This commit is contained in:
50
assignment2/Question1/Running.java
Normal file
50
assignment2/Question1/Running.java
Normal file
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
* 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 Running extends Sport {
|
||||
/**
|
||||
* The length of the running.
|
||||
*/
|
||||
private double length;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param playerNumber the player number of the running.
|
||||
* @param length the length of the running
|
||||
*/
|
||||
public Running(int playerNumber, double length) {
|
||||
super(playerNumber);
|
||||
this.length = length;
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter for the length of the running.
|
||||
*/
|
||||
public double getLength() {
|
||||
return length;
|
||||
}
|
||||
|
||||
/**
|
||||
* Running is not fun.
|
||||
*
|
||||
* @return false
|
||||
*/
|
||||
@Override
|
||||
public boolean isFun() {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test.
|
||||
*/
|
||||
public static void testRunning() {
|
||||
Running r1 = new Running(1, 1.5);
|
||||
System.out.println(r1.getPlayerNumber() == 1);
|
||||
System.out.println(r1.getLength() == 1.5);
|
||||
System.out.println(r1.isFun() == false);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user