Athlete
class with one field that holds a FinalResult
object.
FinalResult
class holds a ShootingResult
object and a SkiingResult
object.
ShootingResult
class holds four separate ShootingRound
objects, one for each of four rounds (e.g., round1
, round2
, round3
, and round4
). Each ShootingRound
stores the number of targets hit (out of five). Use int
for this value. Assume that only valid numbers of targets hit will be created; you do not need to do any error checking at this point in the course.
SkiingResult
class holds the time (in seconds) at which the athlete crossed the finish line for each lap and the athlete's position in the finishing order on the final lap (1 for first, 2 for second, etc). Use a double for each of the five lap times and an int for the position.
ShootingResult
and SkiingResult
should implement an IEvent
interface. This interface should require a method called pointsEarned
which takes no additional inputs and returns a double
representing an athlete's score on that event.
ShootingResult
is the sum of the targets hit for each round.
SkiingResult
is the sum of each lap time.
FinalResult
class, include a method called getShootingPenalties
that takes a ShootingResult as an input parameter. This method should calculate the amount of penalty time (60 seconds) for each target missed in each round. It should return this modifier as a double. Note that this method returns a modifier that is later applied to the time, not a modified time.
FinalResult
class, include a method called finalScore()
that takes no inputs and returns the athlete's final score. This score will be a combination of the athlete's skiing time, position, and shooting penalties.
Athlete
class, include a betterSkiier
method that takes another Athlete
as input and produces the athlete with the better (lower) Skiier score. Assume there are no ties (meaning we won't test for ties and neither should you, as the behavior in event of a tie is not specified).
Athlete
class, include a hasBeaten
method that takes another Athlete
as input and returns a boolean indicating whether the athlete has either a higher shooting score or a lower skiing score than the given (input) Athlete
.
Examples
.
Note on testing Doubles: When you want to use assertEquals to compare doubles, you include a third argument which is the allowable difference between the two values for them to still be considered equal. For example:
assertEquals(5.0, 4.995, .01)returns
true
. Doubles can be imprecise due to the way they are represented within the computer, hence the need for this third argument.
Note on Writing Tests that Compare Objects: A subtlety to JUnit (that we will talk about next week) affects how you write tests that compare objects. When writing these tests, name the objects for your rounds and use the names in the assertEquals
test. The example below assumes that ShootingResult contains a hypothetical method called bestRound() that returns a ShootingRound:
public class Examples { ShootingRound longRound = new ShootingRound(...); ShootingResult goodResult = new ShootingResult(... longRound ...); ... @Test public void testLongBest() { assertEquals(longRound, goodResult.bestRound()); } }You should NOT make a new
ShootingRound
for the expected answer in the assertEquals
. Such a test would fail, even if the two rounds had the same contents (again, for reasons we will explain in detail in week 2).
If you get a compilation error involving this file on a class or method that you defined, do not edit this file. Edit your files instead! As you are working, you may wish to comment out sections of the file that check methods you haven't written yet (that's fine). The final work you turn in should, however, compile against the entire contents of this file.
You are welcome to leave this file in the directory when you submit your work.
You can find the grading rubric for this assignment by clicking on this link. It will prompt you to download an Excel file.
Here are some details on what we will look for in grading this assignment:
Programs must compile in order to receive credit. If you submit a program that doesn't compile, the grader will notify you and give you one chance to resubmit within 24 hours; a penalty (25% of the total points for the assignment) will be applied as a resubmission penalty. Code that is commented out will not be graded.
Submit (via InstructAssist) a single zip file (not tar, rar, 7zip, etc) containing all of your .java files that contain your classes, interfaces, and examples for this assignment. Do not submit the .class files. You may put all of your other classes and interfaces either into a single file or into separate ones (as you prefer). If you have separate src and test subdirectories, you may retain that structure in your zip file.
Make sure all of your tests are in separate files from your code, as explained in the Expectations for Preparing Homework.