Re: Arraylist
- From: "John W. Kennedy" <jwkenne@xxxxxxxxxxxxx>
- Date: Sun, 28 Jan 2007 20:54:27 -0500
chris1980 wrote:
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.
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.
--
John W. Kennedy
"The blind rulers of Logres
Nourished the land on a fallacy of rational virtue."
-- Charles Williams. "Taliessin through Logres: Prelude"
.
- Follow-Ups:
- Re: Arraylist
- From: chris1980
- Re: Arraylist
- References:
- Arraylist
- From: chris1980
- Re: Arraylist
- From: John W. Kennedy
- Re: Arraylist
- From: chris1980
- Arraylist
- Prev by Date: Re: altenatives for double is mathematical integer
- Next by Date: Re: How to detect blank input using Scanner?
- Previous by thread: Re: Arraylist
- Next by thread: Re: Arraylist
- Index(es):
Relevant Pages
|