I have not used java in quite a while and I am getting a little frustrated with this… It always returns -99 but I don’t know where the logic is wrong.
public static void main(String[] args){
System.out.println(shippingCost('P',10));
}
public static int shippingCost(char packageType, int weight)
{
String e1 = "Legal Values: Package Type must be P or R";
String e2 = "Legal Values: Weight < 0";
int cost = 0;
if((packageType != 'P')||(packageType != 'R'))
{
//throw new Exception(e1);
return -99;
} else {
return -1;
}
Your if() should be using an
AND. Since it’s anORnow, it is ALWAYS true that your packageType is neither P or R.