aspose file tools*
The moose likes Beginning Java and the fly likes Very New (obviously) - Program terminates Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Very New (obviously) - Program terminates" Watch "Very New (obviously) - Program terminates" New topic
Author

Very New (obviously) - Program terminates

Lori Gardner-Wilson
Greenhorn

Joined: Jun 03, 2009
Posts: 11
Hello -

I am very new to Java and am working on a program for a class, but am having problems with it.

Basically, I want to be able to add Clients, lookup Clients and eventually modify Clients.

I'm working on the add and lookup functions now, but can't figure it out.

Any help would be greatly appreciated!!

Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18124
    
  39

I'm working on the add and lookup functions now, but can't figure it out.


First, welcome to the JavaRanch. What is it that you are having an issue with ?... You created a client object. You created a list. And you printed out that list -- whose printout told you there is one client object in it.

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18124
    
  39




Be careful here... Your "home" and "cell" phone parameters take an int value. "555-412-0432" is not an integer value -- it is an integer expression. Basically, Java will evaluate it to "555 minus 412 minus the value of 0432 (converted from octal to decimal)" and use the result of that.

Henry
Lori Gardner-Wilson
Greenhorn

Joined: Jun 03, 2009
Posts: 11
Thanks. I will do some research on which variable type to use for the phone numbers.

I guess my question is how do I return the list with the variables?



Thanks so much for the help.
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18124
    
  39

Lori Gardner-Wilson wrote:I guess my question is how do I return the list with the variables?


Well, it is already a list of client objects -- so I am assuming you mean how to see what clients are in those objects? Instead of just printing the list, you can iterate through the list to get the client objects -- which in turn, you can print the fields... like so...



Henry
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 36520
    
  16
If you are as new as you say you are, beware of a 154 line class. If you need a 154 line class, start with a 3-line class and compile it and test it by running. Then enlarge it to 7 lines, compile and run, then enlarge it to 11 lines . . . etc etc.
You will find programming much easier if you do it in tiny bits.
Fred Hamilton
Ranch Hand

Joined: May 13, 2009
Posts: 679
Henry Wong wrote:


Be careful here... Your "home" and "cell" phone parameters take an int value. "555-412-0432" is not an integer value -- it is an integer expression. Basically, Java will evaluate it to "555 minus 412 minus the value of 0432 (converted from octal to decimal)" and use the result of that.

Henry


I would like to suggest that unless the variable is going to be used in a mathematical expression of some kind, declare it as string.

Even if the OP did not include the dashes in the phone number, I'd still declare it a String, because it will never be included in any kind of mathematical expressions. Maybe this is just a question of style, you can make it work either way.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 36520
    
  16
I think you are correct about using a String, Fred.
Lori Gardner-Wilson
Greenhorn

Joined: Jun 03, 2009
Posts: 11
Thanks for all the help and suggestions!

I really appreciate it.

 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Very New (obviously) - Program terminates
 
Similar Threads
Values are assigning null
Deleting HashMap Key
Return object values from ArrayList
How Inheritance Affects Serialization
Deserialize and display an object's attributes in UI