- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
创建一个在下订单之前需要密码的程序。成功输入密码后,客户应该会看到一条欢迎消息。然后是菜单。客户应该能够看到菜单和子菜单中的选项。订单(含价格)应在客户退出计划之前完成。
在我下面的代码中,它仍然要求输入密码,我不知道下一步该怎么做。另外,订单应该被统计并出现在客户退出之前的最后部分。请引导我完成这个!
欢迎来到 Favor Stuff(派对赠品)
请从可用菜单中选择。
A.万宝路灯
1. Soft Pack 70.00
2. Flip Top 80.00
B.万宝路红
1. Soft Pack 70.00
2. Flip Top 80.00
C.登喜路
1. Soft Pack 60.00
2. Flip Top 70.00
D.菲利普
1. Soft Pack 70.00
2. Flip Top 80.00
import java.util.Scanner;
import java.io.*;
public class MenuORDER {
public static void main(String[] args) {
int attempts = 0;
String Order;
Scanner keyboard = new Scanner(System.in);
String password = null;
String CORRECT_PWORD = "1234";
do {
System.out.println("Enter Password: ");
password = keyboard.next();
if (!password.equals(CORRECT_PWORD)) {
System.out.println("Password is incorrect!");
attempts++;
}
} while (!password.equals(CORRECT_PWORD) && attempts <3);
if (password.equals(CORRECT_PWORD)) {
System.out.println("Welcome to Favor Stuff (Party Giveaways)!");
do {
System.out.println("Please select from the available options below! ");
System.out.println("A. Marlboro Lights");
System.out.println("B. Marlboro Red");
System.out.println("C. Dunhill");
System.out.println("D. Phillip");
System.out.print("Sellect your brand: ");
System.out.println("");
String Price = keyboard.nextLine();
String Price1 = "";
String Price2 = "";
switch (Price) {
case "A": Price1 = "Soft Pack 70.00";
break;
case "B": Price2 = "Flip Top 80.00";
break;
case "C": Price1 = "Soft Pack 70.00";
break;
case "D": Price2 = "Flip Top 80.00";
break;
case "E": Price1 = "Soft Pack 70.00";
break;
case "F": Price2 = "Flip Top 80.00";
break;
case "G": Price1 = "Soft Pack 70.00";
break;
case "H": Price2 = "Flip Top 80.00";
break;
case "I": Price1 = "Soft Pack 70.00";
break;
case "J": Price2 = "Flip Top 80.00";
break;
default:
System.out.println("Invalid Input");
break;
}
System.out.println("Thank you! Your order is " + brand + Price);
}while (!password.equals(CORRECT_PWORD));
}while (!password.equals(CORRECT_PWORD) && attempts <3);
}
}
最佳答案
首先分解您的要求,首先您需要验证用户......
int attempts = 0;
Scanner keyboard = new Scanner(System.in);
String password = null;
String CORRECT_PWORD = "1234";
String Options = null;
do {
System.out.print("Enter Pin Code: ");
password = keyboard.next();
if (!password.equals(CORRECT_PWORD)) {
System.out.println("Password is incorrect!");
attempts++;
}
} while (!password.equals(CORRECT_PWORD) && attempts < 3);
他们要么输入正确的密码,要么失败。根据结果,您需要决定下一步该做什么...
if (password.equals(CORRECT_PWORD)) {
System.out.println("Welcome to Favor Stuff (Party Giveaways)!");
// Only valid user options should appear here...
} else {
System.out.println("Sorry but you can no longer continue!:");
}
// Program is allowed to terminate naturally
所以,在“有效用户”部分,您想显示主菜单...
if (password.equals(CORRECT_PWORD)) {
System.out.println("Welcome to Favor Stuff (Party Giveaways)!");
String option = null;
do {
System.out.println("Please select from the available options below! ");
System.out.println("A. Truffled Boxes");
System.out.println("B. Candy Jars");
System.out.println("C. Jellies");
System.out.println("D. Cupcakes");
System.out.println("E. Bride and Groom");
System.out.println("X. Exit");
option = keyboard.nextLine();
if (option.equals("A")) {
String subOption = null;
do {
System.out.println("1. Truffled Boxes with two (2) truffles and personalized thank you tags");
System.out.println("2. Truffled Boxes with four (4) truffles and personalized thank you tags");
System.out.println("3. Truffled Boxes with six (6) truffles and personalized thank you tags");
System.out.println("0. Return");
subOption = keyboard.nextLine();
if (subOption.equals("1")) {
} else if (subOption.equals("2")) {
} else if (subOption.equals("3")) {
} else if (subOption.equals("0")) {
// Do nothing, but don't want to display
// invalid entry message
} else {
System.out.println("Invalid entry!");
}
} while (!subOption.equalsIgnoreCase("0"));
} else if (option.equals("B")) {
// Candy jars...
} else if (option.equals("C")) {
// Jellies...
} else if (option.equals("D")) {
// Candy Cupcakes...
} else if (option.equals("E")) {
// Bride groom...
} else if (option.equalsIgnoreCase("x")) {
// Do nothing, but don't want to display
// invalid entry message
} else {
System.out.println("Invalid entry!");
}
} while (!option.equalsIgnoreCase("x"));
}
该主循环负责主菜单中的所有选项。每个子部分也将有它自己的输入循环。如果您对方法做了任何工作,我会将所有这些分解为它自己的方法,以使生活更轻松。
要跟踪订单,有许多可能的解决方案,例如,您可以创建一个 Product
类,其中包含有关每个产品的信息(名称、价格),然后创建一个 Order
类,其中包含有关已订购的 Product
和数量的信息。这可能是首选方式。但更简单、更黑客的方法是定义一系列键......
public static final String TRUFFLE_BOXES_2 = "Truffle Boxes with (2) truffles and personalized thank you tags";
public static final String TRUFFLE_BOXES_4 = "Truffle Boxes with (4) truffles and personalized thank you tags";
public static final String TRUFFLE_BOXES_6 = "Truffle Boxes with (6) truffles and personalized thank you tags";
public static final String CANDY_MARSHMELLOW = "Marshmallow";
public static final String CANDY_CHOCOLATE = "Chocolate";
public static final String CANDY_COOKIES = "Cookies";
public static final String JELLIES_JELLY_BEANS = "Jelly Beans";
public static final String CUP_CAKES_REGULAR = "Regular cupcake box";
public static final String CUP_CAKES_REGULAR_BULK = "Regular cupcake box by bulk";
public static final String BRIDE_AND_GROOM_BOX = "Bride and groom box (per pair)";
这些表示对 Map
执行查找的快速且简单的键
然后,您可以定义每个产品/ key 的价格
Map<String, Double> prices = new HashMap<>(10);
prices.put(TRUFFLE_BOXES_2, 45.00);
prices.put(TRUFFLE_BOXES_4, 50.00);
prices.put(TRUFFLE_BOXES_6, 60.00);
prices.put(CANDY_MARSHMELLOW, 35.00);
prices.put(CANDY_CHOCOLATE, 50.00);
prices.put(CANDY_COOKIES, 45.00);
prices.put(JELLIES_JELLY_BEANS, 45.00);
prices.put(CUP_CAKES_REGULAR, 60.00);
prices.put(CUP_CAKES_REGULAR_BULK, 40.00);
prices.put(BRIDE_AND_GROOM_BOX, 70.00);
然后您可以使用诸如...之类的方式跟踪订单
Map<String, Integer> order = new HashMap<>(25);
order.put(CANDY_CHOCOLATE, 10);
order.put(CUP_CAKES_REGULAR, 5);
order.put(CANDY_COOKIES, 12);
并在需要时提供统计
double total = 0;
for (Map.Entry<String, Integer> entry : order.entrySet()) {
int quanity = entry.getValue();
double price = prices.get(entry.getKey());
total += quanity * price;
System.out.println(String.format(
"%-20s x %4d @ %7s = %10s",
entry.getKey(),
quanity,
NumberFormat.getCurrencyInstance().format(price),
NumberFormat.getCurrencyInstance().format(quanity * price)));
}
System.out.printf("%-20s %4s %7s ==========%n", "", "", "");
System.out.printf("%-20s %4s %7s %10s%n", "", "", "", NumberFormat.getCurrencyInstance().format(total));
其中打印
Chocolate x 10 @ $50.00 = $500.00
Cookies x 12 @ $45.00 = $540.00
Regular cupcake box x 5 @ $60.00 = $300.00
==========
$1,340.00
I want to change the options into Cigar brands, and use switch so it would be better... but add the prices at the end just like what you did with the previous one.. I'm confused
我又要把你搞糊涂了...
基本上,这是您的整个(更新)计划、项目、价格、菜单、计数。
它利用商品、订单、价格和组的 map
来生成整个程序。
“数据”都是可变的,但是当您创建/添加/删除产品时,菜单和订购系统的工作方式不需要更改
import java.text.NumberFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Scanner;
public class TestShop {
public static final String MALBORO_LIGHTS = "Malboro Lights";
public static final String MALBORO_LIGHTS_SOFT = "Marlboro Lights, Soft Pack";
public static final String MALBORO_LIGHTS_FLIP = "Marlboro Lights, Flip Pack";
public static final String MALBORO_RED = "Malboro Reds";
public static final String MALBORO_RED_SOFT = "Marlboro Reds, Soft Pack";
public static final String MALBORO_RED_FLIP = "Marlboro Reds, Flip Pack";
public static final String DUNHILL = "Dunhill";
public static final String DUNHILL_SOFT = "Dunhill, Soft Pack";
public static final String DUNHILL_FLIP = "Dunhill, Flip Pack";
public static final String PHILLIP = "Phillip";
public static final String PHILLIP_SOFT = "Phillip, Soft Pack";
public static final String PHILLIP_FLIP = "Phillip, Flip Pack";
public static void main(String[] args) {
new TestShop();
}
public TestShop() {
Scanner keyboard = new Scanner(System.in);
/**************************************************************************/
/* This part is dynamic, change this when you want new items, prices or */
/* groups */
/**************************************************************************/
// A list of items that have been ordered
Map<String, Integer> orders = new HashMap<>(25);
// A list of items keyed to prices
Map<String, Double> prices = new HashMap<>(25);
prices.put(MALBORO_LIGHTS_SOFT, 70d);
prices.put(MALBORO_LIGHTS_FLIP, 80d);
prices.put(MALBORO_RED_SOFT, 70d);
prices.put(MALBORO_RED_FLIP, 80d);
prices.put(DUNHILL_SOFT, 60d);
prices.put(DUNHILL_FLIP, 70d);
prices.put(PHILLIP_SOFT, 70d);
prices.put(PHILLIP_FLIP, 80d);
// Mapping items to groups...
Map<String, List<String>> groups = new HashMap<>(25);
groups.put(MALBORO_LIGHTS, new ArrayList<>(Arrays.asList(new String[]{MALBORO_LIGHTS_SOFT, MALBORO_LIGHTS_FLIP})));
groups.put(MALBORO_RED, new ArrayList<>(Arrays.asList(new String[]{MALBORO_RED_SOFT, MALBORO_RED_FLIP})));
groups.put(DUNHILL, new ArrayList<>(Arrays.asList(new String[]{DUNHILL_SOFT, DUNHILL_FLIP})));
groups.put(PHILLIP, new ArrayList<>(Arrays.asList(new String[]{PHILLIP_SOFT, PHILLIP_FLIP})));
/**************************************************************************/
/**************************************************************************/
/* The rest of this is pretty static and is driven by the data from above */
/* This means, you don't need change anything below here, when the stuff */
/* changes */
/**************************************************************************/
boolean done = false;
do {
System.out.println("Welcome to my shop");
List<String> keys = new ArrayList<>(groups.keySet());
for (int index = 0; index < keys.size(); index++) {
System.out.println("[" + (index + 1) + "] " + keys.get(index));
}
System.out.println("[0] Exit");
String input = keyboard.nextLine();
try {
int selectedIndex = Integer.parseInt(input);
if (selectedIndex == 0) {
done = true;
} else if (selectedIndex > 0 && selectedIndex <= keys.size()) {
String key = keys.get(selectedIndex - 1);
List<String> items = groups.get(key);
boolean subDone = false;
do {
System.out.println("Items for " + key + "....");
for (int index = 0; index < items.size(); index++) {
System.out.println(" [" + (index + 1) + "] " + items.get(index));
}
System.out.println(" [0] Return");
input = keyboard.nextLine();
try {
int index = Integer.parseInt(input);
if (index > 0 && index <= items.size()) {
index--; // The items in the list are 0 indexed
String item = items.get(index);
Integer quanity = orders.get(item);
if (quanity == null) {
quanity = 1;
} else {
quanity++;
}
orders.put(item, quanity);
} else if (index == 0) {
subDone = true;
} else {
System.out.println("Invalid selection, please try again");
}
} catch (NumberFormatException exp) {
System.out.println("!! " + input + " is not a valid selection");
}
} while (!subDone);
} else {
System.out.println("Invalid selection, please try again");
}
} catch (NumberFormatException exp) {
System.out.println("!! " + input + " is not a valid selection");
}
} while (!done);
double total = 0;
for (Map.Entry<String, Integer> entry : orders.entrySet()) {
int quanity = entry.getValue();
double price = prices.get(entry.getKey());
total += quanity * price;
System.out.println(String.format(
"%-20s x %4d @ %7s = %10s",
entry.getKey(),
quanity,
NumberFormat.getCurrencyInstance().format(price),
NumberFormat.getCurrencyInstance().format(quanity * price)));
}
System.out.printf("%-20s %4s %7s ==========%n", "", "", "");
System.out.printf("%-20s %4s %7s %10s%n", "", "", "", NumberFormat.getCurrencyInstance().format(total));
}
}
关于java - 带密码和简单订单的菜单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33206299/
我尝试编写一个有多个链接表的解决方案。现在我有另一个问题: 我想将返回的行数限制为 1000。但我想显示 ID 1-1000,下一页 1001-2000。ID可以以不规则的顺序存储在数据库中(ID 1
我已经尝试申请 Drupal 商业优惠券大约 2 天了。我已经负责验证优惠券,但目前在尝试兑换优惠券时遇到了困难。 所以在我的回调函数中,我正在调用: my_module_coupons_coupon
[问]请帮忙,比如有一个数据 tbl_user | Id | name | | 1 | Bayu | | 2 | Indra | | 3 | Rangga | tbl_data | Id | user
我在 Android 应用程序中使用的一些 Parcelable 自定义类遇到了问题,我设法以一种非常奇怪的方式解决了这个问题。 仅在少数特定情况下,我在读取 parcelable 时发生了崩溃(这让
我一直在做一个项目,我需要在数据库中存储订单列表(在本例中为食品)。 我曾尝试四处寻找存储此类列表的最佳方式,但找不到任何方法。 目前,我将数据存储在 phpMyAdmin/SQL 中,订单存储为要打
目录 1、背景简介 2、订单业务 1、订单体系 2、流程管理 2
HBase案例:客户/订单 假设HBase 用于存储客户和订单信息。有两种核心记录类型被摄取:客户记录类型和订单记录类型。 客户记录类型将包含您通常期望的所有内容: 客户编号 客户名称
C-x C-b 显示缓冲区列表。首先是自然顺序,最近使用的缓冲区在顶部,隐藏的缓冲区在底部。 在那里,我现在可以按名称、大小、模式和文件对缓冲区进行排序。但是一旦我点击了这样的选项,我就无法回到原来的
我为 Woocommerce 添加了一个新的排序选项,它将按最低价格排序。我所有的价格都存储在一个自定义属性中,连同一些其他序列化数据。我想要的是有一个回调函数来反序列化这些数据,检查最低价格并按该价
想象一下我有一张 table : ID field1 field2 --- ------- ------ 111 1 11113 112
Kotlin forEach 是按数组的实际顺序遍历数组还是有时可能按其他顺序遍历数组?我的意思是这是否总是打印 1,2,3,...9 或者它可能会打印类似 1,5,3,4,... val numbe
我在 woocommerce 3+ 上创建了 html 电子邮件模板,但我无法通过订单 ID 获取订单项。我试过这个,但对我不起作用。 get_items(); foreach
我对将我自己的内部广告与 AdMob 的广告一起展示并使用按重要性顺序设置 eCPM 值的问题感到有些困惑。 我目前只与 AdMobs 的网络一起转换一个自家广告。 从常见问题解答和 AdMob 帮助
我正在尝试构建一个电子商务数据库,但我不了解订单,产品和客户之间的关系。 有很多数据库示例,但是它们太复杂了。是否有关于可能的表和关系的更简单的解释或示例。 谢谢。 最佳答案 如果客户可以拥有多个订单
我必须对电子商务系统进行一些更改以添加一些附加信息,并希望借此机会进行一些改进并使其更加灵活。当客户下订单时,我们必须为每个订购的商品存储几项信息;例如,产品价格、运费、征收的税款、所做的任何调整。
我正在尝试新的 ASP.NET bundle 功能,但似乎无法让我的自定义排序正常工作。这是我的 JS 文件: bootstrap.js bootstrap.min.js jquery-1.7.2.i
我正在尝试以下代码,并希望获取日期之间的所有订单并打印它们 $orders = $my_query->posts; $order = wc_get_order( $order_id ); $or
我有 ORMLite 数据库对象,它有一个字段: @ForeignCollectionField(eager = true) public ForeignCollection blocks; 现在,当
除了调用 event_list_attendees 并寻呼与会者以尝试找到正确的用户匹配之外,是否有其他方法可以获取门票/订单的用户条形码 ID?这种方法会增加 eventbrite 服务器的负担,并
这个问题已经有答案了: What is a NullPointerException, and how do I fix it? (12 个回答) 已关闭 5 年前。 我制作了订单食品应用程序。当我单
我是一名优秀的程序员,十分优秀!