Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Shavit Borisov
- // CW
- import java.util.Scanner;
- public class Competition {
- public static void main(String[] args)
- {
- Scanner in = new Scanner (System.in);
- int playerAmount;
- double averageTime = 0;
- System.out.printf("How many people are participating in the competition? ");
- playerAmount = in.nextInt();
- Player[] participant = new Player[playerAmount];
- System.out.printf("Enter details for each participant\n");
- for(int i = 0; i < playerAmount; i++)
- {
- System.out.printf("Participant No. %d:\n", i + 1);
- System.out.printf("Name: ");
- String currentName = in.next();
- System.out.printf("Address: ");
- String currentAdress = in.next();
- System.out.printf("Id: ");
- String currentId = in.next();
- System.out.printf("Time: ");
- double currentTime = in.nextDouble();
- participant[i] = new Player(currentName, currentAdress, currentId, currentTime);
- }
- for(int i = 0; i < playerAmount; i++)
- averageTime += participant[i].getTime();
- averageTime /= playerAmount;
- for(int i = 0; i < playerAmount; i++)
- if(participant[i].getTime() < averageTime)
- participant[i].getData();
- in.close();
- }
- }
- // Next class
- public class Player
- {
- private String name;
- private String address;
- private String id;
- private double time;
- public Player(String name, String address, String id, double time)
- {
- this.name = name;
- this.address = address;
- this.id = id;
- this.time = time;
- }
- public double getTime()
- {
- return time;
- }
- public void getData()
- {
- System.out.printf("___________________________\n");
- System.out.printf("Name: %s\n", name);
- System.out.printf("Address: %s\n", address);
- System.out.printf("Id: %s\n", id);
- System.out.printf("Time: %f\n", time);
- System.out.printf("___________________________\n");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement