• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Bear Bibeault
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Jj Roberts
  • Tim Holloway
  • Piet Souris
Bartenders:
  • Himai Minh
  • Carey Brown
  • salvin francis

Very New (obviously) - Program terminates

 
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!!

 
author
Posts: 23887
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux 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
Posts: 23887
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux 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
Posts: 23887
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux 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
 
Marshal
Posts: 71055
291
  • 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.
 
Ranch Hand
Posts: 686
  • 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
Marshal
Posts: 71055
291
  • 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.

 
rubbery bacon. crispy tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic