Java 壁画计算器。(两种解决方案-给出两种不同的结果)

Java 壁画计算器。(两种解决方案-给出两种不同的结果),java,Java,不久前,我开始学习JAVA,一切都进行得很顺利,直到我做了这个练习: 条件 编写一个程序,完成后将计算粉刷房间墙壁和天花板所需的油漆量 您的程序应该询问房间的长度、宽度和高度。假设房间有门和窗,不需要油漆。此外,房间里的地板也没有油漆 要求用户输入房间的门数和窗数,并相应地调整待涂漆的总平方英尺 假设每个门有20平方英尺,每个窗户有15平方英尺。 假设油漆每加仑350平方英尺。在这里输入代码 我选择的参数 我的解决方案 } } 输出为0.02857142 练习作者提出的其他解决方案 因此,两种不

不久前,我开始学习JAVA,一切都进行得很顺利,直到我做了这个练习:

条件 编写一个程序,完成后将计算粉刷房间墙壁和天花板所需的油漆量

您的程序应该询问房间的长度、宽度和高度。假设房间有门和窗,不需要油漆。此外,房间里的地板也没有油漆

要求用户输入房间的门数和窗数,并相应地调整待涂漆的总平方英尺

假设每个门有20平方英尺,每个窗户有15平方英尺。 假设油漆每加仑350平方英尺。在这里输入代码

我选择的参数 我的解决方案 } }

输出为
0.02857142

练习作者提出的其他解决方案 因此,两种不同的解决方案给出了两种不同的输出


有没有人能帮我澄清一下,我哪里出错了?

首先,
width*length*height
计算房间的体积,而不是表面积。其次,这是一个在运行时使用调试器并查看变量的绝佳机会。是的,我唯一需要做的就是编写一个正确的函数来计算表面积。无论如何,我觉得这是个愚蠢的问题,谢谢你的帮助
Width    3;
Length  10;
Height   2.0;
Doors    1;
Windows  2;
int width     = Integer.parseInt(JOptionPane.showInputDialog("Please, enter the width of a room"));
int length    = Integer.parseInt(JOptionPane.showInputDialog("Please, enter the length of the room"));
double height = Double.parseDouble(JOptionPane.showInputDialog("Please, enter the height of the room"));
int doors     = Integer.parseInt(JOptionPane.showInputDialog("If there are doors, please, enter the amount of them:"));
int windows   = Integer.parseInt(JOptionPane.showInputDialog("If there are some windows, please, enter the amount of them:"));

double feet   = 1.00/350.00;
double area   = (width*length*height)-(windows*15+doors*20);

JOptionPane.showMessageDialog(null, "You need:"+feet*area+" gallons of paint.");    
        public static void main(String[] args) {
    
        {
        int length, width, numberOfDoors, numberOfWindows;
        double height;
        
        Scanner console = new Scanner(System.in);

        System.out.print("Enter length: ");
        length = console.nextInt();
 
        System.out.print("Enter width: ");
        width = console.nextInt();
        
        System.out.print("Enter height: ");
        height = console.nextDouble();
        
        System.out.print("Enter number of doors: ");
        numberOfDoors = console.nextInt();
        
        System.out.print("Enter number of windows: ");
        numberOfWindows = console.nextInt();

        double totalSurfaceArea = 2 * (length * width + length
                * height + width * height);

        int areaOfFloor = length * width;
        
        int areaOfDoors = 20 * numberOfDoors;
        
        int areaOfWindows = 15 * numberOfWindows;
        
        double totalPaintArea = totalSurfaceArea - areaOfFloor
                - areaOfDoors - areaOfWindows;
        
        double requiredPaint = totalPaintArea / 350;

        System.out.println("Paint required "
                + requiredPaint + " gallons.");
      }
      }
      }
        The output is 0.09142857142857143;