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.
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.