- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
在此 while 循环内,有 4 个项目可供选择。咖啡 (1)、拿铁 (2)、卡布奇诺 (3) 和浓缩咖啡 (4)。模拟会选取一堆随机数来填写每个客户的订单和数量,然后计算每个客户的总成本。现在我必须在 while 循环之后制作销售报告,并且必须计算每个项目的销售总额。由于数字是随机的并且循环会根据客户数量自行重复,我该如何做到这一点?
while (CustomersSimulated <= MaxCustomersSimulated)
{
//customer number
System.out.println("Customer " + CustomersSimulated);
//one random item for each customer
Random RandomList = new Random();
int RandomItem = RandomList.nextInt(4) + 1;
if (RandomItem == 1)
{
System.out.println("Item purchased: Coffee");
final double CoffeePrice = 1.50;
//random quantity for the item
Random RandomListTwo = new Random();
int RandomQuantity = RandomListTwo.nextInt(5) + 1;
System.out.println("Quantity purchased: " + RandomQuantity);
//total cost for the one customer
double TotalCoffeeCost = RandomQuantity * CoffeePrice;
System.out.println("Total Cost: $" + NumberFormat.format(TotalCoffeeCost));
}
else if (RandomItem == 2)
{
System.out.println("Item purchased: Latte");
final double LattePrice = 3.50;
Random RandomListTwo = new Random();
int RandomQuantity = RandomListTwo.nextInt(5) + 1;
System.out.println("Quantity purchased: " + RandomQuantity);
double TotalLatteCost = RandomQuantity * LattePrice;
System.out.println("Total Cost: $" + NumberFormat.format(TotalLatteCost));
}
else if (RandomItem == 3)
{
System.out.println("Item purchased: Cappuccino");
final double CappuccinoPrice = 3.25;
Random RandomListTwo = new Random();
int RandomQuantity = RandomListTwo.nextInt(5) + 1;
System.out.println("Quantity purchased: " + RandomQuantity);
double TotalCappuccinoCost = RandomQuantity * CappuccinoPrice;
System.out.println("Total Cost: $" + NumberFormat.format(TotalCappuccinoCost));
}
else if (RandomItem == 4)
{
System.out.println("Item purchased: Espresso");
final double EspressoPrice = 2.00;
Random RandomListTwo = new Random();
int RandomQuantity = RandomListTwo.nextInt(5) + 1;
System.out.println("Quantity purchased: " + RandomQuantity);
double TotalEspressoCost = RandomQuantity * EspressoPrice;
System.out.println("Total Cost: $" + NumberFormat.format(TotalEspressoCost));
}
System.out.println(" ");
CustomersSimulated++;
}
最佳答案
我能想到的唯一方法是创建四个不同的计数器并通过每次添加来存储每个销售。
关于java - 如何获得循环内每个商品的总销售成本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15017016/
我的学校项目是创建一个销售和出租产品的电子商务网站。 我的主要问题是我找不到“出租”部分的最佳设计。现在我正在考虑两种设计: 第一个数据库设计建议: 第二条数据库设计建议: 如您所见,两种设计中都有相
如果 Mono 项目成功,它将为非 Windows 平台上的商业软件铺平道路。 我对根据我们现有的 Smoke Vector Graphics (OCaml) 和 F# for Visualizati
关闭。这个问题是off-topic .它目前不接受答案。 想改进这个问题吗? Update the question所以它是on-topic用于堆栈溢出。 关闭 10 年前。 Improve thi
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 这个问题似乎与 help center 中定义的范围内的编程无关。 . 关闭 8 年前。 Improve
是否有出售 .net 控件的网站?我似乎找不到任何东西。我想知道是否有人可以将我指向一个站点。我宁愿它不是一个需要提供源代码的网站(如果可以的话,无论如何都包括它们)。 最佳答案 有1个站点CodeC
免责声明:我主要是一名后端开发人员,没有广泛的 FE 知识。 我正在编写一个生成 HTML 的非 SPA Golang Web 应用程序,然后将其发送给用户。因为我想更好地更新和监控我的 Javasc
我尝试了几种不同的方法来从 Magento 中删除测试订单。 使用插件(http://www.magentocommerce.com/magento-connect/asperience-delete
我们有一个 Woocommerce 网站,并在 Facebook 和 Instagram 上转换广告。当潜在客户点击这些广告时,我们的网站将加载到 Facebook 和 Instagram 使用的应用
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 想改进这个问题?将问题更新为 on-topic对于堆栈溢出。 7年前关闭。 Improve this qu
我们已经在数据库中看到了销售数据,但在 Appstore Connect 控制台中看不到任何销售数据。有谁知道什么会导致这种情况吗? 只有当苹果应用内购买的 .purchased 状态回调被触发时,我
假设我有一个应用程序,我可以在其中以 iBook 的形式出售补充内容。无论哪种方式,他们都会收取 30%,但我可以将该应用程序用作销售它的平台。有没有一种方法可以通过应用程序本身销售它,但保留 iBo
我使用 BlueSnap API 通过 PayPal 销售产品。在我的网站上,我将购物者发送到 PayPal,而无需他们填写任何运输详细信息 - 一旦他们登录到 PayPal,我就会从他们的 Blue
最近,中国大型发行商联系了我,他们在越狱设备上拥有自己的“AppStore”。他们也让我通过他们的平台销售我的应用程序。我只是想知道有没有人有这方面的经验?合法吗? Apple 会在 AppStore
我正在尝试为 PayPal 交易提取 Sale Id。我正在使用 PayPalAndroidSDK 和 PayPal_MPL 到目前为止,我可以检索支付资源,例如PAY-... 使用这个: Paym
我已经安装了 Magento 2.2 并将支付方式配置为“PayPal Express Checkout” When i have payment with PayPal Express Checko
我有一个网站,人们可以在其中比较驾校。我已经使用 schema.org 标记将我知道的这些学校的所有详细信息(名称、描述、位置、价格范围等)添加到他们在我网站上的页面。 几周以来,人们还可以直接在我的
我需要知道一种向 magento admin 添加打印订单功能的方法。 最佳答案 您可以使用这个 extension .我没有测试它。于是手动安装。复制粘贴其扩展 key 并下载 here . 编辑:
我需要知道一种向 magento admin 添加打印订单功能的方法。 最佳答案 您可以使用这个 extension .我没有测试它。于是手动安装。复制粘贴其扩展 key 并下载 here . 编辑:
我有以下表格作为 MySQL Workbench 8.0CE 中更大架构的一部分; 订单 - Order_ID、Customer_ID、Payment_ID、Delivery_ID、Order_Dat
我正在使用亚马逊 MWS api 来获取完整的亚马逊订单列表。拥有这样的 api 非常好,它返回由亚马逊 (AFN) 完成和由卖家 (MFN) 订单完成。 登录到亚马逊卖家中心后,我可以看到所有销售
我是一名优秀的程序员,十分优秀!