• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

int and double get methods

 
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi everyone, I have written the code to get Strings out of an arraylist, but I have encountered problems with int and double, clearly it is not done in the same way, below I have added an eg of the String get methods I have added, and work (phew!). Any help on how to write a similar method ot return a double or int would be greatfully received.

 
Ranch Hand
Posts: 132
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm not sure where you want to return the integer or double, but have you tried parsing the string to an integer and then checking for equality as you iterate through?
 
Lari Hopkins
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well I have worked out how to get an int, after much playing, but I am still stuck on the other part that I wanted to ask about. I want to be able to get a reg number after being given two pieces of data. I tried to modify my code to...



... but the top section clealy isn't right, as however I put the search make/SearhMake/searchMake etc it is not recognised. In the other methods the three lines look like...

 
lowercase baba
Posts: 13089
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i'm confused on what you are doing... Note that if you do this:

the second line overwrites what you got in the first line. Did you mean something like this:


Now, you can do this. you then have to define a getRegistration method that takes TWO strings as arguments. I am also assuming that the getReg method you pasted in is really getRegistration()???

These little details make a huge difference. You should get in the habit now of paying attention to things like that. Your life (and anybody who reads your code) will be much simpler if you are more accurate in saying what you mean.
 
Lari Hopkins
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ah sorry I must have missed out that last line...



is what I have, followed by the corresponding method (which is currently)...



However I am getting the errors cannot find symbol searchModel and searchMake, which is I think because they are in vehicle and not car, which I am referencing with the 'c.' before them, is there some way I am meant to declare them in car.java?
 
Nathan Leniz
Ranch Hand
Posts: 132
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
searchMake and searchModel are coming in as Strings. If you have get methods inside car to return the make and model, you could compare what those methods return to the strings searchMake and searchModel.
 
Ranch Hand
Posts: 122
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If i remember your classes correct, it has to be
 
fred rosenberger
lowercase baba
Posts: 13089
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

This still bothers me. It's still very early, but how is this what you need? you ask the user to "Enter make", and store that in the string Search. You then ask the user to "Enter model", and store that in the string Search, LOSING WHAT YOU JUST GOT FOR MAKE.

you then call a method, passing in two variables that I have NO idea what they are or where they came from: Searchmake and Searchmodel. These variables have appeared out of thin air, which is probably why the compiler is complaining.

When the compiler says "cannot find symbols", it should tell you on what line the mystery symbols are on. Look for that line, then see if those variables are defined somewhere in scope for that method (I can tell you that because of the error message, they are not). So, what do you really want to send into the method?
 
Anton Uwe
Ranch Hand
Posts: 122
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
As Fred already stated: The code sniplet he posted has to be changed to something like
, if you have those String references defined, else to
if you don't already defined these String reference variables.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic