Travel costs java application

Assignment Help Basic Computer Science
Reference no: EM131204496

Travel Costs Java Application

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 line show 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 line show 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.

Reference no: EM131204496

Questions Cloud

What is triple encryption : What is triple encryption? Why is the middle portion of 3DES a decryption rather than an encryption?
How large is the deadweight loss from the externality : There is a large number of commuters who decide to use either their car or the tube. Commuting by train takes 70 minutes whatever the number of commuters taking the train. Commuting by car takes C(x) = 20 + 60x minutes, where x is the proportion o..
Methods of attacking the pwc : Suggest some methods of attacking the PWC worm defense that could be used by worm creators and suggest countermeasures to these methods.
Find the probability that the average number of calories : Find the probability that the average number of calories in a box of six randomly selected croissants from the Flaky Bakery is more than 310 calories.
Travel costs java application : 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:
Why statistical data used by criminal justice leadership : Write paper discussing how and why statistical data should be used by criminal justice leadership.-Statistical support to criminal justice policy making.
Discuss two key concepts that you felt were most impactful : Discuss at least two key concepts that you felt were most impactful to you this term and the manner in which you might use these concepts in the future.
Why is it useful to have host-based firewalls : Why is it useful to have host-based firewalls? What is a DMZ network and what types of systems would you expect to find on such networks?
Develop a a learning outcome you would like to measure : Develop a a learning outcome you would like to measure. Use a specific content area. Then develop three test items: using the format in Appendix D of the Text.

Reviews

Write a Review

Basic Computer Science Questions & Answers

  How many pages are needed to store the entire job

How many pages are needed to store the entire job?

  The use of borrowed material and utilize original ideas

The paper should be in the range of 1200 - 1500 words with double spacing. It is very important to include proper APA citation (in-text citations with quotation marks and source information, plus a reference list). Please minimize the use of bo..

  Raise money for the event

Every runner is required to solicit sponsors to help raise money for the event. There are two types of sponsors - corporate and personal.Design a second table that will store data about the sponsors for each runner.1.Make a list of the field names an..

  How to convert a string of binary into decimal

how to convert a string of binary into decimal and a decimal into binary using java

  Research the key terms

Research the key terms

  Develop a mobile application for a restaurant

This is a work that has already previously done by the experts, but not completed due to insufficient funds. I would like them to finish off the work that has been set before. Please follow the checklist!. The other files uploaded are the files yo..

  Conduct an internet search for the oecd

The Organisation for Economic Co-operation and Development (OECD) has created a list of principles to aid organizations in dealing with people and organizations in different countries with different cultures.

  Find syntax errors the definitions of the following classes

Find the syntax errors in the definitions of the following classes. a. class AA { public: void print() const ; int sum(); AA(); int AA(int, int); private: int x; int y; }; b. class BB { int one; int two; public: ..

  Write dimensions of memory containing bytes of storage

Write down the dimensions of a memory containing 1mb(2^20) bytes of storage? How large would the MAR be? how many bits are sent to the row column decoders?

  Give an algorithm to record global state

Consider a distributed system where every node has its physical clock and all physical clocks are perfectly synchronized.

  All disk drives in a particular batch are the same model

All disk drives of a certain model of a particular manufacturer have exactly the same capacity.

  What is the downward closure property

How does it aid in developing an efficient algorithm for finding association rules, that is, with regard to finding large item sets?

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd