object - java method boolean returning false when its suppose to be true -
i making method in 1 class. have doubled checked , , should work accordingly. when run object in main method using method false homecoming though suppose true.
the print statements don't print can't check whether values beingness passed in , tried making if statement homecoming true , still returns false! doing head in logically correct.
is there rule don't know boolean method automatically homecoming false if somethings wrong?
public boolean addpartsdetails (string newdescription, double newcost) { system.out.println("is description empty?: " + newdescription); system.out.println("is cost negative?: " + newcost); if (newdescription.isempty() | newcost < 0) { homecoming false; } else { this.partscost += cost; string newpart = string.format("\t - %s (%.2f) \n", description, cost); this.partslist = this.partslist.concat(newpart); homecoming true; } }
in main method:
boolean addbool = tempobj.addpartsdetails(partdes, partcost); if(addbool) { system.out.println("\npart details recorded sucessfullyfor vehicle \"" + tempobj.getregnum() + "\""); } else { system.out.println("\nerror - invalid part details supplied!"); }
i believe want utilize || instead of | here:
if (newdescription.isempty() | newcost < 0) {
change to
if (newdescription.isempty() || newcost < 0) {
|
used bitwise or operation while ||
used conditional or
java object methods boolean
No comments:
Post a Comment