aspose file tools
The moose likes Beginning Java and the fly likes int and double get methods Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Reply Bookmark "int and double get methods" Watch "int and double get methods" New topic
Author

int and double get methods

Lari Hopkins
Ranch Hand

Joined: Nov 23, 2006
Posts: 37
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.

Nathan Leniz
Ranch Hand

Joined: Nov 26, 2006
Posts: 132
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?


The very existence of flamethrowers proves that at some time, some where, some place, someone once said to themselves "I'd really like to set those people on fire over there, but I just can't get close enough".
Lari Hopkins
Ranch Hand

Joined: Nov 23, 2006
Posts: 37
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...

fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 9955
    
    6

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.


Never ascribe to malice that which can be adequately explained by stupidity.
Lari Hopkins
Ranch Hand

Joined: Nov 23, 2006
Posts: 37
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

Joined: Nov 26, 2006
Posts: 132
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.
Anton Uwe
Ranch Hand

Joined: Jan 10, 2007
Posts: 122
If i remember your classes correct, it has to be
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 9955
    
    6


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

Joined: Jan 10, 2007
Posts: 122
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: int and double get methods
 
Similar Threads
How to store method return type in primitive
creating a new object in an ArrayList
compiler error: cannot find symbol
Javadoc
Arraylist