Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Dont know how to recorrect

  1. #1
    Junior Member
    Join Date
    Oct 2011
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Dont know how to recorrect

    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


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Dont know how to recorrect

    how to set that customer record with vacant
    What is a vacant vehicle?
    Is there a Customer class? That would be a logical place to save data for a customer.
    If not, what is a customer record?

    You have a variable named vacant in the Rent class. You have code that sets its value.
    Can you explain what you are trying to do?

Similar Threads

  1. please help me with this program, I dont have enough time to do it
    By n.azizabadi in forum Member Introductions
    Replies: 1
    Last Post: June 10th, 2011, 03:35 AM
  2. I dont understand why this happens....
    By ashenwolf in forum What's Wrong With My Code?
    Replies: 4
    Last Post: May 10th, 2011, 09:31 PM
  3. i'm getting this error, dont know why? please help
    By amr in forum What's Wrong With My Code?
    Replies: 4
    Last Post: December 17th, 2010, 06:14 AM
  4. I dont get it....please help
    By DestinyChick1225 in forum What's Wrong With My Code?
    Replies: 12
    Last Post: June 30th, 2010, 03:16 AM
  5. Dont laugh at me
    By Neblin in forum What's Wrong With My Code?
    Replies: 5
    Last Post: October 3rd, 2009, 08:18 AM