当我只需要参数toBePainted
时,此代码要求两次相同的问题public static int getToBePainted(){
//Gets the rooms square footage
int height = 0;
String heightString = "";
int width = 0;
String widthString = "";
int length = 0;
String lengthString = "";
int toBePainted = 0;
heightString = JOptionPane.showInputDialog(" What is the hieght of the ceiling in feet: ");
widthString = JOptionPane.showInputDialog("What is the width of the room in feet: ");
lengthString = JOptionPane.showInputDialog("What is the length of the room in feet: ");
height = Integer.parseInt(heightString);
width = Integer.parseInt(widthString);
length = Integer.parseInt(lengthString);
toBePainted = Math.round((((length * width) * 4) + (height * width)) - (6));
return toBePainted;
}
public static int getBaseAmmount(){
int squareFeet = getToBePainted();
int baseAmmount = 0;
int gallons = 0;
gallons = (squareFeet / 400);
if (gallons < 1) {
gallons = 1;
}
baseAmmount = (gallons * 30);
return baseAmmount;
}
我只需要从getToBePainted获得答案而不是整个函数。