Write a program that helps a person decide whether to buy a hybrid car. Your pro
ID: 3665493 • Letter: W
Question
Write a program that helps a person decide whether to buy a hybrid car. Your program’s inputs should come from user and include: The cost of the each car The estimated miles per year driven The estimated gas price in dollars per gallon The efficiency of each car in miles per gallon The estimated resale value of each car after 5 years The program should output the cost of each car after hypothetically buying each car with cash, driving it for 5 years and then selling it. Ignore costs not listed as part of the inputs above Obtain reasonable estimates for all of the above values from the internet. Turn in your source code ( 1 class) List your inputs and cite your sources. Turn in an example run of your program with the inputs that you found.
Explanation / Answer
import java.util.Scanner;
public class Car
{
public static void main(String[] args)
{
Scanner input = new Scanner(System.in);
System.out.print("Car cost: ");
double car_cost = input.nextDouble();
System.out.print("Miles driven: ");
double miles_driven = input.nextDouble();
System.out.print("Gas price: ");
double gas_price = input.nextDouble();
System.out.print("Fuel Efficiency: ");
double fuel_efficiency = input.nextDouble();
System.out.print("Re-sale value: ");
double resale_value = input.nextDouble();
input.close();
double cost_to_own = car_cost * (fuel_efficiency * miles_driven * gas_price);
System.out.printf("Cost to own: %.2f", cost_to_own);
System.out.println("Cost after re-sale: " + (car_cost - resale_value));
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.