In: Computer Science
A wholesale egg company bases their prices on the number of eggs purchased: 0 up to but not including 4 dozen $0.50 per dozen 4 up to but not including 6 dozen $0.45 per dozen 6 up to but not including 11 dozen $0.40 per dozen 11 or more dozen $0.35 per dozen Extra eggs are priced at 1/12the per dozen price. Create an Eggs application that prompts the user for the number of eggs, and then calculates the bill. The application output should look similar to:
Enter the number of eggs purchased: 18
The bill is equal to: $0.75
Notes:
Coded in Java please.
Don't use any keyboard codes or anything too complicated. Try and make it the easiest way to solve it because I am in grade 11
Code:
import java.util.Scanner;/*Importing scanner class*/
class egg
{
public static void main(String[] args)
{
int negg;
double dozen,price;/*Declaring
variables*/
Scanner scnr=new
Scanner(System.in);
System.out.print("Enter the number
of eggs purchased: ");
negg=scnr.nextInt();/*no of eggs
from the user*/
dozen=negg/12.0;/*Calculating no of
dozens*/
if(dozen<4)
{
price=0.5;/*If
no dozens is less than 4*/
}
else if(dozen<6)
{
price=0.45;/*If
no dozens is less than 6 and above 4 */
}
else if(dozen<11)
{
price=0.4;/*If
no dozens is less than 11 and above 6 */
}
else
{
price=0.35;/*If
no fo dozens 11 or above*/
}
System.out.print("The bill is equal
to: $"+(dozen*price));
/*Finally we print the bill*/
}
}
Output:
Indentation: