Objectives

Using a Scanner to read input. Working with variables and expressions.

Fuel cost and CO2 pollution comparison

You are going to write a program to perform a fuel cost and CO2 pollution comparison of a gasoline car versus an electric car.  Your program should be organized into six sections:

  1. Input values for gas car
  2. Gas car calculations
  3. Print analysis for gas car
  4. Input values for electric car
  5. Electric car calculations
  6. Print analysis for electric car and savings analysis

An example run of your program, using realistic values, should look like this:

How many miles do you drive per year? 12000
What is the current price per gallon of gasoline ? 3.00
How many miles per gallon does your car get? 25

You use 480.0 gallons of gas per year.
This costs $1440.0 and produces 9072.0 lbs of CO2 pollution

Now consider an electric car.
How many kilowatt hours (kwh) does it use per 100 miles? 30
What is the cost/kwh of your electricity in dollars 0.149

That electric car would use 3600.0 kwh's of electricity per year.
This costs $536.4 and produces 2117.3399999999997 lbs of CO2 pollution.

That would save $903.6 per year, and reduce carbon emissions by 6954.66 lbs.

(Later in this class we will learn how to round off and format printed values so you don't print all those excessive digits of precision.)

Part 1 (5 points) Prompt for and read user input values

First you will ask the user for some information about their gasoline car. Get the 3 values shown above. For each value, print a prompt and then read the value using a Scanner. Use scnr.nextDouble(); to get input values, and store them in variables of type double. Use meaningful variable names such as: milesDriven, gasPrice, and mpg.

Part 2 (5 points) Gas car calculations

In the second section calculate the number of gallons of gasoline used per year, the cost for that gasoline, and the CO2 pollution produced by using it.

Include this constant declaration in your program, and use it to calculate the CO2 pollution:

    final double LBS_CO2_PER_GALLON_E10 = 18.9; // pounds of CO2/gallon of E10 gasoline

(E10 is gasoline with 10% ethanol currently used in the US.)

Store your calculated results in more variables.

Part 3 (5 points) Print the gas car results

Print these values just like in the report above.

Part 4 (5 points) Electric car values

Now ask the user for the electric car values. Use meaningful variable names.

Part 5 (5 points) Electric car calculations

Next calculate the number of kwh's used per year, the cost of that much electricity, and the CO2 pollution produced by using it.

Include this constant declaration in your program, and use it to calculate the CO2 pollution:

    final double LBS_CO2_PER_KWH = 0.58815;   // pounds of CO2/KWH

Part 6 (5 points) Print the electric car results and the savings

Print the rest of the report including the cost savings and CO2 reduction.

Testing

The input values in the above example are based on national and local averages and prices. Use these values and verify that your program calculates the exact same results. Now run your program with input based on your own vehicle, usage, and prices, and for a different electric car.

Here are electricity usage values for some current electric cars:

Electric car
kwh/100 miles
Tesla Model 3 24
Hyundai Ioniq 25
Chevy Bolt
29
Nissan Leaf 31
Mustang Mach E
34

Extra Credit (5 points) Lifetime calculations

Ask the user how many years they expect to own the car, and then calculate and print the expected fuel cost savings and CO2 reduction over the lifetime of the car.

What to turn in

Turn in your program and its output for both test cases. Please format your report neatly, and make sure your code is properly indented.