Advertisement
Shavit

P. 95 Ex. 11.13

Feb 18th, 2014
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.83 KB | None | 0 0
  1. // Shavit Borisov
  2. // CW
  3.  
  4. import java.util.Scanner;
  5.  
  6. public class Competition {
  7.  
  8.     public static void main(String[] args)
  9.     {
  10.         Scanner in = new Scanner (System.in);
  11.         int playerAmount;
  12.         double averageTime = 0;
  13.        
  14.         System.out.printf("How many people are participating in the competition? ");
  15.         playerAmount = in.nextInt();
  16.        
  17.         Player[] participant = new Player[playerAmount];
  18.        
  19.         System.out.printf("Enter details for each participant\n");
  20.         for(int i = 0; i < playerAmount; i++)
  21.         {
  22.             System.out.printf("Participant No. %d:\n", i + 1);
  23.             System.out.printf("Name: ");
  24.             String currentName = in.next();
  25.             System.out.printf("Address: ");
  26.             String currentAdress = in.next();
  27.             System.out.printf("Id: ");
  28.             String currentId = in.next();
  29.             System.out.printf("Time: ");
  30.             double currentTime = in.nextDouble();
  31.             participant[i] = new Player(currentName, currentAdress, currentId, currentTime);
  32.         }
  33.         for(int i = 0; i < playerAmount; i++)
  34.             averageTime += participant[i].getTime();
  35.        
  36.         averageTime /= playerAmount;
  37.        
  38.         for(int i = 0; i < playerAmount; i++)
  39.             if(participant[i].getTime() < averageTime)
  40.                 participant[i].getData();
  41.        
  42.         in.close();
  43.     }
  44. }
  45.  
  46. // Next class
  47.  
  48. public class Player
  49.  
  50. {
  51.     private String name;
  52.     private String address;
  53.     private String id;
  54.     private double time;
  55.    
  56.     public Player(String name, String address, String id, double time)
  57.     {
  58.         this.name = name;
  59.         this.address = address;
  60.         this.id = id;
  61.         this.time = time;
  62.     }
  63.    
  64.     public double getTime()
  65.     {
  66.         return time;
  67.     }
  68.    
  69.     public void getData()
  70.     {
  71.         System.out.printf("___________________________\n");
  72.         System.out.printf("Name: %s\n", name);
  73.         System.out.printf("Address: %s\n", address);
  74.         System.out.printf("Id: %s\n", id);
  75.         System.out.printf("Time: %f\n", time);
  76.         System.out.printf("___________________________\n");
  77.     }
  78. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement