hi please can anyone help me with this code.

the prob lies in the add function for some reason it only executes 2 lines of the code and as soon as i enter the data the program finishes

import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.io.*;


class customers{
	
	private String cus_id;
	private String cus_name;
	private String cus_add;
	private String cus_email;
	private RandomAccessFile raf;
	

	
	public customers(){
		
		
		try {
            
            raf = new RandomAccessFile("Pass.dat", "rw");

          
       } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }

		cus_id = null;
		cus_name = null;
		cus_add = null;
		cus_email = null;
		
	}
	
	public void add(){
		
	System.out.println("What do You wish to do?");	
	System.out.println("\t1.Add New.");
	System.out.println("\t2.Edit Existing");
	
	BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	String choice;
	
    try {
         choice = br.readLine();
         
         if (choice == "1")
         {
         	System.out.println("Enter the data specified");
         	System.out.println("Customer ID:\t ");
         	
            br = new BufferedReader(new InputStreamReader(System.in));
         
           cus_id = br.readLine();
         
            System.out.println("Customer Name:\t ");	
         
            br = new BufferedReader(new InputStreamReader(System.in));
            cus_name = br.readLine();
         
            System.out.println("Customer Address:\t ");
            br = new BufferedReader(new InputStreamReader(System.in));
            cus_add = br.readLine();
         
            System.out.println("Customer Email:\t "); 
            br = new BufferedReader(new InputStreamReader(System.in));
            cus_email = br.readLine();
         
         	
         	raf.seek(raf.length());
            raf.writeUTF(cus_id);
            raf.writeUTF(cus_name);
            raf.writeUTF(cus_add);
            raf.writeUTF(cus_email);
         } 
         
         
         
      } catch (IOException ioe) {
         System.out.println("Your choice is not recognised");
         
      }
	
	

		
		
		
		
		
	}
	
	
}




class Cust
{
   public static void main(String[] args)
   {
       
      customers arr; 
      arr = new customers(); 
     arr.add();
     
   } 
}

ahh ... small mistake .............
you can compare strings with "==", you should use .equals

replace line number 51 (if (choice == "1"))
with
if (choice.equals("1"))

I am assuming that you know the difference between "==" and .equals. if no then below is the diff:
== compares the reference while .equals compares values, you can find the details any where

aww fish i didnt know that thnaks

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.