RU beehive logo ITEC dept promo banner
ITEC 120
2019fall
asbrennem
ibarland

if-else, and helper functions
Train Schedules

Your assignment is to complete the »Train Ticket« program, with a few modified requirements. Turn in a hard copy, and attach your TrainTicket.java to the D2L, hw02-dropbox. Due Sep.16 (Mon)18 (Wed) 10:00.

After reading over the instructions on that link above, our assignment will be the same essence, just converting I/O to test-cases (and, specifying the exact names of functions you should have).

  1. To do this, we'll have an overall function named fareMsg which:
  2. You must have a (helper) function called fare which will be called with the same three arguments as fareMsg; it will return the cost of the trip, in dollars.
    E.g. fare(3,1,13) might return 1.6,
    while fare(2,6,18) might return 5.2.
  3. You must have a (helper) function stationName, which takes in a valid station-number, and returns that station's name.
    E.g. stationName(5) might return "Misty Market"
  4. You may certainly use other helper-functions, if you like. My own solution happened to include a helper which took in to station-numbers and returned a boolean.
  5. For each function above, you must also have a test-function. (Write each of these before you write the corresponding function-being-tested.)
    1. testStationName must have two tests.
    2. testFare must test the following sorts of trips:
      • each of the two samples given on your sheet;
      • A trip just like some other test-case but with swapped beginning/ending stations (hence it has the same fare);
      • at least one trip crossing the river;
      • at least one trip not crossing the river;
      • a trip only 1 stop long;
      • a trip 0 stops long.
      (Note that one test might be able to satisfy several of the conditions above; you might be able to get by with as few as five tests. Myself, I had eight different tests before I thought I was reasonably covering all cases, though.)
    3. testFareMsg should test the same inputs that testFare does.
    4. Include a function testAll which calls the other three test-functions.
    5. Purely optional (but it makes your life easier): Use assertEquals for your test-cases.
      (It was added to Object120.java1 on Sep.13 (Fri) noon).
  6. Recommendation: First write tests for stationName followed by stationName. Only then, start writing fare's tests and code, and only do fareMsg's tests and code last.
  7. Use other helper functions as appropriate; also include tests for them.
  8. You may assume a function's inputs are always valid numbers.
  9. Make sure that each of your (non-test) functions have a short @return javadoc-comment (that is, inside /** */ immediately preceding your function).
  10. Just to be clear: We will not prompt the user for stations or the time. Don't use any input (such as class Scanner), and there should be no printlns outside of a test-function.
  11. Formatting numbers: When including numbers in the fareMsg, for full credit, make sure
    1. the price has exactly two decimal places;
      hint: String.format("%.3f",23.14159) returns "23.142"
    2. the hour (right before the ":00", is exactly two-digits long, padded with a leading-zero as needed.
      hint: String.format("%02d",4) returns "04"
    However, if your actual-results aren't formatted quite right, you'll still get nearly all the points. But your desired-results definitely should meet this requirement. Of course, your answers should be correct (at least to within $0.0000001 :-).
  12. Look over Ms. Brenneman's HW3gradingWorksheet.pdf, but do not turn it in (since we'll have a slightly different grading rubric, allocating points to helper-functions and unit tests).
  13. Be sure to use the exact file and function-names given here; part of this homework may be auto-graded, and having the wrong name will mean the auto-grader gives you 0 for that section.


1 Recall: Right-click on the file to download it, and BlueJ Edit » Add Class from File… (from the project-view). And, make sure your class TrainTicket extends Object120 { }.      

logo for creative commons by-attribution license
This page licensed CC-BY 4.0 Ian Barland
Page last generated
Please mail any suggestions
(incl. typos, broken links)
to ibarlandradford.edu
Rendered by Racket.