CIS 636 Spring 2005         Assignment 2 – Some Basic Calculations                                                                                     100 points

Assigned: 01/27/2005

Due: 02/03/2005 at the start of class 

 

You may work individually or in pairs for this assignment. But all work must be the work of the person/people whose name is on the code! If working in pairs, the individual contributions should be relatively equal. One possibility is to work together tonight, then finish separately (to avoid communication difficulties).

 

Main Assignment:

We are writing a program to help a driver keep track of their car expenses, focusing on gas costs.  Your program will interact with the user, asking for the number of gallons of gas purchased, the price per gallon paid for the gas, the odometer reading when the tank was full, and the odometer reading when refilling the tank.  For your variable types, choose the type that fits the possible values. Your program calculate the miles traveled, the amount of money spent, the miles per gallon, and the cost per mile driven, and will display all basic information including the calculated information.

  I would like your interaction with the user to be via dialog boxes, using static methods from RedmondMsgInBasic and RedmondMsgOut in my IO package. See the sample interaction below for a textual replay of what happened in one example.  

Hand in:

To avoid needless long waits, I recommend working on this on the c: drive or jump drive, then upon completion, copying it to the a: drive, testing it there, creating an extra backup for yourself.

Miscellaneous:

·         You can get any of my IO code you need from the assignment or review page of my WWW site.  It is written with a package statement that assumes that it is in a package of named IO.  Save it there.

·         You shouldn’t have to change anything in RedmondMsgInBasic and RedmondMsgOut. The recommended methods make some simplifying assumptions, since we haven’t covered exception handling yet. This means that some exceptions will result if the user tries hard enough. Until we cover exceptions, we won’t catch invalid values that are the wrong type (e.g. letters where numbers are needed)).  No biggie at this point.

·         In using the read valid methods in RedmondMsgInBasic, you automatically get validation.  The number of gallons of gas should be positive and no more than 25; the price per gallon should be positive and no more than $5.00;  the odometer reading at the start of the trip should be positive and no more than 1 million; the odometer reading at the end of the trip should be greater than the odometer reading at the start of the trip and no more than 1 million.

·         MAKE SURE YOUR PROGRAM WORKS! (i.e. more than just removing compile errors). Try more than the below example; convince yourself that it works.  Be a skeptic. 

·         Put YOUR NAME, and e-mail address and date in comments at the beginning of the program.

·         Also, comment any significant code to document it. 

·         Indent code following standard conventions (indent to show that something is “inside” or “part of” the preceding code (e.g. inside if’s or loops, or statements continued on a new line. This will not have much impact on this small program).  The IDE should handle this if you hit ENTER and move on to the next line (If you make changes, you may need to TAB to make things right).

·         Name your variables meaningfully, to describe their use in the program.

 

Textual Version of Interaction:

What is the odometer at the start of the trip?

79504

What is the odometer at the end of the trip?

79759

How many gallons of gas were purchased?

10.5

What price (per gallon) was paid for the gas?

1.369

Results:

      Start Reading:        79504

      End Reading:          79759

      Miles Traveled:         255

      Price:                    1.369

      Gallons:                 10.5

      Total Amount Paid:       14.37

      Miles Per Gallon:        24.3

      Cost Per Mile:            0.06