Question
CompSci 251: Assignment 4 JAVA Due 2/27, 2017 10:00am Topics Covered: Writing classes; References; Equality 1 Introduction B.O.S.S. is a non-emergency service designed to provide
CompSci 251: Assignment 4 JAVA
Due 2/27, 2017 10:00am
Topics Covered: Writing classes; References; Equality
1 Introduction
B.O.S.S. is a non-emergency service designed to provide a safe ride around the UW-Milwaukee campus. B.O.S.S. runs seven days a week when school is in session and there is no cost at the point of use for currently enrolled UWM students.
2 What you will do
For this assignment you will write a BossRoadTrip class and a driver class called BossRoadTripDriver. A BossRoadTrip object represents a trip that someone might take between two locations over couple of minutes.
Here is the UML diagram for the BossRoadTrip class:
BossRoadTrip |
- start: String - destination: String - minutes: int // at least 1 |
+ BossRoadTrip(start: String, destination: String) // minutes = 1, must call other constructor + BossRoadTrip(start: String, destination: String, mins: int) + getStart() : String + getDestination() : String + getMinutes() : int + lengthen(mins: int) : void // adds additional minutes to trip, mins supposed to be positive, if not do not add + shorten(mins: int):boolean //reduces minutes of trip, returns true if successful, false otherwise. //mins supposed to be negative, if not don not update the minutes instance variable. //if mins that will be taken from the trip will make minutes + equals(other: Object) : boolean // true if all instance variables are equal + toString() : String // used to print trip data. Notice that it prints minute or minutes |
The UML diagram for the BossRoadTripDriver class shown below.
You must implement these classes the way that we specify. (Note: The comments in the UML class diagrams are not a standard part of UML. It just happens to be a convenient place to document some of how the methods should work.)
The BossRoadTripDriver combine() method needs a bit of explanation. It takes two BossRoadTrip objects as parameters and returns the combination of the two. This only makes sense if the destination of the first BossRoadTrip is the start of the second BossRoadTrip. When this is the case, the method returns a
1
BossRoadTripDriver |
+ static main(String[] args) : void + static combine(first: BossRoadTrip, second:BossRoadTrip) : BossRoadTrip // returns a new BossRoadTrip that combines first and second // if trips cant be combined, return value is null +static createRoadTrip(Scanner stdIn, int tripNumber):BossRoadTrip //prompts the user for a series of values to define a new BossRoadTrip object; then //return the object created +static modifyTripLength(stdIn: Scanner, tripNumber: int, trip: BossRoadTrip): void //prompts the user for an integer to modify the trips minutes variable; if the //user provides an integer >0, it calls the lengthen method on trip object, //and if |
new BossRoadTrip whose start comes from first and destination comes from second and whose minutes are the sum of minutes from first and second.
When the two trips dont match correctly, you signal this fact by returning a null reference. (There are better ways to handle this, but we havent covered the techniques yet.) You need to remember that the null value represents an undefined object. So, if try to call a method using null, your program will crash. This means that your main() method will have to check the return value of combine() to see whether it is null. Your driver program will ask the user to enter two BossRoadTrips. Then, it will ask if the user wants to adjust their trip duration(minutes). It will then compare for equality and try to combine them.
3 Sample Runs
Welcome to the B.O.S.S RoadTrip Program
Enter start of B.O.S.S RoadTrip 1: Union Enter destination of B.O.S.S RoadTrip 1: 2000 Frederick ave Enter minutes for the B.O.S.S RoadTrip 1: 5
Enter start of B.O.S.S RoadTrip 2: 2000 Frederick ave Enter destination of B.O.S.S RoadTrip 2: Brady Street Enter minutes for the B.O.S.S RoadTrip 2: 10
B.O.S.S RoadTrip 1: (Union to 2000 Frederick ave, 5 minutes) B.O.S.S RoadTrip 2: (2000 Frederick ave to Brady Street, 10 minutes)
Adjust length of B.O.S.S RoadTrip 1 (zero for no change): 0 Adjust length of B.O.S.S RoadTrip 2 (zero for no change): 0
B.O.S.S RoadTrip 1: (Union to 2000 Frederick ave, 5 minutes) B.O.S.S RoadTrip 2: (2000 Frederick ave to Brady Street, 10 minutes)
The B.O.S.S RoadTrips are not equals. The two B.O.S.S RoadTrips can be combined. The new B.O.S.S RoadTrip is: (Union to Brady Street, 15 minutes)
Goodbye!
2
Welcome to the B.O.S.S RoadTrip Program
Enter start of B.O.S.S RoadTrip 1: Union Enter destination of B.O.S.S RoadTrip 1: Walmart Enter minutes for the B.O.S.S RoadTrip 1: 10
Enter start of B.O.S.S RoadTrip 2: Union Enter destination of B.O.S.S RoadTrip 2: Walmart Enter minutes for the B.O.S.S RoadTrip 2: 10
B.O.S.S RoadTrip 1: (Union to Walmart, 10 minutes) B.O.S.S RoadTrip 2: (Union to Walmart, 10 minutes)
Adjust length of B.O.S.S RoadTrip 1 (zero for no change): 0 Adjust length of B.O.S.S RoadTrip 2 (zero for no change): 0
B.O.S.S RoadTrip 1: (Union to Walmart, 10 minutes) B.O.S.S RoadTrip 2: (Union to Walmart, 10 minutes)
The B.O.S.S RoadTrips are equals. The two B.O.S.S RoadTrips cannot be combined.
Goodbye!
Welcome to the B.O.S.S RoadTrip Program
Enter start of B.O.S.S RoadTrip 1: Union Enter destination of B.O.S.S RoadTrip 1: Walgreens Enter minutes for the B.O.S.S RoadTrip 1: 5
Enter start of B.O.S.S RoadTrip 2: PicknSave Enter destination of B.O.S.S RoadTrip 2: Union Enter minutes for the B.O.S.S RoadTrip 2: 10
B.O.S.S RoadTrip 1: (Union to Walgreens, 5 minutes) B.O.S.S RoadTrip 2: (PicknSave to Union, 10 minutes)
Adjust length of B.O.S.S RoadTrip 1 (zero for no change): 2 Adjust length of B.O.S.S RoadTrip 2 (zero for no change): 6
B.O.S.S RoadTrip 1: (Union to Walgreens, 7 minutes) B.O.S.S RoadTrip 2: (PicknSave to Union, 16 minutes)
The B.O.S.S RoadTrips are not equals. The two B.O.S.S RoadTrips cannot be combined.
Goodbye!
Template:
1 package CS251. edu; 2 import java util Scanner 4 public class BossRoadTripsDriver Drives the program and handles input and output to the console @param args 10 11 public static void mainCString C args) Scanner stdIn new Scanne System i 12 System. out printlnC"Welcome to the B.0.S.S RoadTrip Program n'); 14 15 TODO 16 17 System.out printlnC"VnGoodbye!"); 18 19 20 21e Attempts to combine two BOSS road trips 22 23 param first 24 param second 25 @return A BOSS road trip object with the start of the first trip and the 26 destination of the second if they can combined Returns null if the road trips cannot 27 be combined. 28 29 30e public static Boss RoadTri p combine CBossRoadTrip first p second) //TODO 32 33 35 36 createRoadTrip prompts the user for a series of values to define a new 37 Road Trip object 38 39e public static Boss RoadTri p createRoadTripCScanner stdIn, int tri pNumbe TODO 40 41 end createRoadTrip 42 43 44 45 46e modify TripLength prompts for an integer to modify the trip's minutes variable if 0, it runs the lengthen method 47 and if not it runs the shorten method 48 49 50e public static void mod ifyTripL. stdIn, int tripNumber, BossRoadTrip trip pLengthCScanne 51 TODO 52 53 54 1// end modify TripLength 55 56 57Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started