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) {
        } catch (IOException e) {

		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();
      } catch (IOException ioe) {
         System.out.println("Your choice is not recognised");


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

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

replace line number 51 (if (choice == "1"))
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

Edited 6 Years Ago by vchandra: n/a

This article has been dead for over six months. Start a new discussion instead.