【问题标题】:I want to add 10% service tax and 13% vat but I am unable to do我想加 10% 的服务税和 13% 的增值税,但我做不到
【发布时间】:2019-11-23 08:26:19
【问题描述】:

这是我的作业:

您需要创建一个 MVP(最小可行产品)才能为加德满都的一家当地民族食品餐厅接受客户订单。餐厅提供10种不同类型的美食,取材于当地民族饮食文化。餐厅以有限的菜肴和有限的员工经营。您需要创建一个订单系统原型,以简化餐厅内的工作流程。您的程序应具有以下功能:

  • 程序应在开始时显示菜单(有 10 道菜)
  • 每位客户都将根据显示的菜单下订单。对于每个订单,系统应计算总账单。
  • 每张账单,在加上菜品价格的总和后,总和将征收10%的服务税和13%的增值税。
  • 对于客户(新客户或重复客户)下订单的每个新实例,都会生成一份新账单。
  • 更改已确认的订单不是系统 MVP 阶段的必要功能。
  • 您的 MVP 应该能够同时管理 5 个客户的订单和计费。
  • 菜单价格和其中的菜品最初可以硬连线到您的 MVP 中用于测试目的(在文件或数组中)

我的代码:

public class Array { //class name

    public static void main(String args[]) {
        Scanner input = new Scanner(System.in);
        int choice;
        double total = 0;
        double tax = 0.10;

        //Array for storing prices
        double[] Price = new double[10];
        Price[0] = 120;
        Price[1] = 80;
        Price[2] = 40;
        Price[3] = 100;
        Price[4] = 50;
        Price[5] = 60;
        Price[6] = 90;
        Price[7] = 45;
        Price[8] = 70;
        Price[9] = 60;

        //Menu item array
        String[] FoodItem = new String[10];
        FoodItem[0] = "Momo";
        FoodItem[1] = "Chawmin";
        FoodItem[2] = "Sausages";
        FoodItem[3] = "Pizza";
        FoodItem[4] = "Burger";
        FoodItem[5] = "Buff Sekuwa";
        FoodItem[6] = "Chicken Sekuwa";
        FoodItem[7] = "Alu Paratha";
        FoodItem[8] = "Chicken Chilly";
        FoodItem[9] = "Fry Rice";

        //Welcome user and gather their menu selection
        System.out.println("Welcome to PurpleHaze ! Please enjoy!");
        // System.out.printf("The average pricing for our drinks is: %.2f \n", + cafeAvg( cafePrice));
        System.out.println("Please enter a menu selection:\n" +
            "0. Momo -- 120\n" +
            "1. Chawmin -- 80\n" +
            "2. Sausages -- 40\n" +
            "3. Pizza -- 100\n" +
            "4. Burger -- 50\n" +
            "5. Buff Sekuwa -- 60\n" +
            "6. Chicken Sekuwa -- 90\n" +
            "7. Alu Paratha -- 45\n" +
            "8. Chicken Chilly -- 70\n" +
            "9. Fry Rice -- 60");

        choice = input.nextInt();

        //Add up the total

        total = Price[choice] + tax;
        System.out.println("Your total is: " + total + tax);
    }

}

我想添加 13% 的增值税和 10% 的费用。

【问题讨论】:

  • 请查看How to Ask,现在回答您的问题需要有人为您完成任务,这不是该网站的目的。如果在此过程中,您遇到了某个特定点,请发布另一个有关它的问题,不要忘记包含minimal reproducible example。如果对可以询问的内容有疑问,请查看on-topic
  • 要计算增值税和费用,您可以简单地执行totalPlusVat = total * 1.13 totalPlusCharge = total * 1.1 或两者同时进行(总计 + 23%)total = total * 1.23
  • 或者服务费也包含增值税?所以total * 1.10 * 1.13(与乘以 1.243 或加上 24.3 %(不是 23 %)的结果相同)。
  • 我已经删除了这个问题的第二部分 - 先尝试解决增值税和服务税问题。

标签: java arrays variable-assignment


【解决方案1】:
    boolean cont = true;
    while(cont)
    {
        double total = 0;
        int[] choices = new int[5];
        for(int i = 0; i < 5; i++)
        {
            System.out.printf("Enter choice %d%n", i + 1);
            choices[i] = input.nextInt();
        }
        for(int choice : choices)
        {
            System.out.printf("%s | %.2f%n", FoodItem[choice], Price[choice]);
            total += Price[choice];
        }
        total = total * 1.23;
        System.out.println("Your total is: " + total);
        String ask = "";
        while(!ask.equalsIgnoreCase("yes") && !ask.equalsIgnoreCase("no"))
        {
            System.out.println("Continue? (yes/no)");
            ask = input.next();
        }
        cont = ask.equalsIgnoreCase("yes");
    }

请注意,如果用户输入了除数字以外的任何内容输入了您的Price 数组中不存在的选项,它将使您的程序崩溃。最好实施验证。

【讨论】:

  • 应该能够同时管理 5 个客户的订单和计费。如何编码?
  • @bikaspoudel 除非我误解了你的意思,我的例子就是这样做的;接受 5 个订单并计算总和,并在顶部加上税/增值税。
  • 程序应该打印 5 个客户的总账单。假设如果我点了食物,程序应该打印我的食物的总账单,还应该打印剩余 4 位客户的账单而不终止
  • 我想添加你想继续是/否?为 5 个客户生成账单后
  • 我想添加5张桌子,程序应该根据要求打印单个桌子的帐单,假设如果要打印桌子2的帐单那么应该显示桌子2的帐单,
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2013-06-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-08-01
相关资源
最近更新 更多