Docsity

Programming Assignment 8 - Problem Solving and Programming Concepts | CIS 120, Assignments of Computer Science

Toggle sidebar
bg1
Name:_____________________________ Section:______
CIS 120-101 Fall 2007
Programming Assignment 8
Due: Week 14 (Tue 11/20/07)
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.
* Your name must appear in the title bar of all output.
Taxi Service Cost per mile Initial Charge
Mello Cab $0.45 $2.50
Speedy $0.50 $1.85
A+ $0.55 $1.75
AllStar $0.85 $0.00
Step-on-it $0.52 $1.80
pf3
pf4
pf5

Partial preview of the text

Download Programming Assignment 8 - Problem Solving and Programming Concepts | CIS 120 and more Assignments Computer Science in PDF only on Docsity!

Name:_____________________________ Section:______

CIS 120-101 Fall 2007

Programming Assignment 8

Due: Week 14 (Tue 11/20/07)

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.

  • Your name must appear in the title bar of all output. Taxi Service Cost per mile Initial Charge Mello Cab $0.45 $2. Speedy $0.50 $1. A+ $0.55 $1. AllStar $0.85 $0. Step-on-it $0.52 $1.

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

CIS 120-101 Fall 2007

Programming Assignment 7 Cover Sheet Grade _______________

Name (Print): __________________________________________ Student #: _____________

Instructor: _____________________________________________ Section: _______________

Your program documentation should be labeled and organized according to the following:

DOCUMENTATION and DESIGN: 20% Paper copy and electronic copy are mandatory.

_____10 pt. Data Dictionary

All data and data types specified

Appropriate names chosen

Correct data types chosen

_____10 pt. Test Design (5%) and corresponding program output (5%)

Minimum of five documented test cases with screen captures of the

associated input/output for each case.

Displays correct input and output expected by program.

Output is clear and correct.

Your program should have proper global documentation (at the top). It should also have appropriate

internal documentation with code lines. See lab 1 programs for an example.

PROGRAM: 80% Paper and electronic copy of your source code submitted in a manila

envelope.

_____10 pt. Internal documentation and comments

_____10 pt. Style (indentation, spacing, blank lines, correct capitalization of identifiers

based on coding convention, etc.)

_____10 pt. Meaningful identifiers - matches data dictionary

_____50 pt. Correctness of program. Including: Program compiles, program runs,

produces correct output

Please note : additional points may be deducted if the package submitted does not contain all of

the required contents in an acceptable format.