import java.util.Scanner; public class TripExpenseProgram { public static void main(String[] args) { float food, hotel, gas, entertainment, each, difference; Scanner keyboard = new Scanner(System.in); // Get the user input System.out.println("Enter food expense total: "); food = keyboard.nextFloat(); System.out.println("Enter hotel bill total: "); hotel = keyboard.nextFloat(); System.out.println("Enter gasoline expense total: "); gas = keyboard.nextFloat(); System.out.println("Enter entertainment expense total: "); entertainment = keyboard.nextFloat(); // Calculate the difference each = (food + hotel + gas + entertainment) / 2; difference = each - (gas + entertainment); // These four lines are not necessary, but they give a breakdown // that will help verify whether or not the result is correct. System.out.println("\nThe total expenses are " + String.format("$%,1.2f", each * 2)); System.out.println("Each person should pay " + String.format("$%,1.2f", each)); System.out.println("Steve paid " + String.format("$%,1.2f", (gas + entertainment))); System.out.println("Bob paid " + String.format("$%,1.2f", (food + hotel))); // Decide who owes who and then display the results if (difference > 0) System.out.print("\nTherefore, Steve owes Bob "); else System.out.print("\nTherefore, Bob owes Steve "); System.out.println(String.format("$%,1.2f", difference)); } }