用Java进行四舍五入计算
问题是: 根据售出的数量,欧内斯托的鸡蛋有不同的批发价格: 0至但不包括4打:每打0.50美元 4打至但不包括6打:每打0.45美元 6打至11打,但不包括11打:每打0.40美元 11打或更多打:每打0.35美元 额外鸡蛋的价格是每打价格的1/12 a) 编写一个程序,询问用户鸡蛋的数量,然后计算账单。程序输出应类似于: 输入蛋数:126 你的价格是每打0.40美元或每只鸡蛋0.033美元 你的账单是4.20美元 这是我写的,但我没有正确的四舍五入数字用Java进行四舍五入计算,java,rounding,Java,Rounding,问题是: 根据售出的数量,欧内斯托的鸡蛋有不同的批发价格: 0至但不包括4打:每打0.50美元 4打至但不包括6打:每打0.45美元 6打至11打,但不包括11打:每打0.40美元 11打或更多打:每打0.35美元 额外鸡蛋的价格是每打价格的1/12 a) 编写一个程序,询问用户鸡蛋的数量,然后计算账单。程序输出应类似于: 输入蛋数:126 你的价格是每打0.40美元或每只鸡蛋0.033美元 你的账单是4.20美元 这是我写的,但我没有正确的四舍五入数字 /* Program 1 (Ernest
/*
Program 1 (Ernestos Eggs)
*/
package eggs;
import java.util.Scanner;
/**
*
* @author Laptop
*/
public class Eggs {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
Scanner sc= new Scanner(System.in);
System.out.print("Enter number of eggs: ");
int numberofeggs=sc.nextInt();
int numberofdozens=numberofeggs/12;
if(numberofeggs>=0 && numberofeggs<48){
double costpereggs= 0.50*(1/12);
double total= (0.50*numberofdozens)+costpereggs;
System.out.println("Your cost is $0.50 per dozen or " +costpereggs+ " per egg.");
System.out.print("Your bill comes to $" +total);
}
else if (numberofeggs>=48 && numberofeggs<72){
double costpereggs= 0.45*(1/12);
double total= (0.45*numberofdozens)+costpereggs;
System.out.println("Your cost is $0.45 per dozen or " +costpereggs+ "per egg.");
System.out.println("Your bill comes to $" +total);
}
else if (numberofeggs>=72 && numberofeggs<132) {
double costpereggs= 0.40*(1/12);
double total= ((0.40*numberofdozens)+costpereggs);
System.out.println("Your cost is $0.40 per dozen or " +costpereggs+ " per egg.");
System.out.println("Your bill comes to $" +total);
}
else {
double costpereggs= 0.35*(1/12);
double total= (0.35*numberofdozens)+costpereggs;
System.out.println("Your cost is $0.35 per dozen or " +costpereggs+ "per egg.");
System.out.println("Your bill comes to $" +total);
}
}
}
/*
方案1(欧内斯托斯鸡蛋)
*/
鸡蛋包装;
导入java.util.Scanner;
/**
*
*@author笔记本电脑
*/
公营鸡蛋{
/**
*@param指定命令行参数
*/
公共静态void main(字符串[]args){
扫描仪sc=新的扫描仪(System.in);
System.out.print(“输入蛋数:”);
int numberofeggs=sc.nextInt();
int numberoftheathes=numberofeggs/12;
如果(numberofeggs>=0&&numberofeggs=48&&numberofeggs=72&&numberofeggs为什么要将每个蛋的成本加到总数中?这与总数无关
double total = numberofdozens *0.35;
double costpereggs = total/numberofeggs;
这应该是你想要做的