Hi it's me again, I've pretty much finished a program I'm making, which does the following:
The program is for a garage, and it does the following functions:
Adds a new car
Display cars
Amend price of a car
Delete car ('sell' car)
Find a certain car
Almost everything is working perfect, except that I can't get the 'delete'f unction working correctly.
All the cars data is stored in a text file, like so:
When the program is loaded, the text file data is converted into objects so I can manipulate them. When manipulation is finished, the data is written back to the text file.
For some reason, my 'delete' functions only works if you delete the last entry in the text file, any other and I get a NullPointerExce ption error...Any ideas? Here is my code for the sellCar method.
The program is for a garage, and it does the following functions:
Adds a new car
Display cars
Amend price of a car
Delete car ('sell' car)
Find a certain car
Almost everything is working perfect, except that I can't get the 'delete'f unction working correctly.
All the cars data is stored in a text file, like so:
Code:
V40GOR Vauxhall Omega 2 1998 1000 R45GER BMW Ver2 1995 1000
For some reason, my 'delete' functions only works if you delete the last entry in the text file, any other and I get a NullPointerExce ption error...Any ideas? Here is my code for the sellCar method.
Code:
public void sellCar() throws IOException { if (activeCars != 0) { regFound = false; delRegNo = Text.readString("Please enter the registration number of the car you wish to sell."); while(search < activeCars && delFound == false){ if(carDetails[search].getRegNo().equalsIgnoreCase(delRegNo)) { delFound = true; regFound = true; } else { search++; } } if (delFound == true) { correct = Text.readChar("Here are the details of the car to be deleted: \n" + "Manufacturer: " + carDetails[search].getManufacturer() + "\n" + "Model: " + carDetails[search].getModel() + "\n" + "Registration No: " + carDetails[search].getRegNo() + "\n" + "Year: " + carDetails[search].getYear() + "\n" + "Price: £" + carDetails[search].getPrice() + "\n" + "\n" + "Are these details correct? If so, press Y or y"); if (correct == 'Y' || correct == 'y') { carDetails[search] = null; activeCars--; System.out.println("Deleted."); delFound = true; } else { delFound = false; } } } else { Text.showMessage("There are no car details in the database."); } correct = '?'; }
Comment