Question: I was asked to create a java program that calculates the total for an order of eggs at $3.25 per dozen, and $0.45 for any
I was asked to create a java program that calculates the total for an order of eggs at $3.25 per dozen, and $0.45 for any loose eggs. Here is what I came up with. When I try to compile it it says "Eggs.java:17: error: incompatible types: possible lossy conversion from double to int total=(int) (dozens*PRICE_PER_DOZEN)+(leftOver*PRICE_PER_EGG);"
Below is my code. Help please.
import java.util.Scanner; class Eggs { public static void main(String[] args) { final int DOZEN=12; final double PRICE_PER_DOZEN=3.25; final double PRICE_PER_EGG=0.45; int eggs; int dozens; int leftOver; int total; Scanner input=new Scanner(System.in); System.out.print("Amount of Eggs>>"); eggs=input.nextInt(); dozens=eggs/DOZEN; leftOver=eggs%DOZEN; total=(int) (dozens*PRICE_PER_DOZEN)+(leftOver*PRICE_PER_EGG); System.out.println("You ordered"+eggs+"eggs. That's"+dozens+"dozen at $"+PRICE_PER_DOZEN+"per dozen and"+leftOver+"extra eggs at"+(int)(PRICE_PER_EGG*100)+"cents each for a total of $"+total); } }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
