I'm programming in Java.
I have added comments to every method to explain what they're supposed to do (according to the assignment). I have added what I know to the stub of Password.java
(which I created after researching a javadoc provided by the school).
My question is not about several functions, I know there are mistakes in testWord and setWord, but I'll handle that myself.
My question is about this line:
public static final java.lang.String INITIAL;
This line is provided by the school, so I gotta assume that it is correct, I cant find any documentation anywhere about the constant field value INITIAL, so if anyone could provide me with info on that that would be amazing (eg. how is is handled? what does it store? if anything? type?). Also Im getting an error on this line in Eclipse:
The blank final field INITIAL may not have been initialized
Why is this error here? Thanks in advance about the comments.
FYI the code from Password.java:
package ss.week1;
public class Password extends java.lang.Object {
// ------------------ Instance variables ----------------
/**
* The standard initial password.
*/
public static final java.lang.String INITIAL;
// ------------------ Constructor ------------------------
/**
* Constructs a Password with the initial word provided in INITIAL.
*/
public Password() {
}
/**
* Tests if a given string is an acceptable password. Not acceptable: A word
* with less than 6 characters or a word that contains a space.
*
* @param suggestion
* @return true If suggestion is acceptable
*/
// ------------------ Queries --------------------------
public boolean acceptable(java.lang.String suggestion) {
if (suggestion.length() >= 6 && !suggestion.contains(" ")) {
return true;
} else {
return false;
}
}
/**
* Tests if a given word is equal to the current password.
*
* @param test Word that should be tested
* @return true If test is equal to the current password
*/
public boolean testWord(java.lang.String test) {
if (test == INITIAL) {
return true;
} else {
return false;
}
}
/**
* Changes this password.
*
* @param oldpass The current password
* @param newpass The new password
* @return true if oldpass is equal to the current password and that newpass is an acceptable password
*/
public boolean setWord(java.lang.String oldpass, java.lang.String newpass) {
if (testWord(oldpass) && acceptable(newpass)) {
return true;
} else {
return false;
}
}
}