/* * Intro to Programming CSE 1310 * University of Texas at Arlington */ package code30augf18; import java.util.Scanner; /** * * @author jcmtiernan */ public class Code30AugF18 { /** * @param args the command line arguments */ public static void main(String[] args) { // Algorithm - /** * Algorithm - set of steps to solve a problem. * * What initial information do we need? * How do we update the value? What are the small steps? * How do we know when we are finished? * Test your algorithm with values by hand * Create a pseudocode algorithm */ /** * Choose between two cars to purchase. * For each car, compute the total cost as follows: annual fuel consumed = annual miles driven / fuel efficiency annual fuel cost = price per gallon x annual fuel consumed operating cost = 10 x annual fuel cost total cost = purchase price + operating cost If total cost of car1 < total cost of car2 Choose car1. Else Choose car2. * * */ double car1PurchasePrice = 20000; double car2PurchasePrice = 15000; int car1Efficiency = 50; int car2Efficiency = 42; double car1FuelConsumed = 0; double car2FuelConsumed = 0; int milesDriven = 18000; double car1FuelCost = 0; double car2FuelCost = 0; double pricePerGallon = 2.5; double car1OperatingCost; double car2OperatingCost; double car1 =0; double car2 =0; int numberOfYears = 14; Scanner input = new Scanner(System.in); System.out.print("Please enter the purchase price for Car 1: "); car1PurchasePrice = input.nextDouble(); System.out.print("Please enter the purchase price for Car 2: "); car2PurchasePrice = input.nextDouble(); System.out.print("Please enter the MPG for Car 1: "); car1Efficiency = input.nextInt(); System.out.print("Please enter the MPG for Car 2: "); car2Efficiency = input.nextInt(); System.out.println("How many miles are you driving in a year? "); milesDriven = input.nextInt(); // annual fuel consumed = annual miles driven / fuel efficiency car1FuelConsumed = milesDriven / (double) car1Efficiency; car2FuelConsumed = milesDriven / (double) car2Efficiency; //car1FuelConsumed = 10000 / (double) car1Efficiency; //car2FuelConsumed = 10000 / (double) car2Efficiency; // annual fuel cost = price per gallon x annual fuel consumed car1FuelCost = pricePerGallon * car1FuelConsumed; car2FuelCost = pricePerGallon * car2FuelConsumed; // operating cost = 10 x annual fuel cost car1OperatingCost = numberOfYears * car1FuelCost; car2OperatingCost = numberOfYears * car2FuelCost; // total cost = purchase price + operating cost car1 = car1PurchasePrice + car1OperatingCost; car2 = car2PurchasePrice + car2OperatingCost; System.out.println("Total cost for car 1 is $"+ car1); System.out.println("Total cost for car 2 is $"+ car2); if (car1 < car2) { System.out.println("The best choice is Car 1"); } else { System.out.println("Car 2 is the best choice"); } } }