0
的部分当我使用||时,布尔运算结果为FALSE OR或&&和JAVA
static boolean isBagFull = ((!Bag.itemSlot1.equals("Empty"))||(!Bag.itemSlot2.equals("Empty"))||(!Bag.itemSlot3.equals("Empty"))||(!Bag.itemSlot4.equals("Empty"))||(!Bag.itemSlot5.equals("Empty")));
总是变成假的!请帮忙!虽然我检查了所有的itemSlots,他们都是 “空”
static Bag bag = new Bag();
static String helmet = "";
static String chestplate = "";
static String leggings = "";
static String boots = "";
static boolean isBagFull = ((!Bag.itemSlot1.equals("Empty"))||(!Bag.itemSlot2.equals("Empty"))||(!Bag.itemSlot3.equals("Empty"))||(!Bag.itemSlot4.equals("Empty"))||(!Bag.itemSlot5.equals("Empty")));
public void removeArmour(String s, int b){
if (b==1&&!helmet.equals("")) {
if (!isBagFull){//ITS USED HERE GUYS!!!!!!!!!!!!!!!!!! HELP!!!!!
bag.newItem(s);
helmet = "";
}else{
JOptionPane.showMessageDialog(null, "You do not have any room to remove the "+s);
}
}else if (b==2&&!chestplate.equals("")){
if (!isBagFull){
bag.newItem(s);
chestplate = "";
}else{
JOptionPane.showMessageDialog(null, "You do not have any room to remove the "+s);
}
}else if (b==3&&!leggings.equals("")){
if (!isBagFull){
bag.newItem(s);
leggings = "";
}else{
JOptionPane.showMessageDialog(null, "You do not have any room to remove the "+s);
}
}else if (b==4&&!boots.equals("")){
if (!isBagFull){
bag.newItem(s);
boots = "";
}else{
JOptionPane.showMessageDialog(null, "You do not have any room to remove the "+s);
}
}else if (b>=5||b<=0){
JOptionPane.showMessageDialog(null, "Sorry you don't have the correct position!", "ERROR", 0);
JOptionPane.showMessageDialog(null, "Helmet = 1 \n Chestplate = 2 \n Leggings = 3 \n Boots = 4", "Armour Numbers", 0);
}else{
JOptionPane.showMessageDialog(null, "You ar not wearing anything there!");
}
}
你需要将代码发布到Bag类,这可能比这里的任何事情都要多得多。 – Tibrogargan
请学习使用数组。任何时候你有像'itemSlot1','itemSlot2','itemSlot3'这样的变量,这就是你需要使用一个数组来代替所有变量分开的标志。 – ajb
是的,我在这篇文章后才刚刚开始做这个工作!谢谢!! @ajb –