/* * Intro to Programming CSE 1310 * University of Texas at Arlington */ package code4sepf18; import java.util.Scanner; import javax.swing.JOptionPane; /** * * @author jcmtiernan */ public class Code4SepF18 { /** * @param args the command line arguments */ public static void main(String[] args) { 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; short numberOfYears = 14; long UTAID; byte numberOfDaysInMonth; char initial = 'J'; char tabSpace = '\t'; boolean flagValue = true; Scanner input = new Scanner(System.in); String banner = "The New Car Selection System"; int team2 = 49; String team = 49 + "ers"; System.out.println("Welcome to the "+banner); String price = JOptionPane.showInputDialog("Enter Car 1 purchase price: $"); car1PurchasePrice = Double.parseDouble(price); //System.out.print("Please enter the purchase price for Car 1: "); //car1PurchasePrice = input.nextDouble(); System.out.print("You entered the purchase price of "+ car1PurchasePrice+" for Car 1 \n"); 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 = (float) (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 if (car2 < 20000) { System.out.println("Car 2 is the best choice"); } else { System.out.println("Car 2 is good but not cheap!"); } if (car1 < 10000) { System.out.println("This is a cheap car!"); } System.out.println("Thank you for using the "+banner); } }