Dave Tolls wrote:Where are those three Strings supposed to be used?
Worth to mention, that it is not a compile time error. It is a warning. And it means what it says, that you have declared those variables: string1, string2... but you never use them in your class (any setter or getter or any other method). That I'd consider as a smallest issue you're facing now.lee shotwell wrote:My compiler informs me that private String string1, private String string2, and private String string3 states: The field TripleString.string1 is never read locally. Same message for string2 and string3.
No it doesn't. It does not dereference name but “this”. I will not cause an exception to be thrown, but will return null and assign that to name. In fact it is equivalent toFred Kleinschmidt wrote:. . . Third, getname() dereferences the instance variable "name" that hasn't been set yet, so will cause a NullPointerException.
Dave Tolls wrote:getName calls toString on name, so it will cause a null pointer exception.
Of course it should simply return name.
lee shotwell wrote:The spec. wanted me to instantiate some objects (at least four) to test various aspects of the app. I picked these objects because I wanted some variety to test (string, int, char). I could have picked a duck or a donkey. I was free to select the objects I wanted to use. I hope the above clears up some of the confusion. I value your input and would appreciate further suggestions from you.
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
All things are lawful, but not all things are profitable.
The requirements has some inaccuracy, as some stated above for instance. Keep in mind for the future, that based on such requirements you can't have default constructor. You can have at best "no argument" and "with parameters" constructor. Default constructor being provided by compiler only if there is no user defined constructor (ok, I could sound as being too picky, but that is how actually is). Since you were asked to provide one constructor with some parameters, the other could be no argument constructor (created also by you, not a compiler anymore), but it is no longer called default. I am telling you this in case you'd be up to go for a some certain certifications, so you wouldn't slip therelee shotwell wrote:Default Constructor
TripleString() -- a default constructor that initializes all members to DEFAULT_STRING.
Parameter-Taking Constructor
lee shotwell wrote:JUNILU LACAR & LUTAURAS VILDA: In the instructions I posted there is a section called The Foothill main() wherein it asks me to instantiate four or more TripleString objects. I selected, the objects name, age, gender, and occupation. Since that is not correct, what TripleString objects ( four or more) should I be instantiating? I am confused.
lee shotwell wrote:JUNILU LACAR & LUTAURAS VILDA: In the instructions I posted there is a section called The Foothill main() wherein it asks me to instantiate four or more TripleString objects. I selected, the objects name, age, gender, and occupation. Since that is not correct, what TripleString objects ( four or more) should I be instantiating? I am confused.
I have seen that sort of thing before. A class with three fields should have all three initialised in its constructor. A no‑arguments constructor is at variance with that principle. Unfortunately if that sort of thing appears in the assignment instructions, you are stuck with itLiutauras Vilda wrote:. . .
4. No argument constructor
5. Constructor with 3 parameters (strings)
. . .
Campbell Ritchie wrote:
I have seen that sort of thing before. A class with three fields should have all three initialised in its constructor. A no‑arguments constructor is at variance with that principle. Unfortunately if that sort of thing appears in the assignment instructions, you are stuck with itLiutauras Vilda wrote:. . .
4. No argument constructor
5. Constructor with 3 parameters (strings)
. . .![]()
TripleString() -- a default constructor that initializes all members to DEFAULT_STRING.
Requirements wrote:TripleString(String string1, String string2, String string3) -- a constructor that initializes all members according to the passed parameters. It has to make use of the private helper method validString() to be sure each String satisfies the class requirement for a member String. If any passed parameter does not pass the test, a default String should be stored in that member.
Requirements wrote:All legal strings should be between 1 and 50 characters.
Requirements wrote:MAX_LEN and MIN_LEN...use these static members in the TripleString method whose job it is to test for valid strings...
Campbell Ritchie wrote:
It is no good “rewrit[ing]” things, or “fiddl[ing] around with the app”. You can do that for millions of times and, most probably, one of those million will be correct. Or you can plan a strategy and design and get it to work first time. That constructor I mentioned looks as though you had been guessing.
You misinterpreting that part.lee shotwell wrote:2. I can load three strings, but not four.The instructions call for four or more.
That means:Instructions wrote:Instantiate four or more TripleString objects.
The Foothill main()
...
Do two explicit mutator tests for each, call a mutator in an if/else statement which prints one message if the call is successful and a different message if the call fails.
All things are lawful, but not all things are profitable.
Anderson gave himself the promotion. So I gave myself this tiny ad:
The Low Tech Laboratory Movie Kickstarter is LIVE NOW!
https://www.kickstarter.com/projects/paulwheaton/low-tech
|