this is for a intro programming class i am taking. I have created a Instance method to add a newValue
to the totals.
It has two parameters in the method:
(a letter identifying the amount type, and amount)
I was successful on the first parameter.
the second is making me struggle. I am suppose to us an if statement. I made it so there is amount type, then i have three letters that are to be used that can be true. I set the if(amountType == false)
and the compiler says its a "unreachable statement".
The criteria for the if statement is "If the letter for the amount the is invalid (i.e. not T, D, or E), throw an IllegalArgumentException, and message back to user.
public double newValue(boolean amountType, double amount)
{
boolean T = amountType;
boolean D = amountType;
boolean E = amountType;
if (amount < 0)
{
throw new IllegalArgumentException("The amount needs to be 0 or larger");
}
return amount;
if(amountType == false)
// if not D, E, T.....then exception
{
throw new IllegalArgumentException("That is an invalid letter value. "
+ "The data will be ignored");
}
else
{
}
}
Any help would be appreciated.