• Post Reply Bookmark Topic Watch Topic
  • New Topic

Requesting help in understanding questions asked for project. Code and details inside  RSS feed

 
Mack Grill
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

I'm making a PhoneBook class and I was hoping someone could clarify what these instructions are asking


INSTRUCTIONS:

"A setNumber() method that takes a String as a phone number and an int as an index number for parameters. Set the phoneNumber array at index to equal the String parameter. Return true if the index is in bounds of the phoneNumber array and the data was set. Return false if the index is out of bounds.

A getRecord() method that takes an index number of a record (array slot). Look up the record at that index in the name and phoneNumber arrays. Return a new String array with the record's name in element 0 and the person's phone number in element 1. If the index number is out of bounds or if the record contains no valid data, return null. This method returns either a two element String array or null.

A nextIndex() method returns the next index in the name array that contains null. If no element in the array is null, return -1 as a flag indicating there are no empty slots in the name array. This method can be used by another program to find the nextIndex() in the PhoneBook class where data may be stored without overwriting current data.

A getRecord() method that overloads your other getRecord() method. This method needs to take a String as a parameter that represents the name of a person you want to get the record of. It should return the index number of that record. Your search of the array should be case insensitive. There are methods in the String class that can help with this. Remember to check for a null value before trying to access data in the array element. Return -1 if the record is not found."



Here is my code so far:


PhoneBook Class:




Main Class:




Note: I am only working with one PhoneBook entry right now just to see if I can get it working.
 
Winston Gutkowski
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mack Grill wrote:I'm making a PhoneBook class and I was hoping someone could clarify what these instructions are asking

Well, just taking the first paragraph:

Instruction:
"A setNumber() method that takes a String as a phone number and an int as an index number for parameters...Return true if the index is in bounds of the phoneNumber array and the data was set. Return false if the index is out of bounds."

Your code:
public setNumber() {
   return;
}


Quite apart from the fact that it won't compile:
What does this method take (ie, what are its parameters)?
What does it return?
From the instructions, what do you think it should return?

You already have some examples of properly defined methods; so use them to change the method definition so that it matches the instructions. Then do the same thing for the methods requested in the other paragraphs. When you've done that, come back and we'll continue.

Winston
 
Campbell Ritchie
Marshal
Posts: 56599
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So why haven’t you got a Record class in that code? Not only are paired arrays error‑prone and poor design, they are not taking a Record class. If you have getRecord methods, you ought to have a record somewhere to get.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!