Ask Question, Ask an Expert

+61-413 786 465

info@mywordsolution.com

Ask Java Expert


Home >> Java

Create an application named TravelCosts that is made up of a number of different classes.

Create an abstract superclass called Transportation that has the following three fields:
protected String routeName;
protected int distanceInMiles;
protected int passengerCapacity;
Your class must have a three argument constructor that initializes those three fields, and the class must also have the following getters and setters for those fields:
public String getRouteName()
public void setRouteName(String name)
public int getDistanceInMiles()
public void setDistanceInMiles(int distance)
public int getPassengerCapacity()
public void setPassengerCapacity(int capacity)
The setters for the distanceInMiles and the passengerCapacity must protect that data from getting negative values.
The Transportation class also has an abstract method called getFare() that takes no arguments and returns a double which represents the cost of the trip. Also create a toString() method that returns a String with the route name followed by the distance of the trip followed by the passenger capacity. All of this data must have proper labels and it must be on three separate lines.

Next create two child classes of the Transportation class called TaxiTrip and TrainTrip.

The TaxiTrip class has the following additional field:
protected double ratePerMile;
Create a four argument constructor for this class that sets this field as well as the fields of the superclass. Be sure to set the superclass fields with a call to super(), and remember that when you use a super() call it must be the first line of the constructor.
Also create a getter and a setter method for this field, and be sure the setter method protects the field from getting negative values.
For the TaxiTrip class you need to override the getFare() method such that it determines the fare by multiplying the distanceInMiles with the ratePerMile.
And you must create a toString() method that returns a String with the parent information using a call to super.toString() and then on a separate lineshow the cost of the trip formatted as a dollar amount to two decimals and include a proper label for that information.

The TrainTrip class has the following additional field:
protected int stopsInRoute;
Create a four argument constructor for this class that sets this field as well as the fields of the superclass. Be sure to set the superclass fields with a call to super(), and remember that when you use a super() call it must be the first line of the constructor.
Also create a getter and a setter method for this field, and be sure the setter method protects the field from getting negative values.
For the TrainTrip class you need to override the getFare() method such that the cost of a trip is determined by how far the trip is as well as by how many stops there are on the route. There is a base fare for the trip which is the value of 1/10th of the distance of the trip in dollars and cents. So, for example, if the trip is going to be 555 miles, then the cost will be 1/10th of that, or $55.50. However, the company wants to compensate passengers for too many stops on the route, and so the company subtracts 1/10th of the base fare for the first stop, and 1/100th of the base fare for the second stop, and so on, subtracting 1/10nth of the base fare for every nth stop. If there are no stops, then nothing is subtracted.
For example, if there are 3 stops for a 1000 mile trip, then the base fare is $100.00 and the total fare is:
Total Fare = $100.00 - (100.00 * 1/10) - (100.00 * 1/100) - (100.00 * 1/1000)
Total Fare = $100.00 - 10.00 - 1.00 - 0.10
Total Fare = $88.90
And you must create a toString() method that returns a String with the parent information using a call to super.toString() and then on a separate lineshow the cost of the trip formatted as a dollar amount to two decimals and include a proper label for that information.

Write a driver program called MakeTrip that has the main() method and that test the TaxiTrip and TrainTrip by creating two different Taxi trips and two different Train Trips and then prints them out.

Java, Programming

  • Category:- Java
  • Reference No.:- M92413492
  • Price:- $15

Priced at Now at $15, Verified Solution

Have any Question?


Related Questions in Java

Assignment - java program using array of objectsobjectives

Assignment - JAVA Program using array of objects Objectives - This assessment item relates to the course learning outcomes as stated in the Unit Profile. Details - For this assignment, you are required to develop a Menu ...

Project descriptionwrite a java program to traverse a

Project Description: Write a java program to traverse a directory structure (DirWalker.java) of csv files that contain csv files with customer info. A simple sample in provided in with the sample code but you MUST will r ...

Assessment socket programmingtaskwrite a java gui program

Assessment: Socket Programming Task Write a JAVA GUI program that would facilitate text chatting/exchanging between two or multiple computers over the network/internet, using the concept of JAVA socket programming. If yo ...

Fundamentals of operating systems and java

Fundamentals of Operating Systems and Java Programming Purpose of the assessment (with ULO Mapping) This assignment assesses the following Unit Learning Outcomes; students should be able to demonstrate their achievements ...

Question slideshows or carousels are very popular in

Question : Slideshows (or carousels) are very popular in websites. They allow web developers to display news or images on the website in limited space. In this code challenge, you are required to complete the JavaScript ...

Assessment socket programmingtaskwrite a java gui program

Assessment: Socket Programming Task Write a JAVA GUI program that would facilitate text chatting/exchanging between two or multiple computers over the network/internet, using the concept of JAVA socket programming. If yo ...

Assignment taskwrite a java console application that allows

Assignment task Write a java console application that allows the user to read, validate, store, display, sort and search data such as flight departure city (String), flight number (integer), flight distance (integer), fl ...

Can someone help me please with those question1what is the

Can someone help me please with those question 1:what is the best data type for student id datatime,currency,number,decimal 2:which relationshipis preferable? one to one,one to many,many to many 3:if you add table A's pr ...

Assignment - method in our madnessthe emphasis for this

Assignment - "Method in our Madness" The emphasis for this assignment is methods with parameters. In preparation for this assignment, create a folder called Assign_3 for the DrJava projects for the assignment. A Cityscap ...

Assignment taskwrite a java console application that allows

Assignment task Write a java console application that allows the user to read, validate, store, display, sort and search data such as flight departure city (String), flight number (integer), flight distance (integer), fl ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As