So, I have an assignment question for assignment of certain variables in a parliament class. I kept it as basic as possible, but when I create a subclass called, say, CanadaParl it doesn’t let me change any of the String fields. Int fields work fine. For the Strings it keeps saying Error: cannot find symbol = variable Bob (where Bob is the String I’m trying to enter as the name of the PM field). I’m using BlueJ for my coding interface.
This is an example of the method in the Class:
public void changePM(String newPM) {
primeMinister = newPM;
}
Would this be the wrong way to go about update to a new String? I was just using a previous example for changing fields I saw, but I can’t remember if it had a String included in it or not.
Edit: Sorry for the mixup. I wasn’t paying attention initially and copied the int methods. The methods where the subclass changes the int values are working, but the String changes give the error above.
Here’s the whole class:
public class Parliament
{
int members = 0;
int parties = 0;
public String primeMinister = "";
public String oppLeader = "";
public String speaker = "";
boolean inSession = false;
boolean majority = true;
public void changeMembers(int newValue) {
members = newValue;
}
public void changeParties(int newValue) {
parties = newValue;
}
public void changePM(String newPM) {
primeMinister = newPM;
}
public void changeOL(String newOL) {
oppLeader = newOL;
}
public void changeSpk(String newSpk) {
speaker = newSpk;
}
}
Are you quoting your string ? For example, is Bob entered as “Bob” in your graphical user interface? The “cannot find symbol” seems to indicate that you might not be.
This might also explain why primitives work.