/** * Burger.java - calculates price of a hamburger. * * @author Jeff Pittges * @version 23-Aug-2015 */ import java.util.Scanner; public class Burger { public static void main(String[] args) { final int MIN_PATTIES = 1; final int MAX_PATTIES = 3; final double PATTY_PRICE = 1.50; final double TOMATO_PRICE = 0.30; final double LETTUCE_PRICE = 0.45; Scanner scanObj = new Scanner(System.in); System.out.print("\nHow many patties (1 - 3): "); int numPatties = scanObj.nextInt(); boolean tomato = false; System.out.print("\nDo you want tomato (Y/N): "); String input = scanObj.next(); if (input.charAt(0) == 'Y') tomato = true; boolean lettuce = false; System.out.print("Do you want lettuce (Y/N): "); input = scanObj.next(); if (input.charAt(0) == 'Y') lettuce = true; double total = 0; // Correct: if (numPatties >= MIN_PATTIES && numPatties <= MAX_PATTIES) if (numPatties > MIN_PATTIES && numPatties < MAX_PATTIES) { total = numPatties * PATTY_PRICE; } if (tomato) total += TOMATO_PRICE; if (lettuce) total += LETTUCE_PRICE; System.out.println("\nTotal: " + total); } }