Create an application that calculates your daily driving cost, so that you can estimate how much money could be saved by carpooling, which also has other advantages such as reducing carbon emissions and reducing traffic congestion. The application should input the following information and display the user’s cost per day of driving to work
Total miles driven per day
Cost per gallons of gasoline
Average miles per gallon
Parking fees per day
Tolls per day
package lab0;
import java.util.Scanner;
public class Ques_3 {
public static void main(String[] args) {
double total_miles_driven_per_day, cost_per_gallon_of_gasolin, average_miles_per_gallon, parking_fee_per_day,
tolls_per_week, cost;
Scanner sc = new Scanner(System.in);
System.out.println("Enter details:");
System.out.print("Total miles driven per day:");
total_miles_driven_per_day = Double.parseDouble(sc.nextLine());
System.out.print("Cost per gallon of gasoline:");
cost_per_gallon_of_gasolin = Double.parseDouble(sc.nextLine());
System.out.print("Average miles per gallon:");
average_miles_per_gallon = Double.parseDouble(sc.nextLine());
System.out.print("Parking fee per day:");
parking_fee_per_day = Double.parseDouble(sc.nextLine());
System.out.print("Tolls per week:");
tolls_per_week = Double.parseDouble(sc.nextLine());
sc.close();
cost = parking_fee_per_day + tolls_per_week
+ ((total_miles_driven_per_day / average_miles_per_gallon) * cost_per_gallon_of_gasolin);
System.out.println("Daily Driving Cost : " + cost);
}
}
import java.util.Scanner;
public class Ques_3 {
public static void main(String[] args) {
double total_miles_driven_per_day, cost_per_gallon_of_gasolin, average_miles_per_gallon, parking_fee_per_day,
tolls_per_week, cost;
Scanner sc = new Scanner(System.in);
System.out.println("Enter details:");
System.out.print("Total miles driven per day:");
total_miles_driven_per_day = Double.parseDouble(sc.nextLine());
System.out.print("Cost per gallon of gasoline:");
cost_per_gallon_of_gasolin = Double.parseDouble(sc.nextLine());
System.out.print("Average miles per gallon:");
average_miles_per_gallon = Double.parseDouble(sc.nextLine());
System.out.print("Parking fee per day:");
parking_fee_per_day = Double.parseDouble(sc.nextLine());
System.out.print("Tolls per week:");
tolls_per_week = Double.parseDouble(sc.nextLine());
sc.close();
cost = parking_fee_per_day + tolls_per_week
+ ((total_miles_driven_per_day / average_miles_per_gallon) * cost_per_gallon_of_gasolin);
System.out.println("Daily Driving Cost : " + cost);
}
}
0 Comments