我已经开始了一些演示都很好的演示。我最近加大了复杂性,并制定了一个以公制和英制方式制定该区域的油漆程序。虽然我没有得到任何编译错误,但当我尝试在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
答案 0 :(得分:2)
您需要更改
if (areaKnown == Y)
到
if (areaKnown == 'Y')
等等。
您当前的代码会将areaKnown
与变量Y
的值进行比较,该值为零,而不是将其与字符'Y'
进行比较。