Advertisement
oona

fitness experiment

Feb 4th, 2014
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.38 KB | None | 0 0
  1. public class fitnessExperiment {
  2.  
  3.     public static void main(String[] args) {
  4.         // TODO Auto-generated method stub
  5.        
  6.         //inputs
  7.         double distance[] = {30.6, 56.8, 29.0, 105.1, 78.5, 201.1, 88.9, 99.6, 75.4, 219.2, 61.0, 59.8, 99.9, 160.0, 39.8};
  8.         String day[] = {"1st May", "2nd May", "3rd May", "4th May", "5th May", "6th May", "7th May", "8th May", "9th May", "10th May", "11th May", "12th May", "13th May", "14th May", "15th May"};
  9.         double temp1;
  10.         String temp2;
  11.        
  12.         System.out.println("My longest rate, what is? And I'll classify the distances in a descending order");
  13.         //the highest rate
  14.         for(int i=0; i<distance.length; i++)
  15.         {
  16.             for(int j=1; j<(distance.length-i); j++)
  17.             {
  18.                 if(distance[j-1]<distance[j])
  19.                 {
  20.                     temp1 = distance[j-1];
  21.                     distance[j-1] = distance[j];
  22.                     distance[j] = temp1;
  23.                    
  24.                     temp2 = day[j-1];
  25.                     day[j-1] = day[j];
  26.                     day[j] = temp2;
  27.                 }
  28.             }
  29.         }
  30.         for(int i=0; i<distance.length; i++)
  31.             System.out.println("My longest distance was " + distance[i] + " m, " + day[i]);
  32.        
  33.         //the average rate
  34.         double total = 0;
  35.         double average = 0;
  36.        
  37.         System.out.println("What was my average distance ran?");
  38.        
  39.         for(int i=0; i<distance.length; i++)
  40.         {
  41.         total = total + distance[i];
  42.         average = total/15;
  43.         }
  44.        
  45.         System.out.println("My average distance was " + average + " m");
  46.  
  47.     } //class ends
  48.  
  49. } //program ends
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement