object storing in java vector class

  • Thread starter Christos Kalogeropoulos
  • Start date
C

Christos Kalogeropoulos

Hi, I have writen the class bellow in order to create objects store
inforation about vehicles.

import java.io.*;
import java.util.Vector;

public class VehicleList extends Vector
{
static BufferedReader keyboard = new BufferedReader (new
InputStreamReader (System.in));

public VehicleList() {
super();

}

public void addVeh() throws IOException{
String confirm;
int vRegNo;
String vMake;
String vModel;
int veClass;
int vSml;
//start of do-while loop

do {

System.out.print("Input the Vehicle Registration Number :");
vRegNo=Integer.parseInt(keyboard.readLine().trim());
System.out.print("Input the Vehicle Make: ");
vMake=keyboard.readLine();
System.out.print("Input the Vehicle Model: ");
vModel=keyboard.readLine();
System.out.print("Input the Vehicle Drive Class:");
veClass=Integer.parseInt(keyboard.readLine().trim());
System.out.print("Input the Vehicle Seats/Maxload:");
vSml=Integer.parseInt(keyboard.readLine().trim());

Vehicle regVehicle= new Vehicle (vRegNo,
vMake,vModel,veClass,vSml);
add(regVehicle);

System.out.print ("Add a new vehicle (y or n)? ");
System.out.flush();
confirm= keyboard.readLine();

} while (confirm.equals("y")); //end of do while loop
}

public Object getVehicle(int index)
{

return get(index);
}

public Vehicle lookUpV (int accnos) throws IOException
{

//start of for loop

for(int i=0;i<size();i++)
{

//checks if the information entered are correct using an if
statement

if((((Vehicle)get(i)).getRegNo()) == accnos)
return ((Vehicle)get(i));

}

return null;

}

//Remove a vehicle

public boolean deleteVeh (int vRegNo) throws IOException
{

return remove(lookUpV(vRegNo));

}

public void printVehicles()
{
System.out.println("Vehicle");
System.out.println("---------------");
for(int i=0;i<size();i++)
{
System.out.println(" "+getVehicle(i));
}
System.out.println("\n\n");
}
}

This code adds, deletes and displays the vehicles that I entered in
the terminal. But when the program ends the data disapears. How can I
store an a record - object in that way that it will be there when the
program will start again? Thank you for your answers.
 
A

Andrew Thompson

Christos Kalogeropoulos said:
Hi, I have writen the class bellow in order to create objects store
inforation about vehicles.

import java.io.*;
import java.util.Vector;

public class VehicleList extends Vector

Any class that implements 'Serializable'
can be written to, and read from, disk easily.
....
This code adds, deletes and displays the vehicles that I entered in
the terminal. But when the program ends the data disapears. How can I
store an a record - object in that way that it will be there when the
program will start again?

Do the Sun tutorial trail on I/O and write/read
the Vector to/from disk
..Thank you for your answers.

You're welcome.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top