I have this part of my code so far. It compiles fine and runs fine. But If I choose to insert a Rank that isn't in the list it still prints the value that I input.
private String Rank; //string r
private static String[] Ranks = {"Assistant", "Associate", "Full"};
public professor(String n, int a, int s, String r, int nc, int pp)
{
super(n, a, s);
setRank(r);
setNumCo(nc);
setPubPaps(pp);
}
//mutator to set the Rank and check to make sure it is in the string list
public void setRank(String r)
{
boolean check = false;
List valid = Arrays.asList(this.Ranks);
if(valid.contains(r))
check = true;
if(check = true)
this.Rank = r;
else
this.Rank = "Associate";
}
Here's an example of what I'm talking about:
professor p2 = new professor ("Muench", 50, 222344455, "False", 3, 45);
"False" is definitely not in the list of ranks but it will still print as follows in my print window False professor Muench....
if(check = true)What do you think happens here?check. Simply use the actual conditionvalid.contains(r)in the secondifenumto represent the rank. The method collapses to a simple assignment (and maybe a null check).