Navigation

Home

Weekly Schedule

TA Schedule

Prof Harris Schedule

General Policies

Resources

CodingBat, practice site

Tutorial directory

Lab directory

Programming Assignment 1

Software Requirements Specification

Which car?

Due Friday, September 23 by 5:00pm

Harcopy due in at start of class Monday 

 

Introduction

Purpose: This program is used to determine the 5 year cost of operating a car to determine whether or not purchasing a higher mileage car makes economic sense.

Objectives - At the conclusion of this exercise the student will demonstrate that they can:

Deadlines

Prerequisites

You have covered the material in Chapter 2 of Gaddis.  

Background

It can be tempting to purchase a car that gets better mileage than another with gas prices so high. But one has to look at the difference in original costs of the vehicles, their different resale price and the overall expected savings. While there are a lot of other variables in the operating cost of a car, we can write a program that will at least provide us a better way to analyze which might be the better value.

The five year cost is determined by the difference in the purchase price and expected selling price of the car in 5 years. To that we can add the cost in gas for the vehicle. The cost in gas is the price per gallon, the number of miles expected to be driven each year, and the mileage. We multiply that by the number of years and get the 5 year cost.

Example

Say I purchased a vehicle today that costs $25,000 and I expect it to depreciate by $5000 (so a sale price of $20,000) in 5 years. This vehicle gets 20 miles to the gallon and I drive 15000 miles per year. If we assume gas prices are $3.50/gallon, then the 5 year cost is:

$5000 depreciation + 15000 / 20 miles per gallon or 750 gallons of gas each year for 5 years or 3750 gallons of gas. At $3.50 a gallon, that amounts to $13,125 in gas. Added to depreciation of $5,000, the total cost would be $18,125.

Program Behavior

Your application must be named WhichCar.  

Your application must do these things:

  1. Your program must output a heading "Which car should you buy?" followed by a newline character.
  2. Your program must output a blank line.
  3. Your program must prompt for and then read in each of the values required. See the output section for the specific wording of the prompts.
  4. After you read in each new value, you must output a newline character.
  5. Your program must calculate the 5 year cost of the vehicle based on the input values.
  6. Your program must truncate the resulting amount to the nearest dollar and output the value as a integer value.
  7. Your program must output a blank line.
  8. Your program must output the results as shown in the output section.

Output

  1. For each output line, the quotes are just delimiters to separate the text from the surrounding text. You should not output the quotation marks.
  2. Output the heading, "Which car should you buy" followed by the newline character.
  3. Output a blank line.
  4. Prompt for the input values. Output the newline character after reading the each input value and before the next prompt. Note: your input will be on the same line as the prompt separated from the prompt by a space.
    1. Output "How much does your car cost? "
    2. Ouput "What kind of car is it? "
    3. Output "How much will it be worth in 5 years? "
    4. Output "What kind of mileage does it get? "
    5. Output "How many miles do you drive in a year? "
    6. Output "What is the cost per gallon of gas? "
  5. Output a blank line.
  6. Output the line "The total cost to own this cartype for numberOfYears years is $amount.
    1. cartype would be replaced by the kind of car
    2. numberOfYears would be replaced by the constant number of years
    3. amount is replaced by the total cost. Note that the cost must be preceded by a $ symbol and that the period following it is the sentence period and not part of the number.

Sample output

Notes

Which car should you buy?

How much does your car cost? 22000

What kind of car is it? Prius

How much will it be worth in 5 years? 20000

What kind of mileage does it get? 49.5

How many miles do you drive in a year? 10000

What is the cost per gallon of gas? 3.59

The total cost to own this Prius for 5 years is $5626.

Error handling

You will not need to perform any error handling.  

Additional Program Requirements

  1. You must use variables for the values of the input.
  2. You must use constants for the value of each of the number of years.
  3. In a separate document labelled EXAMPLES, you must provide same input and expected output for three test cases. You may use your group's example from class as one of the examples. This is worth 5 points.
  4. In a separate document labelled REFLECTION, you must provide a brief reflection of your performance on this program. See sample here: Reflection.doc. This is worth 5 points.
  5. Your program must conform to standard Java programming standards and the additional standards for this class. See the Style Guide for your class. This is worth 20 points.
  6. When you turn in your work, the submit report should be on top, then the examples document, then the reflection document. All parts should be stapled together.

Honor Code

This work must conform to the JMU Honor Code and the specific requirements of this class. NO help may be provided by any student to another student. Authorized help is limited to your textbook, the TAs for any CS139 or CS239 section, and the professor for your section. See collaboration policy.

Grading

        For submissions after:

HINTS


Updated 09/14/2011 - NLH