![]() |
|
#1
|
|||
|
|||
Question with accessorsHey guys, i'm writing a program that creates an of N objects, where N is a number the user inputs. You can then change and access any attributes of the N objects, but I don't want the program to throw an exception and close out when the user elects to change something that doesn't actually exist. For example, creating N objects, then trying to access the N+4th object.
I would like something like the following to work, though i cannot seem to figure out how to make such a thing occur JAVA Code:
Thanks in advance guys |
|
#2
|
||||
|
||||
Re: Question with accessorsCan you post more code for what you have, to get a better picture?
Where is size set? What if index < 0, then what happens? Are you getting errors now, if so, what are they? (post them all) etc... __________________
Use the force...read the source!! WYCIWYG -- what you code is what you get! |
|
#3
|
|||
|
|||
Re: Question with accessorsAbsolutely, here is the code in full, i'm working on commenting currently, along with trying to clean it up, so it's a bit messy, but i'm using BlueJ for the program. It's probably not the most robust program as i'm only a few weeks deep into my first java course.
HeaterControl JAVA Code:
Heater JAVA Code:
The error that pops up is just that i'm trying to access an element of the array that doesn't exist (which i expected to pop up) i'd just rather it didn't pop up. I'm supposed to deal with out of bounds errors "gracefully" |
|
#4
|
|||
|
|||
Re: Question with accessorsAlso, you've made a good point; I'd like index to be within certain bounds
atleast zero would be needed as well as below size |
|
#5
|
||||
|
||||
Re: Question with accessorsDo you have a post for the 'driver' file? There's not a main (unless it was taken out during the 'clean-up' ) in either file, so it would be easier work with what you have.
__________________
Use the force...read the source!! WYCIWYG -- what you code is what you get! |
|
#6
|
|||
|
|||
Re: Question with accessorsThere actually is no main :-/, In blueJ i've got to create in instance of heaterControl and test things through that... But i think i have figured it out, i'll post the code later today
|
|
#7
|
||||
|
||||
Re: Question with accessorsYou're right, an instance is all that's needed, but since there isn't any output, I didn't bother trying to 'slap' something together.
__________________
Use the force...read the source!! WYCIWYG -- what you code is what you get! |
Recent GIDBlog
Stupid Management Policies by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Borland compile question | monnick | C++ Forum | 4 | 12-Feb-2006 18:40 |
| non-member function question | crq | C++ Forum | 1 | 03-Feb-2005 22:59 |
| Simple question on arrays--please help! | brookeville | C++ Forum | 16 | 18-Nov-2004 00:23 |
| Repetition structure problem and question | brookeville | C++ Forum | 17 | 29-Oct-2004 18:48 |
| question of practice | magiccreative | C++ Forum | 1 | 06-Feb-2004 08:17 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The