Create a LunchOrder application that prompts the user for the number of hamburge
ID: 3545787 • Letter: C
Question
Create a LunchOrder application that prompts the user for the number of hamburgers, salads, French fries, and sodas and then displays the total for the order. The LunchOrder application should include a Food object with a constructor that accepts the price, fat, carbs, and fiber for an item. Food method should return the price of the item and return the fat, carbohydrates, and fiber. Use the chart below for food prices and nutrition information:
Item Price Fat(g) Carbs(g) Fiber(g)
Hamburger $1.85 9 33 1
Salad $2.00 1 11 5
French fries $1.30 11 36 4
Soda $0.95 0 38 0
Application output should look similar to:
Enter number of hamburgers: 3
Each hamburger has 9.0g of fat, 33.0g of carbs, and 1.0g of fiber.
Enter number of salads: 4
Each salad has 1.0g of fat, 11.0g of carbs, and 5.0g of fiber.
Enter number of French fries: 2
French fries have 11.0g of fat, 36.0g of carbs, 4.0g of fiber.
Enter number of sodas: 5
Each soda has 0.0g of fat, 38.0g of carbs, 0.0g of fiber.
Your order comes to: $20.90
Explanation / Answer
import java.util.*;
public class LunchOrder {
int Hamburger ;
int Salad ;
int fries;
int Soda ;
LunchOrder(){
Scanner ob = new Scanner(System.in);
System.out.println("Enter number of hamburgers: ");
Hamburger = ob.nextInt();
System.out.println("Each hamburger has 9.0g of fat, 33.0g of carbs, and 1.0g of fiber.");
System.out.println("Enter number of salads: ");
Salad = ob.nextInt();
System.out.println("Each salad has 1.0g of fat, 11.0g of carbs, and 5.0g of fiber.");
System.out.println("Enter number of French fries: ");
fries = ob.nextInt();
System.out.println("French fries have 11.0g of fat, 36.0g of carbs, 4.0g of fiber.");
System.out.println("Enter number of sodas: ");
Soda = ob.nextInt();
System.out.println("Each soda has 0.0g of fat, 38.0g of carbs, 0.0g of fiber.");
}
public double food() {
double cost;
cost = Hamburger * 1.85 + Salad * 2.0 + fries * 1.30 + Soda * 0.95 ;
return cost;
}
public static void main(String[] args) {
LunchOrder Food = new LunchOrder();
System.out.println("Your order comes to: $"+Food.food());
}
}