You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

53 lines
1.3 KiB

/* SkiJumper.java
* CS207-2 Homework 7 Fall 2018
* This class represents a Ski Jumper in code.
*
* Add code to this class by implementing the interfaces
* ITrainer and IAthlete such that the code in main()
* executes providing the output shown in Problem 3.
*/
public class SkiJumper implements IAthlete, ITrainer
{
private String name;
private double hours;
private int nJumps;
public SkiJumper(String name){
this.name=name;
this.hours=0;
this.nJumps=0;
}
public String getName(){
return this.name;
}
public int getNJumps(){
return this.nJumps;
}
public void jump(){
this.nJumps += 1;
}
@Override
public void data(){
System.out.println("Name: "+this.name);
System.out.println("Hours: "+this.hours);
System.out.println("Number of jumps: "+this.nJumps);
}
@Override
public void train(double h){
System.out.println("I am on slopes "+h+" hours today");
this.hours += h;
}
@Override
public boolean equals(Object other) {
boolean eq;
if (other == null){
return false;
}
else if (this.getClass() != other.getClass()){
return false;
}
else{
SkiJumper sj = (SkiJumper) other;
return this.nJumps == sj.getNJumps();
}
} // End class SkiJumper
}