Advertisement
Guest User

Untitled

a guest
Feb 28th, 2020
622
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.07 KB | None | 0 0
  1. Summary
  2.  
  3. 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.)
  4. Work Items
  5.  
  6. 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:
  7. The chart may be handwritten and can be more than one page. Please make it legible.
  8. Your image file can be PDF, JPG, TIF, or PNG.
  9. Please submit only one image file via Canvas. Do not email your instructor your work.
  10. Name your file Flowchart.jpg (or whatever is the extension for the graphic format you’re using). You must name your file this way.
  11. Write the program described below. Put the three Java files (ReportDriver.java, RaceReport.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.
  12. Please submit only a single zip file via Canvas. Do not email your instructor your work.
  13. 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.
  14. 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!
  15.  
  16. Program Description
  17.  
  18. You are to write a program that collects six 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 pieces of user input will be the individual race times that correspond all the racing participants; your program will prompt the user to enter these in via the keyboard. Note that you cannot assume these times will be in any particular order; putting them in order is one of the first things your program should after entry. Thus, your program will need to do the following:
  19.  
  20. Prompt the user for up to six ints or doubles, which represent the times for the racers.
  21. Sort the times into ascending order (i.e., greatest to least).But, only the top three finishing times will be reported.
  22. Remember, to swap two variables requires a third, temporary variable.
  23. 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.
  24. You may not use a built-in sorting method to sort your times. You have to use if statements (or something similar).
  25. Output the three top sorted race times in order (fastest time first).
  26. Describe the overlap in times, if any exist. The options will be:
  27. All are tied for first.
  28. Two are tied for first.
  29. None are tied for first (no overlap).
  30. Do step (3) for the second and third place finishes, as needed.
  31. Output the range of the race times for all racers.
  32. Output the average of all race times and the average for the top three finishers.
  33.  
  34. 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":
  35.  
  36. Data Input: Ask the user for up to six race times (in no particular order).
  37. Ordering Data: Order the race times from fastest to slowest.
  38. Data Analysis and Output:
  39. Determine how many racers tied for first, second or third place (i.e., how many overlap times) and output result to console.
  40. Calculate the range of the race times (i.e., the absolute value of the slowest minus the fastest times) and output result to console.
  41. Calculate the average of all race times and average of the top three race time output results to the console.
  42.  
  43. 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.
  44.  
  45. 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:
  46.  
  47. In the Race class:
  48. readIntimes
  49. sortTimesAscending
  50. ... and other methods ...
  51. In the RaceReport class: A writeReport method.
  52. 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.)
  53.  
  54. (Don't forget to create constructor and other methods, if appropriate.)
  55.  
  56. 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):
  57.  
  58. Enter the race times (in seconds):
  59. 85.6 120.5 90.2 94.66 79.22
  60.  
  61. First place (time in seconds): 79.22
  62. Second place (time in seconds): 85.6
  63. Third place (time in seconds): 90.2
  64.  
  65. The range of the race times (in seconds): 41.28
  66. The average time of all racers (in seconds): 94.036
  67. The average time of the top three racers (in seconds): 85.16
  68.  
  69. Enter another race? (y/n): y
  70.  
  71. Enter the race times (in seconds):
  72. 1 1 4 3
  73.  
  74. First place (time in seconds): 1.0
  75. Second place (time in seconds): 1.0
  76. Third place (time in seconds): 3.0
  77.  
  78. Two racers shared first place.
  79. The range of the race times (in seconds): 3.0
  80. The average time of all racers (in seconds): 2.25
  81.  
  82. Enter another race? (y/n): n
  83.  
  84. (Note that the particular numerical formatter I used displays two decimal places if needed and only one decimal place if the second isn't needed. If you don't duplicate that aspect of the output (e.g., you make all average times to two decimal places), that's okay.)
  85.  
  86. 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).
  87.  
  88. No variables and methods should be static (except main) because the assignment is about defining objects.
  89.  
  90. 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.
  91. Regarding the Grading Rubric
  92.  
  93. Most of the criteria listed on the rubric are self-explanatory. The Programming Style 1–3 criterion will be selected by the instructor from these criteria:
  94.  
  95. Comments describe purpose and conditions for each method: These are done as Javadoc comments that are placed before each method header line. (Look up "Javadoc" in the textbook index if you're not sure what this is.)
  96. Comments document non-obvious code blocks.
  97. Each code file has a header block at the top of the file that describes the purpose and assumptions of the class or program.
  98. Meaningful identifiers are used.
  99. Indentation is used appropriately to delineate code blocks.
  100.  
  101. Thus, if you wish to maximize your chance of receiving full-credit, make sure all of the above programming style criteria are met by your code.
  102. Additional Hints
  103.  
  104. Don’t wait till the last minute to get started or get help from the instructor. At the very least, read through the assignment the first day it's available. This assignment, in particular, is tricky. The code itself is not tricky, but figuring out how to think about object-oriented programming is tricky. You'll probably benefit from talking it out with your classmates and instructor.
  105. Follow the Coding Style Guidelines. Use comments in your code!
  106.  
  107. Here is a final checklist of items to run through before you submit your work:
  108.  
  109. You should be turning-in only one file, a zip file. Please make sure your flowchart image is oriented so it is upright when opened.
  110. Compile and execute your code before turning in your .java files. If they don't work, something is wrong.
  111. Do your file and directory names follow the correct convention as described in the assignment?
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement