After creating an array, I now need to pull info back out following a user request in simple IO. After a series of press one for this and that, the user types in a car registratio number. I am not sure how to call the car method and prompt it with the user input. Have I got my ideas completly confused?
This is the code in the main method:
and in the Car class
Please let me know if I have not posted enough code for context.
From reading what you have posted couldnt you just loop through the ArrayList of Car objects and check the getReg() of each car object to see whether it matches the user input and then pull that one back?
e.g.
Im am also a little bit confused to why you are creating another Car instance in the getReg() method in the Car class?
If i have missed something please say and i will try to help again,
thanks John, I can see what you are saying and when I do something with the car Ill print it in the console.
I'm getting complier error with ot recognising the variable cars in
[code] for (Car c : cars) { [/code/]
which is obviously because its not a variable I am using. However, I'm not really understanding what the for condition is describing for me to assign the correct variable. Could you advise?
Also, regards the additional car1 in car.java - it's just novice error i'm afraid!
thank you kindly. All is now understood. My array is referenced as carList so that has worked beautifully.
The compiler is now grumbling about static and non-static, but I notice someone has posted a topic about this, so i will take a look over there before repeating the question.
ahhh, it turns out the static/ non static post is a little old and above my head!
So, on the whole, my code seems to be taking better shape, however I'm getting the following compliler error
now, i'd think that I would also have to have the reg as a static variable, but that doesn't seem right as the reg variable is one of many populated throughout the array. Nevertheless, I tried fiddling about with static-ing bits and bobs, to no avail.