fork download
  1. import java.util.Scanner;
  2.  
  3. class ChiliToGoProfit
  4. {
  5. public static void main (String[] args)
  6. {
  7. final double PROFIT_FOR_ADULT = 4.35;
  8. final double PROFIT_FOR_CHILD = 3.10;
  9. final double PRICE_FOR_ADULT = 7;
  10. final double PRICE_FOR_CHILD = 4;
  11.  
  12. double adultMeals;
  13. double childMeals;
  14.  
  15. Scanner scanner = new Scanner(System.in);
  16.  
  17. System.out.print("Input the number of adult meals:");
  18. adultMeals = scanner.nextDouble();
  19.  
  20. System.out.println("Input the number of child meals:");
  21. childMeals = scanner.nextDouble();
  22.  
  23. double totalPriceAdult = adultMeals * PRICE_FOR_ADULT;
  24. double totalPriceChild = childMeals * PRICE_FOR_CHILD;
  25. double totalPrice = totalPriceAdult + totalPriceChild;
  26. double totalProfitAdult = adultMeals * (PRICE_FOR_ADULT - PROFIT_FOR_ADULT);
  27. double totalProfitChild = childMeals * (PRICE_FOR_CHILD - PROFIT_FOR_CHILD);
  28. double totalProfit = totalProfitAdult + totalProfitChild;
  29.  
  30.  
  31. System.out.println("There are " + adultMeals + " adult meal(s).");
  32. System.out.println("There are " + childMeals + " child meal(s).");
  33. System.out.println("The total price of the meals is $" + totalPrice);
  34. System.out.println("Total profit from adult meals is $" + totalProfitAdult);
  35. System.out.println("Total profit from child meals is $" + totalProfitChild);
  36. System.out.println("Grand profit from total amount of meals is $" + totalProfit);
  37. }
  38. }
Success #stdin #stdout 0.16s 61224KB
stdin
10
5
stdout
Input the number of adult meals:Input the number of child meals:
There are 10.0 adult meal(s).
There are 5.0 child meal(s).
The total price of the meals is $90.0
Total profit from adult meals is $26.500000000000004
Total profit from child meals is $4.5
Grand profit from total amount of meals is $31.000000000000004