aspose file tools*
The moose likes Beginning Java and the fly likes need help with this project please Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "need help with this project please" Watch "need help with this project please" New topic
Author

need help with this project please

daniel zona
Greenhorn

Joined: Oct 11, 2011
Posts: 1

* You will be creating a cell phone application with two class files, the CellPhone class which dials cell phone numbers entered by a user or numbers entered into memory; and the Memory class which assigns and returns nine (9) phone numbers stored in memory.

* The outline for the Memory class is displayed below:


* Add a new void mutator method storeMemory() to the 'Memory' class that stores a phone number into one of the memory fields; this method takes two parameters: (1) memoryDigit, an int, which is the location in which the phone number is to be stored (valid values are 1 through 9); and (2) memoryNumber, a String, the phone number to be stored; use "if" testing for memoryDigit and store the phone number as follows: if memoryDigit = 1, assign memoryNumber into the memory1 field; if memoryDigit = 2, assign memoryNumber into the memory2 field; etc.; if memoryDigit is not a value between 1 and 9, do not store the phoneNumber but display an error message to the terminal window

* Add a new accessor method getMemory() of type String to the 'Memory' class that retrieves a phone number from one of the memory fields; this method takes a single parameter memoryDigit, an int, which is the location from which the phone number is to be retrieved (valid values are 1 through 9); if memoryDigit = 1 return the value stored in the memory1 field, if memoryDigit = 2 return the value stored in the memory2 field, etc.; if memoryDigit is not a value between 1 and 9, return an empty string and display an error message to the terminal window

* The outline for the CellPhone class is displayed below:


* Add a new void mutator method setPhoneNumber() to the 'CellPhone' class that stores a string to the phoneNumber field; this method takes a single parameter phoneNumber, a String, which is assigned to the phoneNumber field.

* Add a new void mutator method setToMemory() to the 'CellPhone' class that stores a string to one of the memory fields stored in the mem object instantiated from the 'Memory' class; this method takes two parameters: (1) memoryDigit, an int, which is the location in which the phone number is to be stored; and (2) memoryNumber, a String, the phone number to be stored; both of these parameter variables are passed in a call to the storeMemory method of the 'Memory' class.

* Add a new void mutator method getFromMemory() to the 'CellPhone' class that stores a string to the phoneNumber field; this method takes a single parameter memoryDigit, an int, which is the location in the mem object of the class 'Memory' from which the phone number is to be retrieved; the method calls the getMemory method of the 'Memory' class; if the return value is not an empty string assign it to the field phoneNumber.

* Add a new accessor method getPhoneNumber() of type String to the 'CellPhone' class that returns the phoneNumber field.

* Add a new accessor method connect() of type String to the 'CellPhone' class; if the current value of the field phoneNumber = empty string, return a string message asking the user to dial a number first (to call either setPhoneNumber or getFromMemory method); if the current value of the field phoneNumber != empty string, return the phoneNumber field by calling its accessor method.
Matthew Brown
Bartender

Joined: Apr 06, 2010
Posts: 4387
    
    8

Hi Daniel. Welcome to the Ranch!

That looks suspiciously like homework, and we don't just hand out homework answers here - this site is all about helping you learn, and giving you an answer doesn't help you. So the best idea is if you have a good attempt yourself, and then you can ask much more specific questions when you get stuck.

As a starting point, the question gives you very specific instructions on what methods are required, and what they should do. So create your classes, add those methods (with no content as a starting point - just returning dummy values to begin with) and get it to compile. Once you've done that, work on one method at a time (I'd suggest writing very short programs to check that they work).
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38777
    
  23
Welcome again.

MB has given some really useful advice. One thing, you should ask why the nine numbers are stored in memory as individual fields rather than an array or List. Have you not learnt about arrays yet?
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38777
    
  23
daniel zona wrote: . . .
. . .
That is mistaken. If you have an empty constructor, the Strings will all be initialised to null. This is potentially hazardous, because using methods on any of those Strings will cause a NullPointerException. You might do well to query that, and to initialise all those Strings to "", which is an empty String.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: need help with this project please