-3

我已经开始了一些演示,它们都运行良好。我最近加强了复杂性,并编写了一个绘制程序,以公制和英制计算面积。虽然我没有收到任何编译错误,但当我尝试在 Eclipse 中运行该程序时,它错过了计算部分。希望有人可以提供帮助:

//program begin
package paintCalculation;

import java.util.Scanner;

public class PaintCoverageV1 
{

public static void main(String[] args)
{
    //Variables
    double roomArea = 0, roomHeightSq = 0, roomWidthSq = 0, coverage = 172.22, wastage = 1.10;
    double roomHeightRec, roomWidthRec, roomLengthRec;
    double totalpaintgallons = (roomArea / coverage) * wastage;
    double totalpaintlitres = totalpaintgallons * (4.54);
    double metresconversion = 10.7;
    char areaKnown, Y = 0, N = 0;
    char con, I = 0, M = 0;
    char roomType, S = 0, R = 0;


    //Heading
        System.out.println("Paint Coverage Calculator");

        Scanner keyboard = new Scanner(System.in);

    //areaKnown
        System.out.println("Do you know wall area? (Y for YES, N for NO)  ");
        areaKnown = keyboard.next().charAt(0);

            if (areaKnown == Y)
            {
            System.out.println("Enter room area  ");
            roomArea = keyboard.nextDouble();   
            }

            else if (areaKnown == N)
            {
            //roomType
            System.out.println("Enter room shape (S for Square, R for Rectangle)   ");
            roomType = keyboard.next().charAt(0);

                if (roomType == S)
                {
                System.out.println("Enter wall height   ");
                roomHeightSq = keyboard.nextDouble();

                System.out.println("Enter wall width   ");
                roomWidthSq = keyboard.nextDouble();

                roomArea = (roomHeightSq * roomWidthSq) * 4;
                }

                else if (roomType == R)
                {
                System.out.println("Enter wall height   ");
                roomHeightRec = keyboard.nextDouble();

                System.out.println("Enter wall length   ");
                roomLengthRec = keyboard.nextDouble();

                System.out.println("Enter wall width   ");
                roomWidthRec = keyboard.nextDouble();

                roomArea = ((roomHeightRec * roomWidthRec) + (roomLengthRec * roomHeightRec)) * 2;
                }   
            }
{
    //metricConversion

        System.out.println("Which conversion is required? (M = Metric, I = Imperial)");
        con = keyboard.next().charAt(0);

        keyboard.close();
        if (con == I)
        {
            System.out.print("Total amount of paint in gallon(s) required is " + totalpaintgallons);
            System.out.print("Total amount of paint in litre(s) required is " + totalpaintlitres);
        }
        else if (con == M)
        {
            coverage = coverage / metresconversion;
            System.out.print("Total amount of paint in gallon(s) required is " + totalpaintgallons);
            System.out.print("Total amount of paint in litre(s) required is " + totalpaintlitres);
        }
        }
}
}

//program end
4

1 回答 1

2

你需要改变

        if (areaKnown == Y)

        if (areaKnown == 'Y')

等等。

您当前的代码与areaKnownvariable 的值Y(为零)进行比较,而不是将其与 character 进行比较'Y'

于 2013-09-15T10:22:19.513 回答