Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

HW: Classes (CSS): You will write a racing report program using object-oriented programming with three classes: ReportDriver, RaceReport, and Race. The main method of the

HW: Classes (CSS):

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.)

Work Items

  1. Draw a flow chart of your main method in ReportDriver. You can treat the methods called by your main program as black-boxes, as far as the flow chart is concerned. (That is, just represent calls to methods as a rectangle with the calling text inside the rectangle.) If your flow chart is too complex your code can probably be simplified by putting some functionality into a method. Submit the image file of a scan of this flow chart:
    1. The chart may be handwritten and can be more than one page. Please make it legible.
    2. Your image file can be PDF, JPG, TIF, or PNG.
    3. Please submit only one image file via Canvas. Do not email your instructor your work.
    4. Name your file Flowchart.jpg (or whatever is the extension for the graphic format youre using). You must name your file this way.
  2. Write the program described below. Put the three Java files (ReportDriver.java, Report.java, and Race.java) that are your classes in a directory, add in your flow chart file, zip up the directory, then submit the zip file to your instructor.
    1. Please submit only a single zip file via Canvas. Do not email your instructor your work.
    2. Name your directory HW_Classes and your zip file HW_Classes.zip. You must name your directory and zip file this way. In the end, this one zip file will contain one directory and that directory will contain four files.
    3. If you're not sure how to create a zip file of a directory, please do a Google search to find out. The process to do so will be different depending on what operating system you're using. You do not merely rename the directory by putting .zip extension on it. Make sure you give yourself time to do this!

Program Description

You are 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 times into ascending order (i.e., least to greatest).
    1. Remember, to swap two variables requires a third, temporary variable.
    2. 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.
    3. You may not use a built-in sorting method to sort your times. You have to use if statements (or something similar).
    4. Output the sorted race times in order (fastest time first).
  3. Describe the overlap in times, if any exist. The options will be:
    1. All are tied for first.
    2. Two are tied for first.
    3. None are tied for first (no overlap).
  4. Do step (3) for the second and third place finishes, as needed.
  5. Output the range of the race times.
  6. Output the average of the race times.

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 times (in no particular order).
  • Ordering Data: Order the race times 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 times (i.e., the absolute value of the slowest minus the fastest times) and output result to console.
    • Calculate the average of the race times and output result to console.

The program that you write is not to be a procedural (or structured programming) program but is to be divided up in an object-oriented way. That is, your program should be divided into blocks of sub-tasks that can become methods, and you are then to create the infrastructure (e.g., declaring and setting instance attributes, creating accessor and/or mutator methods, making sure all the classes can work with one another, etc.) to implement the program in an object-oriented way.

What might be some of the methods that you will create? Here are just as few from one possible solution (it does not include all the methods from that solution). Again, remember that there are many valid ways of writing this program; you may or may not want to create any of these methods, but you will almost certainly need to create more than these methods. (Note the grading rubric describes the minimum number of methods I expect to see in your code.) This list is just to give you an idea of how one might be able to restructure the functionality described above into an object-oriented structure:

  • In the Race class:
    • readIntimes
    • sortTimesAscending
    • ... and other methods ...
  • In the RaceReport class: A writeReport method.
  • In the ReportDriver class: There is only a main method. (If you have other methods here, such as a test method, that's okay, but if you don't, that's okay too.)

(Don't forget to create constructor and other methods, if appropriate.)

Your program is required to exactly reproduce the format and behavior of the sample execution below (note how the user is asked to continue if desired):

Enter the race times (in seconds): 85.6 120.5 90.2 First place (time in seconds): 85.6 Second place (time in seconds): 90.2 Third place (time in seconds): 120.5 The range of the race times (in seconds): 34.9 The average time of all racers (in seconds): 98.77 Enter another race? (y/n): y Enter the race times (in seconds): 1 1 4 First place (time in seconds): 1.0 Second place (time in seconds): 1.0 Third place (time in seconds): 4.0 Two racers shared first place. The range of the race times (in seconds): 3.0 The average time of all racers (in seconds): 2.0 Enter another race? (y/n): n

I expect you to make appropriate choices about variable types and which variables are instance variables and which are local to a method. The private data (attributes) of any class should only be the data directly associated with being that kind of object. Thus, the private attributes of Race should only be the data associated with being a race. Any other variables that help in performing the tasks (i.e., the methods) should be local (i.e., defined within the method).

No variables and methods should be static (except main) because the assignment is about defining objects.

Finally, there should be at least one method that you write that can be used to provide output for tracing variables: The method should be called test-something, e.g., testVariableValues. Somewhere in your program, there should be a call to that method. In the code you submit, that call should be commented out, but I should be able to find it.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

MongoDB Applied Design Patterns Practical Use Cases With The Leading NoSQL Database

Authors: Rick Copeland

1st Edition

1449340040, 978-1449340049

More Books

Students also viewed these Databases questions