• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Very New (obviously) - Program terminates

 
Lori Gardner-Wilson
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Marshal
Pie
Posts: 21443
84
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Henry Wong
author
Marshal
Pie
Posts: 21443
84
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator



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
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Marshal
Pie
Posts: 21443
84
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 49864
70
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 684
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 49864
70
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think you are correct about using a String, Fred.
 
Lori Gardner-Wilson
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for all the help and suggestions!

I really appreciate it.

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic