Question: The NetBeans software and requires no QUI. This lab uses a series of classes that compare the cost of travel by plane, train and auto

The NetBeans software and requires no QUI.

This lab uses a series of classes that compare the cost of travel by plane, train and auto from Rochester to some other destination. An interface is required and input is received through command line arguments.

Exercise 1 The cost of car travel

Step 1:

Creating the interface - Create an interface, TravelCost, that has the following characteristics: A constant double AGENT_FEE value in US dollars ($s) of 10.00 An abstract method getDuration that returns a double trip length in hrs An abstract method getTotalCost that returns a double trip cost in $s

An abstract method getLodgingCost that returns a double lodging cost in $s An abstract method getDestination that returns a String destination An abstract method toString that returns a string formatted by String.format()

Step 2:

Create a class, CarTravelCost, with the characteristics:

Attributes are trip distance int numMiles, nightly lodging cost double hotelCost and trip destination String destination A normal accessor for destination A constructor that accepts and updates all the instance variables getDestination returns: numHours=(double)numMiles/65, (uses car speed of 65 mph) The getLodgingCost() returns: numDays*hotelCost. numDays, which is the number of days on the road, is calculated getDuration()/8.0 (8 hours of driving per day). There is no need to include fractional days as a whole day (why?); the method Math.floor() method will help. getTotalCost() returns: (numMiles * 0.45) + getLodgingCost() + AGENT_FEE A toString method returns: destination, getDuration() and getTotalCost() formatted by String.format()

Step 3:

Create a test class , TestCarTravelCost, that takes in three command line arguments: number of miles, hotel cost per night and destination. Issue an error message if there are not three arguments: ERROR: Invalid number of command line arguments. All data conversions should be done in the test class (e.g. String to double). If there is a valid number of arguments then:

Instantiate an object of the CarTravelCost class using the three arguments

Print out the toString

Sample Output

Janeway:Lab12_Interfaces Key jim$ java TestCarTravelCost 400 Boston

ERROR: Invalid number of command line arguments

Janeway:Lab12_Interfaces Key jim$ java TestCarTravelCost 400 200 Boston

Car travel to Boston will take 6.15 hours and cost $190.00.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!