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

7 years ago
7 years ago
  1. /* SkiJumper.java
  2. * CS207-2 Homework 7 Fall 2018
  3. * This class represents a Ski Jumper in code.
  4. *
  5. * Add code to this class by implementing the interfaces
  6. * ITrainer and IAthlete such that the code in main()
  7. * executes providing the output shown in Problem 3.
  8. */
  9. public class SkiJumper implements IAthlete, ITrainer
  10. {
  11. private String name;
  12. private double hours;
  13. private int nJumps;
  14. public SkiJumper(String name){
  15. this.name=name;
  16. this.hours=0;
  17. this.nJumps=0;
  18. }
  19. public String getName(){
  20. return this.name;
  21. }
  22. public int getNJumps(){
  23. return this.nJumps;
  24. }
  25. public void jump(){
  26. this.nJumps += 1;
  27. }
  28. @Override
  29. public void data(){
  30. System.out.println("Name: "+this.name);
  31. System.out.println("Hours: "+this.hours);
  32. System.out.println("Number of jumps: "+this.nJumps);
  33. }
  34. @Override
  35. public void train(double h){
  36. System.out.println("I am on slopes "+h+" hours today");
  37. this.hours += h;
  38. }
  39. @Override
  40. public boolean equals(Object other) {
  41. boolean eq;
  42. if (other == null){
  43. return false;
  44. }
  45. else if (this.getClass() != other.getClass()){
  46. return false;
  47. }
  48. else{
  49. SkiJumper sj = (SkiJumper) other;
  50. return this.nJumps == sj.getNJumps();
  51. }
  52. } // End class SkiJumper
  53. }