ok thanks for the code. i know now what you did and what i was doing
wrong. i was getting confused in how to store the car added by the
user?. though arraylist looks good to me but have never used one. so
still i am going to have problems in creating a method for deleting a
car and viewing the car. any good explanation on how should i acheieve
this goal? i am just writing this program to test my java skills. yes
i got through in reading the first book for java.
Thanks
> ok thanks for the code. i know now what you did and what i was doing
> wrong. i was getting confused in how to store the car added by the
[quoted text clipped - 3 lines]
> this goal? i am just writing this program to test my java skills. yes
> i got through in reading the first book for java.
You want to add additional methods to the CarList class, one to delete,
and one to list.
Before doing this, you have to think about how you want to do the
delete. Without a significant redesign, about the only thing you can do
is A) list everything, including a number, and B) delete based on the
number listed. (In a GUI application, you would use a checkbox instead.)
Or, of course, you could ask for make, model, and year, and then scan
through everything -- but in a real application, it's rather peculiar to
ask for the user to enter the entire content of a record in order to
designate it for deletion. In order to do it otherwise, you'll have to
think of some way to pick one Car from another other than by place in
the list.
Also, the way it is now, with the dialog in the Car constructor, is
very, very unusual. It would be more usual to read the data as part of
the main, and then call a constructor with profile:
Car (String make, String model, String year) { ... }
To go further, the actual variables in the Car object should be private,
and new getMake, getModel, getYear methods should be added.

Signature
John W. Kennedy
"The blind rulers of Logres
Nourished the land on a fallacy of rational virtue."
-- Charles Williams. "Taliessin through Logres: Prelude"
chris1980 - 29 Jan 2007 15:52 GMT
John. thanks for a great explanation. I am glad someone was able to
take his time out and explain me a little much better. so what you
trying to say is :
class Car
{
private String make;
private String model;
private String year;
public Car (String mk, String md, String yr) {
this.make = mk;
this.model = md;
this.year = yr;
}
public String getMake() {
return make;
}
public String getModel() {
return mode;
}
public String getYear() {
return year;
}
I think i am getting the idea of a good encapsulated program. i will
post back if i get stuck. i have good knowledge of java not very good
but good but very new to Arraylist. i thought of using arrays but when
i read the Api arraylist sounds good to me. Thanks alot Kennedy :).