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:
- Input data from a keyboard.
- Use Java math operations
- Properly format output to specification
- Do everything necessary to create, debug, and run a java program.
- Use comments to delineate each section of the program.
- Adhere to a Style Guide.
- READ AND FOLLOW DIRECTIONS!!!!!
Deadlines
- Submit: September 23, 2011 by 5:00pm.
- Report: September 26, 2010 at the beginning of class. A 10 point late penalty will apply for each of the 2 deadlines. If the submit is late, the report is due the next class or lab session day after successful submission. Programs will not be accepted after 7 days late.
- NOTE: There is no penalty for multiple submissions.
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:
- Your program must output a heading "Which car should you buy?" followed by a newline character.
- Your program must output a blank line.
- 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.
- After you read in each new value, you must output a newline character.
- Your program must calculate the 5 year cost of the vehicle based on the input values.
- Your program must truncate the resulting amount to the nearest dollar and output the value as a integer value.
- Your program must output a blank line.
- Your program must output the results as shown in the output section.
Output
- For each output line, the quotes are just delimiters to separate the text from the surrounding text. You should not output the quotation marks.
- Output the heading, "Which car should you buy" followed by the newline character.
- Output a blank line.
- 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.
- Output "How much does your car cost? "
- Ouput "What kind of car is it? "
- Output "How much will it be worth in 5 years? "
- Output "What kind of mileage does it get? "
- Output "How many miles do you drive in a year? "
- Output "What is the cost per gallon of gas? "
- Output a blank line.
- Output the line "The total cost to own this cartype for numberOfYears years is $amount.
- cartype would be replaced by the kind of car
- numberOfYears would be replaced by the constant number of years
- 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
-
There is a blank space between each question mark and where the user begins to type data.
-
There is no blank space after the first ? after buy.
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
- You must use variables for the values of the input.
- You must use constants for the value of each of the number of years.
- 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.
- 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.
- 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.
- 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
- Your program will be evaluated both by its correctness and conformance to the required elements.
- You will achieve a grade of
70 for a program that runs correctly
and produces exactly the required output in the required format. (It passes submit tests.)
- Documented examples - 5 points.
- Reflection document - 5 points.
- The remainder (20 points) will be based on your conformance to the Style and other requirements of the assignment. Review the Style Guide before submitting your program and the grade sheet which is produced by the submit system.
- All grades will be based on 100 points.
- You may submit any number of times. The only one I will count is the one that corresponds to the hardcopy report that you turn in.
- The hardcopy that you turn in will be the formatted version that I will check. Make sure it has no line wraps or other spacing issues.
- Successfully submitted programs that are late will be graded, then the late penalty is assessed for each day late according to the following schedule.
- Sept 23 - 5 points
- Sept 25 - 15 points
- Sept 26 - 25 points
- Sept 27 - 35 points
- Sept 28 - 45 points
- Sept 29 - 100 points
HINTS
- Begin early. Students run into trouble by waiting too long to start the program.
- Understand the problem at hand. Create your examples FIRST.
- Break the problem up into small segments. Compile and test (as appropriate) each segment.
- In the body of your main method, outline your steps with comment lines for each part of the project.
- Create your variables.
- Assign to them the literal values from your first example.
- Create the calculation to calculate the cost and print that out. Don't worry about formatting.
- Create the correct welcome and result line with the formatting for the cost.
- Add in (perhaps one at a time) the prompt and input for each variable.
- Finally, test your program with each of your examples.
- Make sure that you follow the requirements precisely. Don't add additional "flourishes". You will be downgraded or at the very least may have more submissions than you should.
Updated 09/14/2011 - NLH