Ok, so this is my first post. Firstly I've been trying to solve this problem on my own but it's been hours and I'm still lost. I've tried searching the web and nothing specific enough comes up. Here is the requirements for the project:
- the class must contain a private instance field of type int and named checkNumber .There should be no explicit initialization where the field is declared.
- It must provide a no-parameter constructor that initializes the value of the checkNumber field to 23.
- It must provide a public method named setCheckNumber that takes one parameter of type int, sets the value of the private field to the value of the parameter, and has no return value. 5. It must provide another a public method named firstLastCheck that takes an ArrayList as its parameter and returns a boolean value. If the initial or last value in the list is equal to the value in the instance field checkNumber then the method returns true; otherwise it returns false. The method may assume that the parameter is a list containing at least one element; that is, it is not the empty list and it is not null.
Here is what I have so far:
public class BasicsA {
//fields
private int checkNumber;
//constructor to initialize fields
public BasicsA() {
//initialize checkNumber
checkNumber = 23;
}
//method to take input and change checkNumber
public void setCheckNumber(int nextNumber) {
checkNumber = nextNumber;
}
//method to return boolean value
public boolean firstLastCheck(ArrayList<Integer>) {
}
}
Now, I have tried changing all sorts of things. Like using firstLastCheck(nameofArrayVariable). Usually it wants an identifier, but if I get it working it simply cannot return an Array int as boolean. It also confuses me that there is no instruction to first create the array or define it as a field.
Also how can it check the first and last array elements when there is no elements in the array yet either? You would think the checkNumber would pass the new int into the array, but it doesn't say to do this.
Sorry I hope I haven't overcomplicated this.
EDIT:
public boolean firstLastCheck(ArrayList<Integer> listInt) {
if(listInt.get(0) == checkNumber || listInt.get(listInt.size() - 1) == checkNumber) {
return true;
} else {
return false;
}
}
So how can I check this using the BlueJ IDE? I don't understand what it wants?