here i have to set the record with vacant vehicle details and customer details,but i don't know how to set that customer record with vacant vehicle.please help me with this coding
This is the coding foe Rent class,i think there is no error
public class Rent {
//vehicle details
private String vehicle_no;
private String vehicle_model;
private String driver_name;
private String driver_license;
private boolean vacant;
//customer details
private String customer_name;
private String customer_mobile;
private int no_of_rented_days;
//record details
private int rent_record_no;
private static int total_records;
public Rent(String vNo,String vModel,String dName,String dLicense){
vehicle_no=vNo;
vehicle_model=vModel;
driver_name=dName;
driver_license=dLicense;
vacant=true;
}
public void setCustomerDetails(String cName,String cMobile,int rDays){
customer_name=cName;
customer_mobile=cMobile;
no_of_rented_days=rDays;
vacant=false;
total_records++;
rent_record_no=total_records;
}
public void setVacancy(){
vacant=true;
no_of_rented_days=0;
rent_record_no=0;
}
public void displayRentRecord(){
System.out.println("Rent Record No. : "+rent_record_no);
System.out.print("\nVehicle :"+vehicle_model);
System.out.print(" - "+vehicle_no);
System.out.print("\nDriver"+driver_name);
System.out.print(" - "+driver_license);
System.out.print("\nCustomer : "+customer_name);
System.out.print(" - "+customer_mobile);
System.out.println("Number of rented days : "+no_of_rented_days);
}
public boolean getVacant(){
return vacant;
}
public int getRentRecNo(){
return rent_record_no;
}
public int getTotRecords(){
return total_records;
}
}
This is the coding of my main class
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author Asin
*/import java.util.*;
public class MainInterface {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
Scanner s=new Scanner(System.in);
int choice;
Rent[] rent=new Rent[5];
String car_model=null;
String car_no=null;
String driver_name=null;
String drLicen_no=null;
String cus_name=null;
String cus_mobile=null;
int no_of_rentedDays=0;
int i=0,j=0;
while(true){
System.out.println();
System.out.println(" Main Menu");
System.out.println();
System.out.println("Add a Car <press 1>");
System.out.println("Rent a Car <press 2>");
System.out.println("Return a Car <press 3>");
System.out.println("View all Rented Records <press 4>");
System.out.println("Exit <press 5>");
choice=s.nextInt();
if(choice==1){ //display add a car interface
System.out.print("Enter the Car model: ");
car_model=s.next();
System.out.print("Enter the Car number: ");
car_no=s.next();
System.out.print("Enter Driver's name: ");
driver_name=s.next();
System.out.print("Enter Driver's licence: ");
drLicen_no=s.next();
rent[i]=new Rent(car_no,car_model,driver_name,drLicen_no);
i++;
}else if(choice==2){
System.out.print("Eneter customer name: ");
cus_name=s.next();
System.out.print("Enter customer mobile: ");
cus_mobile=s.next();
System.out.print("Enter no of days to be rented: ");
no_of_rentedDays=s.nextInt();
rent[j].setCustomerDetails(cus_name, cus_mobile, no_of_rentedDays);
rent[j].displayRentRecord();
j++;
}else if(choice==3){
try{
System.out.print("Enter Record Number : ");
rent[s.nextInt()].setVacancy();
System.out.println("Successfully Updated...");
}catch(ArrayIndexOutOfBoundsException e1){
System.out.println("Record number does not exist!");
}
}else if(choice==4){
try{
for(int r=0;r<rent.length;r++){
rent[r].displayRentRecord();
}
}catch(NullPointerException e2){
System.out.println("end of records");
}
}else if(choice==5){
System.exit(0);
}
}
}
}
//end of the program