Java program that helps a person decide whether to buy a hybrid car
###### Posted by Samath
Last Updated: February 09, 2021

Write a Java program that helps a person decide whether to buy a hybrid car.
• The cost of a new car
• The estimated miles driven per year
• The estimated gas price
• The efficiency in miles per gallon
• The estimated re-sale value after 5 years
Compute the total cost of owning the car for five years.
(For simplicity, we will not take the cost of financing into account.)
Obtain realistic prices for a new and used hybrid and a comparable car from the Web.
Run your program twice, using today’s gas price and 15,000 miles per year.

Code:

```import java.util.Scanner;

public class Main
{
public static void main(String[] args) {

Scanner input = new Scanner(System.in);
double car_cost;
double miles_driven;
double gas_price;
double fuel_efficiency;
double resale_value;
double cost_to_own;

System.out.print("Car cost: ");
car_cost = input.nextDouble();

System.out.print("Miles driven: ");
miles_driven = input.nextDouble();

System.out.print("Gas price: ");
gas_price = input.nextDouble();

System.out.print("Fuel Efficiency: ");
fuel_efficiency = input.nextDouble();

System.out.print("Re-sale value:  ");
resale_value = input.nextDouble();

input.close();

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));
}
}
```
###### Car Class using C++
Samath | Jan 07, 2021
###### Write a program in C++ that calculate the bonus of a sales person
Samath | Nov 02, 2014
###### Car Loan Applet in Java
gideonna | Apr 13, 2016
###### Java program calculate the cost per 100 miles and how far the car can go with the gas in the tank
Samath | Feb 09, 2021
###### Java program that calculates and prints the value of the coupon a person can receive based on groceries purchased
Samath | May 08, 2021