Project 3 UberJava Solved

50.00 $

Click Category Button to View Your Next Assignment | Homework

You'll get a download link with a: . zip solution files instantly, after Payment


5/5 - (3 votes)

PURPOSE: Learn more designing multiple classes, packages, accessing a Web site, parsing Strings, creating your own Exception, and being an UberJava driver. Do all your work in the Github repository available via the link (

(There is one package location that you’ll need from there)

In this assignment, you are to pretend that you, James Naismith and Prateek are all Uber Drivers!  Each of you get fares and drive people to their destination (all around California). You must keep track of all the trips that you take, how much money that you make, and your rating.

Here is how UberJavaDriver works:

  1. You instantiate all three Drivers – you, James Naismith, and Prateek – each with their name and a Car

Note: We’ll talk about in class how you access a Web page – it is pretty much like reading a file.

Sometimes Surge Pricing and sometimes Double Surge Pricing is in effect.  In those cases, you get bigger fares. The above fare line will be followed with a line that looks like this:




  1. In order to figure out your costs you should get the information that is available at the provided link.<rideNumber> where the rideNumber is what was provided in the nextFare request.

For example, for ride number 1502587145, the return is






TO ALSO get the miles and distance from your current location, add the following to the end of the request: &start=

<startLocationName> , Make sure to replace any space in the location name with a “+” so for instance, (

This will return at the end of the reply with a line like

Note: From Los Angeles to San Francisco will be 209 miles and take 378 minutes

There you get the distance, time it takes (Note that because of a special deal with the California Highway Patrol, Uberjava drivers are not assessed tolls when driving from their start location to the beginning of a fare).  This information is also in fixed format.

If you enter a bad location the reply will be simply

ERROR: Invalid start location

Note: You cannot specify the start location IF it is the same as the fare from location. You’ll get an error return: ERROR: Start location cannot be specified if same as from location

  1. All drivers must accept all fares that they are able to get to (depending on their current location) within 300 minutes or less. If a fare is not accepted, then you must make the call to UberJava<rideNumber>

(<rideNumber>) to let the “dispatcher” know

The reply will look something like this:


RideNumber: 1502587145

Reject acknowledged

  1. When you complete the ride, let UberJava know (so that you can be paid); AND so you can learn what your rating is. Do this by going to the site:<rideNumber> where the rideNumber is what was provided in the nextFare request.

There in graphical format you get your rating for the ride from 1 to 5 stars. For example,

Note:  All riders are famous USF graduates, so please treat them with respect when they ride in your car!  Plus, that way you’ll get a good rating!

Note: As famous USF graduates, they can magically take multiple rides at the same time and they can randomly appear in locations instantaneously.

Locations: The only locations for starting OR that rides on UberJava are as follows:

Death Valley


Los Angeles



San Bernadino

San Diego

San Francisco

San Jose Yosemite

All drivers must start in San Francisco.

Types of Drivers: Drivers may or may not be UberJavaX Premium Drivers.  However, only James Naismith and Prateek are UberJavaX Premium drivers, everyone else is a regular Driver.  As Premium Drivers, James and Prateek drive more expensive cars that use more gas and they have to pay for extra amenities that they give their riders – like water & snacks. They get paid a higher fare than Regular UberJava drivers. The cost of their amenities is listed on the distance.cgi page, as follows:

Amenities (Water, snacks, etc.): $27.57

Cars: Your car can be any make and year and get between 15 and 50 miles per gallon. Every car has operating cost (maintenance plus insurance) per year equal to 20% of the initial price of the car (So a car that costs $62,000 will have an operating cost of $169.86 per 24-hour period) The Premium drivers have the following cars:

Prateek drives a 2019 Tesla Roadster that cost $219,800.

James drives a 2018 Porsche 911 Turbo S Cabriole that cost $200,400

Prateek gets 102 miles per gallon (in equivalent electrical cost); James gets 11.5 miles per gallon.

Your car can be any make and year and gets between 15 and 50 miles per gallon and costs at least $40,000 (we’re a high-end operation here at UberJava! Note your car – even if electric – cannot get more than 50 miles per gallon otherwise you cannot drive for UberJava!


Every UberJava Driver has the following costs

Cost of vehicle ownership – assume that each car was got on a 3-year loan at 7% per year for the entire purchase cost. Look on

( off-line to see what the monthly cost of the loan divide that by (30 * 24) and use that as the value of the cost for an hour of use. Use this to compute the ownership cost for the time of use in UberJava.

Operating costs for your vehicle for the time of use in UberJava

Tolls – if any

Cost per mile for gasoline

Amenities (for UberJavaX Premium Drivers)


  1. You should write a main driver class called UberJavaMain in which you instantiate the three drivers (you, Prateek and James Naismith); and then have them accept and handle fares
  2. All Drivers (with their Cars) start in San Francisco AND they must keep driving for a “Session” of at least 24 hours (of recorded driving time) AND until their last fare ends in San Francisco. Note this may entail driving for significantly more than 24 hours.
  3. When your last Driver ends, the main method should print for each driver the following information:

Driver name and whether they are UberJavaX Premium Number of fares they had

Total fares, total miles driven, and total hours/minutes word Total amount the driver earned.

Total cost of operation (with a breakdown by type of cost)

Average Rider Rating

Effective Hourly Earnings after all costs are deducted.

  1. Also, at the end, print the record for each Rider as follows:

Total number of fares they had in total and per Driver

Total amount they paid UberJava

Total minutes that they spent on UberJava rides


  1. You can practice any of the calls to UberJava in an ordinary browser by just typing in the request in the address bar. Try it now!

( (Note Abner Doubleday is widely considered the inventer of baseball)

  1. All your drivers and interaction with the UberJava web pages should be in a package called uberjava.
  2. Drivers may or may not be UberJavaX Premium (only James Naismith and Prateek are the latter). This should be set when you instantiate a Driver.
  3. The Driver class should support the following methods int startSession() throws IllegalStateException – this will start a new UberJava session. Statistics should be kept for a session in an UberStatistics class object.  This call returns a sessionNumber particular to the driver. This will throw an IllegalStateException if there is already a started session that has not yet ended.

int endSession() throws IllegalStateException – this will end the current session; returns the ended session’s sessionNumber. This throws IllegalStateException if there is no current session.

UberStatistics getSessionStatistics(int sessionNumber) returns the statistics for the specified session or null if session does not exist

UberStatistics getSessionStatistics() returns the statistics for the current session (if it exists) or last session that ended else null

Location getCurrentLocation() returns the current location of the Driver

Int getSessionMinutes() throws IllegalStateException returns the total minutes since the start of the currentSession; throws IllegalStateException if there is no current session.

  1. The Car class should extend from Vehicle. Both Car and Vehicle should be in a package called vehicle.
  2. Vehicle class:

The vehicle class maintains position of a vehicle

Should be declared abstract (you can instantiate a Car or other subclasses, but not Vehicle) Should have a currentLocation that indicates where the vehicle currently is.

The Constructor of Vehicle should be passed a start location.

boolean driveTo(Location newLocation) method should take a Location object as a parameter. (This is how a Vehicle moves). The method returns true if the Vehicle (Car) is moved false otherwise.

  1. The Car class (which extends from Vehicle) should also include the following:

Include two Constructors

  1. Car(String name, int year, String make) – sets Location to San Francisco
  2. Car(String name, int year, String make, Location location) – sets Location to specified Location name (for instance, “Prateek’s Car”) instance variable getName() call parked boolean indicating whether or not the car is parked.

boolean isParked() to indicate if car is parked void park() to park the car the vehicle driveTo call should be overridden to first set parked to false before calling the super method. Keep track of all the cars that are created

static Car[] getCars – static method to get an array of all the cars

Keep track of operating cost of the car by including the following:

  1. purchaseCost – the amount spent to initially buy the Car. Set to a null value in the Constructor and add a setter and getter for this. The getter should throw a ValueUndefinedException (see below) if called before the value has been set.
  2. milesPerGallon – how many miles the Car can travel on a gallon of gas. Again, set to a null value in the Constructor, and add a setter and getter for this. The getter should throw a ValueUndefinedException (see below) if called before the value has been set.
  1. After driving somewhere, you must park the Car before driving it again. (driveTo should return false IF the car is not parked when the method is called otherwise it works just like the vehicle driveTo method).
  2. A package called location is provided for you (because it includes “latitude” and “longitude” that can be used to hook this into a graphical user interface). It has one class called Location, that has a private constructor and statically creates an array of all ten locations that are available. Do not alter this class. Location include a getName() method that returns the Location name (e.g., “San Francisco”) and overrides toString. It also Includes the following static methods:

Location getByName(String name) – returns the Location with that name or null

Location[] getLocations() – returns an array of all available locations

  1. Create a package called exception. Include at least one class called ValueNotSetException that extends RuntimeException. Make sure to include at least one Constructor that is passed a message parameter. 11. Make all instance variables private; provide getters and setters where appropriate Make sure to override toString for almost every class that you create.
  2. Remember you have to drive from where ever you are to where your next Rider is and THAT takes time (included in your 24 hour++ session) and has gas and operating costs.
  3. Values returned in Web calls to UberJava: rideNumber is 10 characters long and consists of numbers and capital letters “[A-Z0-9]” Fares are in dollars and cents

Distance is in integer miles

Toll is integer dollars

Minutes are an integer

For the rating there are up to five stars – either “golden-star.jpg” or “blank-star.png” – count the goldenstar occurrences for the rating.


After you have  pushed to github, please submit here on Canvas a statement that you have made your commit (This is how we’ll know it’s done!)  INCLUDE YOUR github user name in that statement.

Academic Honesty

Please do all your work individually unless otherwise specified. Do not look at anybody else’s code or solutions. You may discuss high level concepts and seek help from the TA or professor. Any outside sources used for help must be noted.


Create exception class ValueUndefinedException (or ValueNotSetException) and throw it from getInitialCost and getMilesPerGallon  – 10 points

Implement a method that gets pages from the Web – 10 points

Implement a “parser” for each of the three calls – nextFare, distance, rating – 5 points each * 3 = 15 points

Implement Car & Vehicle classes 10 points each * 2 = 20 points

Implement Driver class – 15 points

Instantiate 3 different drivers (James Naismith, Prateek, and themselves) – 5 points

Run a session (>= 24 hours ending in San Francisco) for all 3 Drivers; maintain statistics for rides; demonstrated with a printout or clear within code – 15 points

Implemented sequence of events for a ride (Steps 4-7 under the explanation of how UberJava works: get nextFare; get  distance info; (optionally reject if too far); driveTo from wherever you are to the start of the ride (if necessary);  driveTo to the “to” location of the Ride; get rating  – 10 points

Total    100 points

Bonus Points Available

Maintain encapsulation by making instance variables private and implementing getters and setters throughout classes – 5 points

Created additional main methods in Driver and other classes in order to test code – 5 points