



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!




Problem Description: Design and implement a Java class called “Taxi”. This “Taxi” class will be able to construct Taxi objects based on the taxi service name, cost per mile, and initial charge. This class must also have operations that do the following: calculate the total fare provided a distance (fractional miles allowed); search for a taxi service and display the service name and fare information or display that the service was not found when provided a name; search for the cheapest fare provided a distance and then display the total fare and related service/rate information. Design and implement a Java application called “Program8” that will use the “Taxi” class. This application will ask the user if they would like to search for a taxi company by name. The output will be as described above and as illustrated in the example output. The user must be given the opportunity to perform another search as long as desired. The user will then be asked to provide a distance and the cheapest fare information will be outputted as described above and illustrated in the example output. Error Checking: You must check for cancel being clicked when the dialog box for performing a cheapest fare search is displayed. If cancel is clicked, you must notify the user and exit the program. You may assume that if a value is provided for distance that it will be valid. Coding Requirements Taxi.java You must override the toString() method (an instance method). The toString method will just return a String that is the name of the taxi service, the cost per mile and the initial charge (see sample output). You must also implement a flaot-returning instance method called findFare that will return the taxi-fare of that taxi service for a given (float) number of miles. This instance method will take the number of miles as its formal parameter and returns the float that represents the total fare for driving that number of miles (i.e. initial charge + miles * cost per mile). Program8.java The Taxi objects must be created in this application based on the attributes listed in the table above. Use a class method in Program8 to create and fill an array of 5 Taxis (called this class method fillTaxiArray – you will pass it an allocated array of size 5). The main body of Program8 will also (after asking user for the name of a Taxi Service) call a Taxi-returning method that returns a reference to the Taxi with the specified name or returns null if the name given by the user is not among the names of the Taxis in the array. Call this class method findTaxi (it will have as its arguments: an array of 5 Taxis and a String – i.e. the name of the Taxi we are seeking). After finding (or not) the desired Taxi, your main in Program8 will display that data [using the toString method in the Taxi class] or will display a message saying that the desired Taxi service was not found. Your Program8 main will also use another Program8 class method called findTaxiWithBestRate. This method will return a Taxi (actually an object reference to one…) to the Taxi with the best rate for a specified number of miles. This method will take the array of 5 taxis and the miles to travel as its two formal parameters.
Hints: The String class provides a method called EqualsIgnoreCase(String) that performs string comparison and returns a boolean value based on the comparison. Example: String input = “Hello”; input.equalsIgnoreCase(“hello”); // This would return true input.equalsIgnoreCase(“heilo”); // This would return false Filename Requirements: Your program must be saved to files Program8.java and Taxi.java. You must submit a printed and electronic (CD or Floppy) copy of your commented program along with a printed copy of your completed data dictionary, completed test design table, gradesheet, and screen captures of the input and output for all test runs in a manila envelope. Data Dictionary (You may add additional lines) Variable Name Type Usage Test Design Test Case Name Searched Output Distance Output 1 2
User clicks Yes Input (Cancel Selected) Associated Output