I have coded three classes ,1 class containing the Main method.
I have declared three private data fields in Staff class and two data fields in Address class.
The problem is that I am assigning String type data field from the Staff and Address Class through the
public set methods to String type array in a public void method in the Main class.
public static void main(String[] args){ // TODO code application logic here System.out.println("-------------------------------------------------"); System.out.println("Press 1 - 6 To Perform Any One Following Action "); System.out.println("1. Insert New Contact "); System.out.println("2. Delete Contact By Name "); System.out.println("3. Replace Info From Contact "); System.out.println("4. Search Contact By Name "); System.out.println("5. Show All Contacts "); System.out.println("6. Exit Program "); System.out.println("-------------------------------------------------"); System.out.println(); System.out.println("Your Choice :"); AddressBook adBook = new AddressBook(); Staff staff = new Staff(); Address adress = new Address(); adBook.openFile(); adBook.insertRecord(staff.getName(), staff.getDesignation(), staff.getAge(), adress.getAddress(), adress.getMobileNo()); adBook.closeFile(); } java.io.PrintWriter pw; static final int rows = 100; static final int cols = 5; String[][] record = new String[rows][cols]; public AddressBook(){ } public void openFile(){ try{ pw = new java.io.PrintWriter("EmployeeRecords.txt"); } catch(FileNotFoundException e){ System.out.println("Error"); } } public void insertRecord(String n, String d, String ad, String a, String m){ Staff staf = new Staff(); System.out.print(record[0][0] = "Name" + "\t"); System.out.print(record[0][1] = "Designation" + "\t"); System.out.print(record[0][2] = "Age" + "\t"); System.out.print(record[0][3] = "Address" + "\t\t"); System.out.print(record[0][4] = "MobileNo" + "\t"); for(int r = 1; r < rows; r++){ for(int c = 0; c < cols; c++){ record[r][c] = staf.setName(); // I will got error on that assignment stetement } } } class Staff { private String name; private String designation; private String age; public Staff(){ } public void setName(){ Scanner name = new Scanner(System.in); name.toString(); } public String getName(){ return name; } public void setDesignation(){ Scanner designation = new Scanner(System.in); designation.toString(); } public String getDesignation(){ return designation; } public void setAge(){ Scanner age = new Scanner(System.in); age.toString(); } public String getAge(){ return age; } } class Address { private String address; private String mobileNo; public Address(){ } public void setAddress(){ Scanner address = new Scanner(System.in); address.toString(); } public String getAddress(){ return address; } public void setMobileNo(){ Scanner mobile = new Scanner(System.in); mobile.toString(); } public String getMobileNo(){ return mobileNo; } }