Westonci.ca is the Q&A platform that connects you with experts who provide accurate and detailed answers. Our platform provides a seamless experience for finding reliable answers from a network of experienced professionals. Connect with a community of professionals ready to provide precise solutions to your questions quickly and accurately.

Summary
You will write a racing report program using object-oriented programming with three classes:
ReportDriver, RaceReport, and Race. The main method of the program will be in the
class ReportDriver and will include a loop that allows you to enter in more than one race and
have reports written out for all the races you enter. (The user will enter one race then get a report for that race. After that, the user will be asked whether they want to enter in another race and get another report. This repeats until the user says they do not want to enter in any more races.)
Program Description
There are two major tasks in this assignment. Your first major task is to write a program that collects three pieces of user input about a race and provides a summary of facts about the race. Input will be via the keyboard and output (i.e., the summary of facts) will be via the display (a.k.a., console window). The three pieces of user input will be the three individual race times that correspond the first, second, and third top race finishers; your program will prompt the user to enter these in via the keyboard. Note that you cannot assume these times will be in order; putting them in order is one of the first things your program should do. Thus, your program will need to do the following:
1. Prompt the user for three ints or doubles, which represent the times for the three racers.
2. Sort the three scores into ascending order (i.e., least to greatest).
(a) Remember, to swap two variables requires a third, temporary variable.
(b) See the Math class (documented in Savitch Ch. 5; see the index for the exact location
. . . this is good practice for looking things up) for methods that might help you (e.g.,
min and max). Note that these methods produce a return value.
(c) Output the sorted race scores in order.
3. Describe the overlap in times, if any exist. The options will be:
(a) All are tied for first.
(b) Some are tied for first.
(c) None are tied for first.
4. Do step (4) for the second and third place finishes.
5. Output the range of the race scores.
6. Output the average of the race scores.
There are, of course, many different ways of writing this program. However, if you decompose
your tasks into smaller chunks, attacking a larger program becomes more manageable. If you
mentally divided up the tasks before you, you might have decided on the following list of "work
items", "chunks", or "modules":
Data Input: Ask the user for three race scores (in no particular order).
Ordering Data: Order the race scores by first, second, and third place.
Data Analysis and Output:
– Determine how many racers tied for first, second or third place (i.e., how many overlap
times) and output result to console.
– Calculate the range of the race scores (i.e., the absolute value of the slowest minus the
fastest times) and output result to console.
2 – Calculate the average of the race times and output result to console.


Sagot :

Answer:dddd

Explanation:

//The code is all written in Java and here are the three classes in order ReportDriver, RaceReport, and Race

class ReportDriver {

   

   public static void main(String[] args) {

       boolean continueRace = true;

       Scanner in = new Scanner(System.in);

       ArrayList<ArrayList<Integer>> races = new ArrayList<>();

       while (continueRace == true) {

           System.out.println("Would you like to enter into a race? Y or N");

           char answer = in.next().toLowerCase().charAt(0);

           if (answer == 'y') {

               Race race = new Race();

               races.add(race.Race());

           } else {

               break;

           }

       }

       for (int x = 0; x <= races.size()-1; x++) {

           RaceReport report = new RaceReport();

           report.RaceReport(races.get(x));

           report.printRange();

           report.printAverage();

       }

   }

}

//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

package sample;

import java.util.ArrayList;

public class RaceReport {

   int range, average;

   String first, second, third;

   public void RaceReport(ArrayList<Integer> times) {

       if (times.get(2) == times.get(1)) {

           if (times.get(2) == times.get(0)) {

               System.out.println(first = "Times tied for first place are " + times.get(2) + " and " + times.get(1) + " and " + times.get(0));

           } else {

               System.out.println(first = "Times tied for first place are " + times.get(2) + " and " + times.get(1));

               System.out.println(second = "Second place time is " + times.get(0));

           }

       } else if (times.get(1) == times.get(0)) {

           System.out.println(first = "First place time is " + times.get(2));

           System.out.println(second = "Times tied for Second place are " + times.get(1) + " and " + times.get(0));

       } else {

           System.out.println(first = "First place time is " + times.get(2));

           System.out.println(second = "Second place time is " + times.get(1));

           System.out.println( third = "Third place time is " + times.get(0));

       }

       range = Math.abs(times.get(0) - times.get(2));

       average = (times.get(2) + times.get(1) + times.get(0) / 3);

   }

   public void printRange() {

       System.out.println("The range of the race was " + range);

   }

   public void printAverage() {

       System.out.println("The average of the race was " + average);

   }

}

//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

package sample;

import java.util.ArrayList;

import java.util.Collections;

import java.util.Scanner;

public class Race {

   Scanner in = new Scanner(System.in);

   ArrayList<Integer> times = new ArrayList<>();

   public ArrayList<Integer> Race() {

       System.out.println("Input time 1:");

       times.add(in.nextInt());

       System.out.println("Input time 2:");

       times.add(in.nextInt());

       System.out.println("Input time 3:");

       times.add(in.nextInt());

       Collections.sort(times);

       return times;

   }

}