有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

在数组中存储“inputdialog”数据的java

我编写了一个Java菜单控制台,它要求用户选择一个选项。我已经成功地编译了菜单系统,它接受用户的输入并将他们引导到菜单页面。第一页使用“输入对话框”询问2个问题

下面是“InputDialog”的代码,当我运行java控制台时,我可以访问并将信息输入到这些框中

private void enterInfor()
{
    String carInfo;
    int carHours;
    int i = 0;
    double fee = Double.parseDouble("7.50");
    double sum = 0;

    {
        carInfo = JOptionPane.showInputDialog("Please enter the license plate of the car");
        carHours = Integer.parseInt(JOptionPane.showInputDialog("Enter the number of hours the car was parked (1-12):"));

            System.out.printf("\n");
            System.out.printf("Details for car 1 entered:\n");
            System.out.printf("License plate   Hours      Fee:\n");
            System.out.printf(""+carInfo+"           "+carHours+"         $");
                    if (carHours == 1)
                        System.out.printf("%3.2f",fee*(carHours));
                    else if (carHours == 2)
                        System.out.printf("%3.2f",fee+4.50);
                    else if (carHours >= 3)
                        System.out.printf("%3.2f",3+(carHours*4.50));
            System.out.printf("\n\n");
    }
}

我有“String”和“int”信息来存储用户输入的信息,但是我需要程序来存储至少20个不同的输入,这些输入稍后可以在控制台中访问

我已经成功地进行了控制台重复信息,然后使用for循环输出组合答案=

"for(int Num=1; Num <= 6; Num++)" 

这允许我重复一组问题,然后将信息编译成统计数据,但对于这个控制台,我需要“InputDialog”一次只接收一组答案,然后将用户返回到初始控制台菜单

如果这些信息或格式都很模糊,我再次感到抱歉,只是需要一些关于如何/在何处放置正确代码的帮助


共 (0) 个答案