Create with JAVA, NOT C++ 1) Each morning, a dairy farm sells cartons of milk to
ID: 669355 • Letter: C
Question
Create with JAVA, NOT C++
1) Each morning, a dairy farm sells cartons of milk to a local grocery store. The cost of producing one liter of milk is $0.25, and the markup on each carton of milk is $0.27. The cost of the carton is $1.00, so the total sale price of a carton is
sale price = cost of milk + cost of carton + markup
A carton of milk can hold 1.2 liters. You cannot sell partial cartons of milk!
Write a program that does the following: a. Prompts the user to enter the total amount of milk produced in the morning
b. Outputs the number of milk cartons that can be sold (no partially filled!)
c. Outputs the cost of producing milk
d. Outputs the profit for the cartons that can be sold
Your class for this problem should be called DairyCalculator. All the code can be in the main() function for this problem.
Explanation / Answer
import java.util.Scanner;
public class DairyCalculator {
public static void main(String[] args){
double totalMilk;
Scanner s = new Scanner(System.in);
System.out.print("enter the total amount of milk produced in the morning: ");
totalMilk = s.nextDouble();
int cartonsSold = (int)(totalMilk / 1.2);
System.out.println("number of milk cartons that can be sold: " + cartonsSold);
System.out.println("cost of producing milk: $" + totalMilk * 0.25);
System.out.println("profit for the cartons that can be sold: $" + cartonsSold * 0.27);
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.