• Post Reply Bookmark Topic Watch Topic
  • New Topic

School question help asap!!  RSS feed

 
Martin vanPutten
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Heres a question thats stumping everybody in class. Can somebody help not only I, but my class?
Heres the question:

Exercise 2.72: The string clas defines a length accessor method with the following signature:
/**
* Return the number of characters in this string.
*/
public int length()
add conditional statement to the constructor of Student to print an error message if either the length of the fullName parameter is less than four characters or the length of the studentId parameter is less than three characters. However, the constructor should still use those parameters to set the name and id fields, even if the error message is printed.
Hint: use if statements of the following form (that is, having no else part) to print the error message.
if(perform a test on one of the parameters) {
Print an error message if the test gave a true result


Heres the code:

 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, I think you're a little confused in adding the "length()" method to this class; the problem is talking about your using a method by that name that's already defined in the String class.

Then the code in the Student constructor is terribly close to what I imagine the instructor wants, but go look at the Javadoc for String. Is there a public instance variable named "length"? How about a method by that name? Which are you trying to access in your constructor? Which should you be using?
 
Martin vanPutten
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Got it, thank you!!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!