Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

Help with vector

  Asked By: Arnold    Date: Jun 16    Category: Java    Views: 676

i desperatly need help with figuring out this problem with my uni

i am creating a vehicle hire program, so far you can add cars, view
information on certain cars and add a customer. however when
displaying the information about a certain car if that car is on loan
i need to display the customers information. the problem i am having
is that the customer information is only being displayed when all of
the cars in the vector are set to onloan. any help would be useful

here is some of my code.

public void addCar(String make, String regNo, String colour,
int noOfDoors, double totalMileage, double recordedMileage) {
carVector.addElement(new Car(make, regNo, colour,
noOfDoors, totalMileage, recordedMileage));

public void findCar(String regNo) {
int i = 0;
while(i < carVector.capacity()) {
car = (Car)carVector.elementAt(i); //temp
if(regNo.equalsIgnoreCase(car.getRegNo())) {
vehicleDetails = new VehicleDetails
(car.getMake(), car.getColour(), car.getRegNo(), car.getNoOfDoors(),
car.getTotalMileage(), car.getRecordedMileage(), car.getStatus());
if(car.onLoan == true)
customerDetails = new Customer
(customer.getName(), customer.getLicenceNo(), customer.getVector());

public void allocateCar(String name, int licenceNo, String regNo) {
customerVector.addElement(new Customer(name,
licenceNo, personalVector));
customer = (Customer)customerVector.elementAt(0);
int i = 0;
while(i < carVector.capacity()) {
car = (Car)carVector.elementAt(i);
if(regNo.equalsIgnoreCase(car.getRegNo())) {
car.onLoan = true;
//this will be removed
customerDetails = new Customer(customer.getName(),
customer.getLicenceNo(), customer.getVector());
//ideally needs error checking CAUSES NULLPOINTER EXCEPTION



1 Answer Found

Answer #1    Answered By: Sebastien Anderson     Answered On: Jun 16

Try looping through a Vector using the size() method rather than the
capacity() method. Hope this helps.

while(i < carVector.size()) {

Didn't find what you were looking for? Find more on Help with vector Or get search suggestion and latest updates.