Facebook
From zahid, 1 Week ago, written in Java.
Embed
Download Paste or View Raw
Hits: 57
  1. package athlete;
  2.  
  3. public class Athlete {
  4.  
  5.     String name, gender;
  6.     double age, rank, noOfEventParticipanted;
  7.    
  8.  
  9.     public Athlete(String name, String gender, int age, int rank, int noOfEventParticipant) {
  10.         this.name = name;
  11.         this.gender = gender;
  12.         this.age = age;
  13.         this.rank = rank;
  14.         this.noOfEventParticipanted = noOfEventParticipant;
  15.     }
  16.    
  17.     void participantInEvent(int position, boolean isNewRecord){
  18.         if(position ==1) rank++;
  19.         else if(position == 2) rank+=0.5;
  20.         else if(position ==3) rank+=0.25;
  21.         if(isNewRecord) rank+=0.5;
  22.     }
  23.  
  24.     public double getRank() {
  25.         return rank;
  26.     }
  27.  
  28.     public double getNoOfEventParticipanted() {
  29.         return noOfEventParticipanted;
  30.     }
  31.      public void display()
  32.      {
  33.          System.out.println(name+" "+age+" "+rank);
  34.      }
  35.  
  36. }
  37.  
  38. class TestAthlete{
  39.  
  40.     public static void main(String[] args) {
  41.         Athlete a = new Athlete("rahim","male",17,73,75);
  42.         a.participantInEvent(1, false);
  43.         System.out.println(a.getRank());
  44.         a.display();
  45.     }
  46. }