Array of linked list

I have the following:
          LinkedList pathArray[] = new LinkedList[20];
                        for(int i = 0; i < pathArray.length; i++)
               pathArray[i] = new LinkedList();
          int place=0;          
          for(int j=0; j<size; j++)
               Edge temp = (Edge)edge.get(j);
               if(temp.getSource() == userSource)
                    pathArray[place] = LinkedList.add(temp); //Confused here
                    place++;
          }Assuming Edge is working which is does, how do i add an object to the list that is at position 0 in the array? I know what i did at the line I said I was confused at is wrong but not sure how it should be?
Could someone help?

Ok actually ignore that first code, I have changed it as follows which makes more sense but doesnt quite work:
                         ArrayList path = new ArrayList();
          ArrayList pathArray[] = new ArrayList[20];
          int place=0;
          for(int j=0; j<size; j++)
               Edge temp = (Edge)edge.get(j);
               if(temp.getSource() == userSource)
                    pathArray[place] = path.add(new Edge(temp));
                    place++;
          }I get an error:
C:\Users\Taurus\Desktop\University\AMI - 4517\Assignment\branchb>javac BranchB2.java
BranchB2.java:85: incompatible types
found : boolean
required: java.util.ArrayList
pathArray[place] = path.add(new Edge(temp));
^
1 error
How can i fix that?

Similar Messages

  • Array of Linked List Help

    I am fairly new to Java, and Linked Lists. Can you tell me how I can fix my code? Why does my code print infinite "3" s. That is all I am trying to do is create a linked list and put that linked list into index 2 of the array. In the loop, I am setting up a whole bunch on null Node's, is it even possible to link all these nodes together in that same loop? If something does not make sense, I will try to elaborate. I will eventually impliment an insert method in the Node class, are there any pointers on how to implement it? What are the special cases I need to be looking for when implementing the insert method?
    * To change this template, choose Tools | Templates
    * and open the template in the editor.
    package testlinkedlist;
    * @author Ben
    public class Main {
         * @param args the command line arguments
        public static Node l;
        public static Node p = new Node();
        public static Node Front;
        public static void main(String[] args) {
            Node[] anArray = new Node[4];
            for(int i = 0; i < 4; i++){
                anArray[i] = new Node();
                l = new Node(i);
                l.setLink(l);
            anArray[2] = l;         
            while(anArray[2] != null){
                System.out.println(anArray[2].dataInNode());
                anArray[2] = anArray[2].next;
    }

    l = new Node(i);
    l.setLink(l);The node l is created in line one, in line two a link is created from l to l. In other words here is the presence of your infinite loop which is magnified in the following piece of code:
    anArray[2] = l;         
    while(anArray[2] != null){
      System.out.println(anArray[2].dataInNode());
      anArray[2] = anArray[2].next;
    }Mel

  • Urgent problem : array of linked list

    In order to save memory I am trying to build an array of linkedlist with the following program. It compiles well but when I execute it, error occurs as follows,
    Exception in thread "main" java.lang.NullPointerException
    at testLL2.main(testLL2.java:10)
    My program:
    import java.net.*;
    import java.io.*;
    import java.util.LinkedList;
    public class testLL2 {
    public static void main(String[] args) throws IOException {
    int myLLLength;
    LinkedList myLL2 [] = new LinkedList[10];
    for (int i = 0; i < 10; i++) {
    for (int j=0; j < 5; j++) {
    myLL2.add(" "+j);
    for (int i = 0; i < 10; i++) {
    myLLLength = myLL2[i].size();
    for (int j=0; j<myLLLength; j++) {
    System.out.println(myLL2[i].get(j));
    Since I tried many alternatives to solve it but one of them succeed. Please kindly help me! Thanks in advance!

    [snip]
    2. Where you have 'myLL2.add(" "+j);' it should read
    myLL2. The is probably a typo. If not, make sure
    you understand why you need to change your code.
    The forum posting code will muck up your code if you don't surround it in [ code] [code ] (no spaces) tags.  Even if you do use the code tags, it preprocesses [ i] into <i> to avoid turning your code into italics.

  • Copying an array of linked lists

    I have this:
    ArrayList pathArray[] = new ArrayList[20];
    ArrayList copyRow = pathArray[0];
    pathArray[1] = copyRow;The bottom bit of the above code after the .... doesnt seem to do what i want, I am trying to copy the contents of array index 0 to array index 1. Now when i do that it works but if i start editing the variables in it it changes the variables in index 0, whats the correct way of copying?

    ArrayList pathArray[] = new ArrayList[20];
    Object copyRow  = pathArray[0].clone();
    pathArray[1] = (ArrayList) copyRow;Edited by: Chicon on Apr 25, 2009 8:40 PM

  • Need help on creating a linked list with array...

    I want to create a linked listed using array method. Any suggestion on how would I start it.
    thanks

    That means I want to implement linked list using an
    array.I believe you mean you want to implement list using an array. Linked list is a very different implementation of a list, which can be combined with arrays for a niche implementation of list, but I don't think this is what you're talking about.
    Do you mind if we ask why you don't want to use ArrayList? It does exactly what you specify, plus it will increase the size of the internal array as necessary to ensure it can store the required elements.
    If you really want to make your own, have a look at the source for ArrayList (in src.jar in your JDK installation folder) - it will answer any questions you have. If you don't understand any of the code, feel free to post the relevant code here and ask for clarification.

  • Help on Linked List

    Hey people, i need a small help on my linked list.
    Ok, what i'm trying to do is have a search function with a linked list using strings. First i will have a string, i will then compute the ASCII value for that and take MOD 71 lets say. For example, a string has an ASCII value of 216, MOD 71 of this gives me 3. I will then have an array of 71, and each array will point to a linked list. There will be as many linked list as there are of arrays (71). I will then store this string at index [3] in the linked list in which the array points to.
    My problem for now is, how do i for example create 71 linked list? So far i can create only 1. To create another is easy, but if i have 71 the code will be too much. Is there an iterator i could use that easily creates 71? Sorry about this, i'm not really good with linked list with Java. Anyway, here is what i have now :).
    public class MyLinkedListElement {   
            String string;
            MyLinkedListElement next;
            public MyLinkedListElement(String s) {   
                string = s;
                next = null;   
            public MyLinkedListElement getNext() {
                return next;       
            public String getValue() {
                return string;
    public class MyLinkedList {
        public static MyLinkedListElement head;
        public MyLinkedList() {   
            head = null;
       public static void addToHead(String s) {
            MyLinkedListElement a = new MyLinkedListElement(s);
            if (head == null) {
                head = a;
            } else {
                a.next = head;
                head = a;       
        public static void main(String[] args) {
              String[] arr = {"Bubble", "Angie", "Bob", "Bubble", "Adam"};
              for (int i = 0; i < arr.length; i++) {
                          addToHead(arr);
    MyLinkedListElement current = head;
    while (current != null) {
    System.out.println(current.getValue());
    current = current.next;
    }I can have an array of strings and easily add them to a linked list.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

    I am very confused now, i just need to store a string value inside an array of linked list. But i can't somehow do it. I am very close, i can store the value in a linked list but the array of linked list, this is what i have.
    public class MyLinkedListElement {   
            String string;
            MyLinkedListElement next;
            public MyLinkedListElement(String s) {   
                string = s;
                next = null;   
            public MyLinkedListElement getNext() {
                return next;       
            public String getValue() {
                return string;
    public class MyLinkedList {
        public MyLinkedListElement head;
        public MyLinkedList() {   
              head = null;
        public void addToHead(String s) {
             MyLinkedListElement  a = new MyLinkedListElement(s);
             MyLinkedList[] arrayOfLinkedLists = new MyLinkedList[71];
             for(int i = 0; i < arrayOfLinkedLists.length; i++) {
                 arrayOfLinkedLists[i] = new MyLinkedList();
             if (head == null) {    
                 head = a;
             } else {
                 a.next = head;
                 head = a;       
        public void print(MyLinkedListElement current) {
              while (current  != null) {
                    System.out.println(current.getValue());
                    current = current.next;
        public static void main(String[] args) {
              String[] arr = {"Bubble", "Angie", "Bob", "Bubble", "Adam"};
              MyLinkedList listInstance = new MyLinkedList();
              for (int i = 0; i < arr.length; i++) {
                    listInstance.addToHead(arr);
    MyLinkedListElement current = listInstance.head;
    listInstance.print(current);

  • Multiple Instances of Linked List

    i need to create multiple linked lists; the amount of linked lists i'm creating is based on a user inputted value. what's the quickest and most convient way to do this?

    This is another question based on my post yesterday .
    . . . is it possible to create a JTable with an array
    of Linked Lists? i'm trying but i'm getting a complie
    error that says
    " constructor JTable
    (java.util.LinkedList[],java.lang.String[]) not found
    in class javax.swing.JTable "
    i'm calling the method createTable and passing an
    array of LinkedList to it.The error you're getting from the compiler should tell you quite plainly that no, it's not possible. At least not that way.
    Look at the API docs and see if there's a constructor that does take an array of Lists. If not, you'll have to figure out how to make your data fit into what it does take.

  • Please Hilp me ( about linked list)

    i am an university student
    i was write a proram by ( arrays)
    thes program about Employees ( Add , Searsh , displly , delete )
    it is 6 class
    1 = Employee.java
    2 = Boss.java
    3 = CommissionWorker.java
    4 = HourlyWorker.java
    5 = PieceWorker.java
    6 = StartProgram.java
    i wona now changing the program from (Arrays) to (linked list)
    this is the cood

    The last 1
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class StartProgram extends JFrame
              // The Components For Frame 1
              private JLabel Label_Number_Of_Employee ;
              private JTextField Text_Number_Of_Employee ;
              private JButton Button_New, Button_Display, Button_Search, Button_UpData, Button_Delete;
              private JButton Button_Exit, Button_RE;
              private JPanel Panel_1_North, Panel_1_West, Panel_1_South, Panel_1_Center;
              // The Components For Frame 2
              private JLabel Label_Name, Label_Adress, Label_Gread, Label_ID, Label_Salary , Label_Commiss, Label_Quant, Label_Hour, Label_Wage, Label_Pice, Label_Total_Mony, Label_NumberID_FOR_Searsh;
              private JTextField TextField_Total_mony, TextField_Name, TextField_Adress, TextField_Greade,     TextField_ID, TextField_Salary , TextField_Commiss, TextField_Quant, TextField_Hour, TextField_Wage, TextField_Pice, TextField_NumberID_FOR_Searsh;
              private JButton Button_Clear, Button_OK2, Button_Cancel, Button_Next, Button_Prev, Button_Searsh, Button_Save, Button_Delet, Button_Create;
              private JRadioButton rad_Boss, rad_HourlyWorker, rad_PiceWorker, rad_CommissWorker;
              private ButtonGroup radGroup;
              private JPanel Panel_2_Center, Panel_2_South, Panel_2_North;
              // The Container For Frame 1
              Container cont;
              // The Container For Frame 2
              Container cont2;
              // The Layouts For Frame 1 & 2
              private FlowLayout layout;
              private GridLayout glayout;
              // private class Show_Frame2 extends JFrame
              int ID_Conter_Number[] = new int[1];
              Show_Frame2 Frame_Display;
              Show_Frame2 Frame_Delete;
              Show_Frame2 Frame_UpData;
              Show_Frame2 Frame_Search;
              // VARIABLES
              int Text_Number_TO_int = 0;
              int Countr_Index_Of_ArrayEmp = 0;
              int Number_Chose_Acion;
              int Conter_next = -1;
              int Number_Stop_Create = 0;
              int NumberID_FOR_Searsh = 0 ;
              int Nu_S_S_D_F_T_F_T_T_A; // use in Set_Save_Data_From_Text_Field_To_The_Arayy();
              int Number_Set_Kind_Employee; // use in Set_Save_Data_From_Text_Field_To_The_Arayy();
              int Nu_S_K_E_B_R_S; // use in Set_Kind_Employee_By_radBotton_Selected()
              int Nu_S_D_I_F_T_S_B_S_O_D; // use in Set_Data_in_Folds_To_Show_By_Searsh_Or_Disply()
              // use in Set_Save_Data_From_Text_Field_To_The_Arayy()
              int ID_set_Save_Data;
              int Greade_set_Save_Data;
              String Adress_set_Save_Data;
              String Name_set_Save_Data;
              double Salary_set_Save_Data;
              int Quant_set_Save_Data;
              int Hour_set_Save_Data;
              int Pice_set_Save_Data;
              double Wage_set_Save_Data;
              double Commiss_set_Save_Data;
              double Total_Mony;
              // For updata
              int ID_updata;
              int Greade_updata;
              String Adress_updata;
              String Name_updata;
              double Salary_updata;
              int Quant_updata;
              int Hour_updata;
              int Pice_updata;
              double Wage_updata;
              double Commiss_updata;
              double Total_Mony_updata;
              // Arayy(s) To Keep Elements Data Of Employee
              String ArayyName[];
              String ArayyAdress[];
              int ArayyGreade[];
              int ArayyID[];
              double ArayySalary[];
              double ArayyCommiss[];
              int ArayyQuant[];
              int ArayyHour[];
              double ArayyWage[];
              int ArayyPice[];
              int ArayyKind_Emp[];
              // Arayy(s)2 To Keep A Copy Of Elements Data Of Employee
              // Use in Delete Action
              String ArayyName_Copy[];
              String ArayyAdress_Copy[];
              int ArayyGreade_Copy[];
              int ArayyID_Copy[];
              double ArayySalary_Copy[];
              double ArayyCommiss_Copy[];
              int ArayyQuant_Copy[];
              int ArayyHour_Copy[];
              double ArayyWage_Copy[];
              int ArayyPice_Copy[];
              int ArayyKind_Emp_Copy[];
              // CONSRUCTOR of StartProgram class
              // Open form1
              public StartProgram()
                        super("Start To Employee System Control");
                        cont = getContentPane();
                        Panel_1_North = new JPanel();      Panel_1_North.setLayout(new GridLayout(3,0,0,0));
                        Panel_1_Center = new JPanel();          Panel_1_Center.setLayout(new GridLayout(6,0,0,0));
                        Panel_1_South = new JPanel();          Panel_1_South.setLayout(new GridLayout(1,0,0,0));
                        Label_Number_Of_Employee = new JLabel("Enter The Number Of Employees Then Press (ENTER) In Your KeyBoard ! ");
                        Text_Number_Of_Employee = new JTextField(10);
                        // 1- Display Button Choice To Employee System Control in form1
                        // 2- set Buttons Edit = false
                        Button_New = new JButton("Create a new an Employee(s) ");     Button_New.setVisible(false);
                        Button_Display = new JButton("Display an Employee(s) ");     Button_Display.setVisible(false);
                        Button_Search = new JButton("Search for an Employee(s) ");     Button_Search.setVisible(false);
                        Button_UpData = new JButton("UpData for an Employee(s) ");     Button_UpData.setVisible(false);
                        Button_Delete = new JButton("Delete an Employee(s) "); Button_Delete.setVisible(false);
                        // 1- Display Button ( EXIT & START AGEN ) in form1
                        // 2- set Buttons Edit = false
                        Button_Exit = new JButton("EXIT");     Button_Exit.setEnabled(false);
                        Button_RE = new JButton("START AGEN");     Button_RE.setEnabled(false);
                        // an object from the private class ActionHandler
                        ActionHandler handler = new ActionHandler();
                        Button_New.addActionListener(handler);
                        Button_Display.addActionListener(handler);
                        Button_Search.addActionListener(handler);
                        Button_UpData.addActionListener(handler);
                        Button_Delete.addActionListener(handler);
                        Button_Exit.addActionListener(handler);
                        Button_RE.addActionListener(handler);
                        Text_Number_Of_Employee.addActionListener(handler);
                        // Add all objects in form1
                        Panel_1_North.add(Label_Number_Of_Employee);
                        Panel_1_North.add(Text_Number_Of_Employee);
                        Panel_1_Center.add(Button_New);
                        Panel_1_Center.add(Button_Display);
                        Panel_1_Center.add(Button_Search);
                        Panel_1_Center.add(Button_UpData);
                        Panel_1_Center.add(Button_Delete);
                        Panel_1_South.add(Button_Exit);
                        Panel_1_South.add(Button_RE);
                        cont.add(Panel_1_North , BorderLayout.NORTH);
                        cont.add(Panel_1_Center , BorderLayout.CENTER);
                        cont.add(Panel_1_South , BorderLayout.SOUTH);
                        // setting of form1
                        setSize(450,350);
                        setVisible(true);
                        setResizable(false);
              } // END public StartProgram()
              private class ActionHandler implements ActionListener
                        public void actionPerformed(ActionEvent EEEE)
                                  // ================================================
                                  // ================================================
                                  // if user Put A Number Then He clock Enter
                                  if(EEEE.getSource() == Text_Number_Of_Employee)
                                            Set_Enter_Number_Of_Employee_Start();
                                  // ================================================
                                  // ================================================
                                  // Or if user clock Button Exit
                                  else if(EEEE.getSource() == Button_Exit)
                                            System.gc();
                                            System.exit(0);
                                  // ================================================
                                  // ================================================
                                  // if user clock Button RE START
                                  if(EEEE.getSource() == Button_RE)
                                            Set_Program_Start_Agen();
                                  // ================================================
                                  // ================================================
                                  // if user clock Button Create a new Employee
                                  if(EEEE.getSource() == Button_New)
                                            Number_Chose_Acion = 1;
                                            Show_Frame2 CCCC = new Show_Frame2();
                                  // ================================================
                                  // ================================================
                                  // if user clock Button Display The Employee
                                  if(EEEE.getSource() == Button_Display)
                                            Number_Chose_Acion = 2;
                                            Show_Frame2 CCCC = new Show_Frame2();
                                  // ================================================
                                  // ================================================
                                  // if user clock Button Search The Employee
                                  if(EEEE.getSource() == Button_Search)
                                            Number_Chose_Acion = 3;
                                            Show_Frame2 CCCC = new Show_Frame2();
                                  // ================================================
                                  // ================================================
                                  // if user clock Button UpData The Employee
                                  if(EEEE.getSource() == Button_UpData)
                                            Number_Chose_Acion = 4;
                                            Show_Frame2 CCCC = new Show_Frame2();
                                  // ================================================
                                  // ================================================
                                  // if user clock Button Delete
                                  if(EEEE.getSource() == Button_Delete)
                                            Number_Chose_Acion = 5;
                                            Show_Frame2 CCCC = new Show_Frame2();
                        } // END public void actionPerformed(ActionEvent e)
              } // END private class ActionHandler implements ActionListener
              public void Set_Enter_Number_Of_Employee_Start()
                        try
                                  Text_Number_TO_int = Integer.parseInt(Text_Number_Of_Employee.getText());
                                  if(Text_Number_TO_int <= 0)
                                            Text_Number_Of_Employee.setText("ERROR !! Please Enter a Number More Than 0");
                                  else
                                            Set_Create_Lingth_Of_Arayy_By_Number_That_Entered();
                        catch(NumberFormatException nfe)
                                  Text_Number_Of_Employee.setText("ERROR !! Please Enter a Number");
              public void Set_Create_Lingth_Of_Arayy_By_Number_That_Entered()
                        ID_Conter_Number = new int[Text_Number_TO_int];
                        Text_Number_Of_Employee.setEditable(false);
                        Button_New.setVisible(true);
                        Button_Display.setVisible(true);
                        Button_Search.setVisible(true);
                        Button_UpData.setVisible(true);
                        Button_Delete.setVisible(true);
                        Button_Exit.setEnabled(true);
                        Button_RE.setEnabled(true);
                        ArayyName = new String[Text_Number_TO_int];
                        ArayyAdress = new String[Text_Number_TO_int];
                        ArayyGreade = new int[Text_Number_TO_int];
                        ArayyID = new int[Text_Number_TO_int];
                        ArayySalary = new double[Text_Number_TO_int];
                        ArayyCommiss = new double[Text_Number_TO_int];
                        ArayyQuant = new int[Text_Number_TO_int];
                        ArayyHour = new int[Text_Number_TO_int];
                        ArayyWage = new double[Text_Number_TO_int];
                        ArayyPice = new int[Text_Number_TO_int];
                        ArayyKind_Emp = new int[Text_Number_TO_int];
              public void Set_Program_Start_Agen()
                        Text_Number_Of_Employee.setEditable(true);
                        Text_Number_Of_Employee.setText("");
                        Countr_Index_Of_ArrayEmp = 0;
                        Conter_next = -1;
                        Text_Number_TO_int = 0;
                        Countr_Index_Of_ArrayEmp = 0;
                        Conter_next = -1;
                        Nu_S_S_D_F_T_F_T_T_A = 0;
                        Number_Set_Kind_Employee = 0;
                        Number_Stop_Create = 0;
                        ArayyName = null ;
                        ArayyAdress = null ;
                        ArayyGreade = null ;
                        ArayyID = null ;
                        ArayySalary = null ;
                        ArayyCommiss = null ;
                        ArayyQuant = null ;
                        ArayyHour = null ;
                        ArayyWage = null ;
                        ArayyPice = null ;
                        ArayyKind_Emp = null ;
                        ArayyName_Copy = null ;
                        ArayyAdress_Copy = null ;
                        ArayyGreade_Copy = null ;
                        ArayyID_Copy = null ;
                        ArayySalary_Copy = null ;
                        ArayyCommiss_Copy = null ;
                        ArayyQuant_Copy = null ;
                        ArayyHour_Copy = null ;
                        ArayyWage_Copy = null ;
                        ArayyPice_Copy = null ;
                        ArayyKind_Emp_Copy = null ;
                        ID_set_Save_Data = 0;
                        Greade_set_Save_Data = 0;
                        Adress_set_Save_Data = null;
                        Name_set_Save_Data = null;
                        Salary_set_Save_Data = 0.00;
                        Quant_set_Save_Data = 0;
                        Hour_set_Save_Data = 0;
                        Pice_set_Save_Data = 0;
                        Wage_set_Save_Data = 0.00;
                        Commiss_set_Save_Data = 0.00;
              // Whin User Click Any rad Button
              private class RadHandler implements ItemListener
                        public void itemStateChanged(ItemEvent i)
                                  Set_All_Text_Field_To_Defolt_Text();
                                  TextField_Name.setEditable(true);
                                  TextField_Adress.setEditable(true);
                                  TextField_Greade.setEditable(true);
                                  if(i.getSource() == rad_Boss)
                                            TextField_Salary.setEditable(true);
                                            TextField_Wage.setEditable(false);
                                            TextField_Commiss.setEditable(false);
                                            TextField_Quant.setEditable(false);
                                            TextField_Hour.setEditable(false);
                                            TextField_Pice.setEditable(false);
                                  else if(i.getSource() == rad_HourlyWorker)
                                            TextField_Salary.setEditable(false);
                                            TextField_Wage.setEditable(true);
                                            TextField_Hour.setEditable(true);
                                            TextField_Commiss.setEditable(false);
                                            TextField_Quant.setEditable(false);
                                            TextField_Pice.setEditable(false);
                                  else if(i.getSource() == rad_PiceWorker)
                                            TextField_Salary.setEditable(false);
                                            TextField_Wage.setEditable(true);
                                            TextField_Hour.setEditable(false);
                                            TextField_Quant.setEditable(false);
                                            TextField_Commiss.setEditable(false);
                                            TextField_Pice.setEditable(true);
                                  else if(i.getSource() == rad_CommissWorker)
                                            TextField_Salary.setEditable(true);
                                            TextField_Wage.setEditable(false);
                                            TextField_Hour.setEditable(false);
                                            TextField_Quant.setEditable(false);
                                            TextField_Commiss.setEditable(true);
                                            TextField_Pice.setEditable(true);
              private class Show_Frame2 extends JFrame
                        public Show_Frame2()
                                  super("Control Panal Of Employee's Data");
                                  cont2 = getContentPane();
                                  Panel_2_Center = new JPanel();
                                  Panel_2_Center.setLayout(new GridLayout(11,2,5,5));
                                  Panel_2_South = new JPanel();
                                  Panel_2_South.setLayout(new GridLayout(2,5,5,5));
                                  Panel_2_North = new JPanel();
                                  Panel_2_North.setLayout(new GridLayout(2,1,5,5));
                                  Label_NumberID_FOR_Searsh = new JLabel("Employee's ID :", SwingConstants.RIGHT);
                                  Label_NumberID_FOR_Searsh.setVisible(false);
                                  TextField_NumberID_FOR_Searsh = new JTextField(5);
                                  TextField_NumberID_FOR_Searsh.setVisible(false);
                                  TextField_NumberID_FOR_Searsh.setEditable(false);
                                  Label_Name = new JLabel("Name : " , SwingConstants.RIGHT);
                                  Label_Adress = new JLabel("Address : " , SwingConstants.RIGHT);
                                  Label_Gread = new JLabel("Greade : " , SwingConstants.RIGHT);
                                  Label_ID = new JLabel("ID : " , SwingConstants.RIGHT);
                                  Label_Salary = new JLabel("Salary : " , SwingConstants.RIGHT);
                                  Label_Commiss = new JLabel("Commiss : " , SwingConstants.RIGHT);
                                  Label_Quant = new JLabel("Quant : " , SwingConstants.RIGHT);
                                  Label_Hour = new JLabel("Hours : " , SwingConstants.RIGHT);
                                  Label_Wage = new JLabel("Wage : " , SwingConstants.RIGHT);
                                  Label_Pice = new JLabel("Pice : " , SwingConstants.RIGHT);
                                  Label_Total_Mony = new JLabel("Total_Money : " , SwingConstants.RIGHT);
                                  TextField_Name = new JTextField(45);
                                  TextField_Adress = new JTextField(45);
                                  TextField_Greade = new JTextField(2);
                                  TextField_ID = new JTextField(4);
                                  TextField_Salary = new JTextField(10);
                                  TextField_Commiss = new JTextField(10);
                                  TextField_Quant = new JTextField(10);
                                  TextField_Hour = new JTextField(10);
                                  TextField_Wage = new JTextField(10);
                                  TextField_Pice = new JTextField(10);
                                  TextField_Total_mony = new JTextField(10); TextField_Total_mony.setEditable(false);
                                  rad_Boss = new JRadioButton("Boss" , false);
                                  rad_HourlyWorker = new JRadioButton("Hourly" , false);
                                  rad_PiceWorker = new JRadioButton("Pice" , false);
                                  rad_CommissWorker = new JRadioButton("Commiss" , false);
                                  radGroup = new ButtonGroup();
                                  radGroup.add(rad_Boss);
                                  radGroup.add(rad_HourlyWorker);
                                  radGroup.add(rad_PiceWorker);
                                  radGroup.add(rad_CommissWorker);
                                  //handler is object of private class RadHandler
                                  RadHandler rHandler = new RadHandler();
                                  rad_Boss.addItemListener(rHandler);
                                  rad_HourlyWorker.addItemListener(rHandler);
                                  rad_PiceWorker.addItemListener(rHandler);
                                  rad_CommissWorker.addItemListener(rHandler);
                                  Button_Save = new JButton("Save"); Button_Save.setVisible(false);
                                  Button_Delet = new JButton("Delete"); Button_Delet.setVisible(false);
                                  Button_Searsh = new JButton("Search"); Button_Searsh.setVisible(false);
                                  Button_Next = new JButton("next");
                                  Button_Prev = new JButton("Prev");
                                  Button_Clear = new JButton("Clear");
                                  Button_OK2 = new JButton("OK"); Button_OK2.setEnabled(false);
                                  Button_Cancel = new JButton("Cancel/Menu");
                                  Button_Create = new JButton("Create");
                                  // ================================================
                                  // ================================================
                                  // of usrt click Button Clear
                                  Button_Clear.addActionListener
                                            new ActionListener()
                                                      public void actionPerformed(ActionEvent e)
                                                                Set_Part_Of_Text_Field_Clear_of_Text();
                                  // ================================================
                                  // ================================================
                                  // of usrt click Button Cancel / Menu
                                  Button_Cancel.addActionListener
                                            new ActionListener()
                                                      public void actionPerformed(ActionEvent e)
                                                                setVisible(false);
                                  // ================================================
                                  // ================================================
                                  // 111111111111111111111111111111111111111111111111//
                                  // (Create new Employee)
                                  if (Number_Chose_Acion == 1)
                                            if (Number_Stop_Create >= Text_Number_TO_int)
                                                      JOptionPane.showMessageDialog(cont2, "You Can not add more Employees " , "Createing Will stop",JOptionPane.INFORMATION_MESSAGE);
                                            else
                                                      set_Show_Create_employees_Form();
                                  // ================================================
                                  // ================================================
                                  // 222222222222222222222222222222222222222222222222//
                                  // ( Display Employee)
                                  else if (Number_Chose_Acion == 2)
                                            if (ArayyName[0] == null)
                                                      JOptionPane.showMessageDialog(cont2,"Ther are No Employees to Display", "Exception Display",JOptionPane.ERROR_MESSAGE);
                                            else
                                                      set_Show_Display_employees_Form();
                                  // ================================================
                                  // ================================================
                                  // 333333333333333333333333333333333333333333333333//
                                  // ( Search Employee)
                                  else if (Number_Chose_Acion == 3)
                                            try
                                                      if (ArayyName[0] == null)
                                                                JOptionPane.showMessageDialog(cont2,"Ther are No Employees to Search", "Exception Search",JOptionPane.ERROR_MESSAGE);
                                                      else
                                                                set_Show_Search_employees_Form();
                                            catch (Exception ex)
                                                      JOptionPane.showMessageDialog(cont2,ex, "Exception",JOptionPane.ERROR_MESSAGE);
                                  // ================================================
                                  // ================================================
                                  // 444444444444444444444444444444444444444444444444//
                                  // ( UpData Employee)
                                  else if (Number_Chose_Acion == 4)
                                            try
                                                      if (ArayyName[0] == null)
                                                                JOptionPane.showMessageDialog(cont2,"Ther are No Employees to UpData", "Exception UpData",JOptionPane.ERROR_MESSAGE);
                                                      else
                                                                set_Show_UpData_employees_Form();
                                            catch (Exception ex)
                                                      JOptionPane.showMessageDialog(cont2,ex, "Exception",JOptionPane.ERROR_MESSAGE);
                                  // ================================================
                                  // ================================================
                                  // 555555555555555555555555555555555555555555555555//
                                  // ( Delete Action )
                                  else if (Number_Chose_Acion == 5)
                                            try
                                                      if (ArayyName[0] == null)
                                                                JOptionPane.showMessageDialog(cont2,"Ther are No Employees to Delete", "Exception Delete",JOptionPane.ERROR_MESSAGE);
                                                      else
                                                                set_Show_Delete_employees_Form();
                                            catch (Exception ex)
                                                      JOptionPane.showMessageDialog(cont2,ex, "Exception",JOptionPane.ERROR_MESSAGE);
                                  // ================================================
                                  // ================================================
                        } // END public Show_Frame2()
                        // 11111111111111111111111111111111111111111
                        public void set_Show_Create_employees_Form()
                                  set_Container_Of_Form2();
                                  setTitle("Create employees");
                                  setResizable(false);
                                  setSize(600,500);
                                  setVisible(true);
                                  Set_TextField_Editable_IS_FALSE();
                                  Conter_next = 0;
                                  // whin Fram Create new Employee loading
                                  Button_Next.setEnabled(false);
                                  Button_Prev.setEnabled(false);
                                  // of usrt click Button Create
                                  Button_Create.addActionListener
                                            new ActionListener()
                                                      public void actionPerformed(ActionEvent e)
                                                                // Kind of Employee that will ad is boss
                                                                if(rad_Boss.isSelected() == true)
                                                                          try
                                                                                    int Greade_N = Integer.parseInt(TextField_Greade.getText());
                                                                                    if ( (Greade_N > 99) || (Greade_N < 1) )
                                                                                                   JOptionPane.showMessageDialog(cont2," Please\nEnter Number in (Greade) Between 1 To 99", "ERROR NUMBER",JOptionPane.ERROR_MESSAGE);
                                                                                    else
                                                                                              Nu_S_S_D_F_T_F_T_T_A = Countr_Index_Of_ArrayEmp;
                                                                                              Number_Set_Kind_Employee = 1; // = Boss
                                                                                              Set_Save_Data_From_Text_Field_To_The_Arayy();
                                                                                              Set_All_Text_Field_To_Defolt_Text();
                                                                                              JOptionPane.showMessageDialog(cont2,Name_set_Save_Data + "\nwas Created As Boss", "Create",JOptionPane.INFORMATION_MESSAGE);
                                                                                              Countr_Index_Of_ArrayEmp ++;
                                                                                              Number_Stop_Create ++;
                                                                          catch(Exception ex)
                                                                                    JOptionPane.showMessageDialog(cont2,"Please Enter Correct Data\n"+ex, "Exception",JOptionPane.ERROR_MESSAGE);
                                                                // Kind of Employee that will ad is rad_HourlyWorker
                                                                if(rad_HourlyWorker.isSelected() == true)
                                                                               try
                                                                                    int Greade_N = Integer.parseInt(TextField_Greade.getText());
                                                                                    if ( (Greade_N > 99) || (Greade_N < 1) )
                                                                                              JOptionPane.showMessageDialog(cont2," Please\nEnter Number in (Greade) Between 1 To 99", "ERROR NUMBER",JOptionPane.ERROR_MESSAGE);
                                                                                    else
                                                                                              Nu_S_S_D_F_T_F_T_T_A = Countr_Index_Of_ArrayEmp;
                                                                                              Number_Set_Kind_Employee = 2; // = HourlyWorker
                                                                                              Set_Save_Data_From_Text_Field_To_The_Arayy();
                                                                                              Set_All_Text_Field_To_Defolt_Text();
                                                                                              JOptionPane.showMessageDialog(cont2,Name_set_Save_Data + "\nwas Created As HourlyWorker", "Create",JOptionPane.INFORMATION_MESSAGE);
                                                                                              Countr_Index_Of_ArrayEmp ++;
                                                                                              Number_Stop_Create ++;
                                                                          catch(Exception ex)
                                                                                    JOptionPane.showMessageDialog(cont2,ex, "Exception",JOptionPane.ERROR_MESSAGE);
                                                                // Kind of Employee that will ad is rad_PiceWorker
                                                                if(rad_PiceWorker.isSelected() == true)
                                                                          try
                                                                                    int Greade_N = Integer.parseInt(TextField_Greade.getText());
                                                                                    if ( (Greade_N > 99) || (Greade_N < 1) )
                                                                                              JOptionPane.showMessageDialog(cont2," Please\nEnter Number in (Greade) Between 1 To 99", "ERROR NUMBER",JOptionPane.ERROR_MESSAGE);
                                                                                    else
                                                                                              Nu_S_S_D_F_T_F_T_T_A = Countr_Index_Of_ArrayEmp;
                                                                                              Number_Set_Kind_Employee = 3; // = PiceWorker
                                                                                              Set_Save_Data_From_Text_Field_To_The_Arayy();
                                                                                              Set_All_Text_Field_To_Defolt_Text();
                                                                                              JOptionPane.showMessageDialog(cont2,Name_set_Save_Data + "\nwas Created As PiceWorker", "Create",JOptionPane.INFORMATION_MESSAGE);
                                                                                              Countr_Index_Of_ArrayEmp ++;
                                                                                              Number_Stop_Create ++;
        

  • Constructing a linked list from an array of integers

    How do I create a linked list from an array of 28 integers in a constructor? The array of integers can be of any value that we desire. However we must use that array to test and debug methods such as getFirst(), getLast(), etc...
    I also have a method int getPosition(int position) where its suppose to return an element at the specified position. However, I get an error that says cannot find symbol: variable data or method next()
    public int getPosition(int position){
         LinkedListIterator iter=new LinkedListIterator();
         Node previous=null;
         Node current=first;
         if(position==0)
         return current.data;
         while(iter.hasMore()){
         iter.next();
         if(position==1)
         return iter.data;
         iter.next();
         if(position==2)
         return iter.data;
         iter.next();
         if(position==3)
         return iter.data;
         iter.next();
         if(position==4)
         return iter.data;
         iter.next();
         if(position==5)
         return iter.data;
         iter.next();
         if(position==6)
         return iter.data;
         iter.next();
         if(position==7)
         return iter.data;
         iter.next();
         if(position==8)
         return iter.data;
         iter.next();
         if(position==9)
         return iter.data;
         iter.next();
         if(position==10)
         return iter.data;
         iter.next();
         if(position==11)
         return iter.data;
         iter.next();
         if(position==12)
         return iter.data;
         iter.next();
         if(position==13)
         return iter.data;
         iter.next();
         if(position==14)
         return iter.data;
         iter.next();
         if(position==15)
         return iter.data;
         iter.next();
         if(position==16)
         return iter.data;
         iter.next();
         if(position==17)
         return iter.data;
         iter.next();
         if(position==18)
         return iter.data;
         iter.next();
         if(position==19)
         return iter.data;
         iter.next();
         if(position==20)
         return iter.data;
         iter.next();
         if(position==21)
         return iter.data;
         iter.next();
         if(position==22)
         return iter.data;
         iter.next();
         if(position==23)
         return iter.data;
         iter.next();
         if(position==24)
         return iter.data;
         iter.next();
         if(position==25)
         return iter.data;
         iter.next();
         if(position==26)
         return iter.data;
         iter.next();
         if(position==27)
         return iter.data;
         iter.next();
         if(position==28)
         return iter.data;
         if(position>28 || position<0)
         throw new NoSuchElementException();
         }

    How do I create a linked list from an array of 28 integers
    in a constructor? In a LinkedList constructor? If you check the LinkedList class (google 'java LinkedList'), there is no constructor that accepts an integer array.
    In a constructor of your own class? Use a for loop to step through your array and use the LinkedList add() method to add the elements of your array to your LinkedList.
    I get an error that
    says cannot find symbol: variable data or method
    next()If you look at the LinkedListIterator class (google, wait for it...."java LinkedListIterator"), you will see there is no next() method. Instead, you typically do the following to get an iterator:
    LinkedList myLL = new LinkedList();
    Iterator iter = myLL.iterator();
    The Iterator class has a next() method.

  • Re: array of references to linked lists

    Hi, im having a little problem seeing the wood from the tree...shouldnt be too hard for a fresh pair of eyes...ive been trying for a while now(read ages !!).
    I have an array which will be populated with seperate linked lists (StudentList class) which are populated from a console interface (prompt).
    It seems to work fine, however .. each list entered will overwrite the last by adding itself to it. eg :
    list 1 is added : adam 998 albert 999
    list 2 is added : john 123 jill 666
    lists[0].print() : jill 666 john 123 albert 999 adam 998
    lists[1].print() : jill 666 john 123 albert 999 adam 998
    it should give
    lists[0].print() : jill 666 john 123
    lists[1].print() : albert 999 adam 998
    the code is below,
    cheers for ANY help,
    ta.
    import java.io.*;
    import java.util.*;
    public class StudentId {
         public static void main(java.lang.String[] args) {
              StudentList[] lists = new StudentList[20];
              for (int i = 0; i < lists.length; i++) {
                   lists[i] = new StudentList();
              int n = 0;
              BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
              for(;;) {
                   System.out.print("Please enter a student record list> ");
                   try {
                        //StudentList list = new StudentList();
                        String line = in.readLine();
                        if (line.equals("quit")) {
                             break;
                        StringTokenizer tokenBag = new StringTokenizer (line," ");
                        while (tokenBag.hasMoreTokens()) {
                             try {
                                  String name = tokenBag.nextToken();
                                  String idString = tokenBag.nextToken();
                                  int id = Integer.parseInt(idString);
                                  lists[n].insert(name, id);
                             catch(Exception e) {
                                  System.out.println("Input error : " + e);
                   catch (Exception e) {
                        System.out.println("exception : " + e);
                   n += 1;
              for (int i=0; i<n; i++) {
                   System.out.println("element " + i);
                   lists.print();

    other class (Int node class is standard node class altered
    public class StudentList {
         private static IntNode head;
         private static int count;
         public StudentList() {
              head = null;
              count = 0;
         public boolean isEmpty() {
              if (count == 0) return true;
              else return false;
         public int size(){
              return count;
        public IntNode getHead() {
              return head;
         public void printHead() {
              System.out.println(head.getName() + " " + head.getId());
         public IntNode getTail() {
              IntNode cursor;
              for (cursor = head; cursor != null; cursor = cursor.getLink()) {
              return cursor;
         public void insert(String name, int id){
              head = new IntNode(name, id ,head);
              count++;
         public IntNode searchFor(String name) {
              IntNode cursor;
              cursor = head.listSearch(head, name);
              return cursor;
         public IntNode searchFor(int id) {
              IntNode cursor;
              cursor = head.listSearch(head, id);
              return cursor;
         public void print() {
              IntNode cursor = head;
              for (int i=0; i<count; i++) {
                   System.out.println(cursor.getName()+" "+cursor.getId());
                   cursor = cursor.getLink();
         public void insertListBefore(IntNode match, StudentList list) {
              IntNode preCursor = head.getPrevious(head, match);
              IntNode cursor;
              cursor = this.searchFor(match.getName());
              preCursor.setLink(list.getHead());
              list.getTail().setLink(cursor);
    }

  • Linked Lists with Arrays

    I am setting up a linked list of the following very simplified class:
    class LinkedList
         String Name=" ";
         double ID=0;
         static long next=0;
    }the main class is as follows:
    class Links
         public static void Display(LinkedList Link)
         /** A Display function that simply displays everything within the LinkedList class*/
         System.out.println("\nName: " + Link.Name +"\nID  #: " + Link.ID + "\nNext ID: " + Link.next);
         public static void main(String[] args)
              int MAX_LINKS=10;
              LinkedList[] Link=new LinkedList[MAX_LINKS];
              for (int i=0;i<MAX_LINKS;i++)
                   Link.ID=i;
                   Link[i].next++;
                   Display(Link[i]);
    everything compiles fine, but at runtime I recieve a
    Exception in thread "main" java.lang.NullPointerException
    at Links.Display(Links.java:6)
    at Links.main(Links.java:18)What am I doing wrong?
    Thanks in advance.

    public static void main(String[] args){
       int MAX_LINKS=10;
    // this tells the compiler that the Link array will hold
    //LinkedList objects, but doesn't actually create those objects...
       LinkedList[] Link=new LinkedList[MAX_LINKS];
       for (int i=0;i<MAX_LINKS;i++){
    //NEED TO ADD THIS LINE to create the objects:
          Link[ i ] = new LinkedList();
          Link[ i ].ID=i;
          Link[ i ].next++;
          Display(Link[ i ]);

  • Converting an array to a Linked list.

    I'm writing somewhat of a card game. One of the functions I'm supposed to have is the cut function. I'm supposed to split the deck into two and place the bottom half on top of the top half. My card objects are stored in Nodes in a programmer defined linked list. I believe I successfully converted the linked list into two array (top and bottom) but I am having problems with converting these back to LinkedList (atleast thats where I think my problem is) This is the code i had so far:
         public void cut()
              if (isEmpty())
                   throw new DeckException("Deck of Cards");
              else
                   int pivot = (int)(Math.random()*numCards);
                   Node top[] = new Node[pivot];
                   Node bottom[] = new Node[numCards-pivot];
                   Node traveller = front;
                            //Convert the linkedList into two arrays
                   for(int i = 0; i < numCards; i++)
                        if(i < pivot)
                             top[i] = traveller;
                             traveller = traveller.getNext();
                        else
                             bottom[i-pivot] = traveller;
                             traveller = traveller.getNext();
                            //Convert the two arrays back to a LinkedList, where bottom is put in the front of the list and top is put on the end
                   traveller = front;
                   for(int i = 0; i < numCards; i++)
                        if(i < bottom.length)
                                            //reference comment 1
                             traveller.setNext(bottom);
                             traveller = traveller.getNext();
                        else
    //reference comment 2
                             traveller.setNext(top[i-bottom.length]);
                             traveller = traveller.getNext();
         }I'm not really sure what I'm doing wrong but when i play around with the code I get alot of ArrayOutOfBounds error around the comment above marked as reference comment 1 and 2
    Can someone please give me guidance as to what I'm doing wrong? I feel as If I've reached a block i can't get past.
    EDIT: the variable numCards above should have the value 52
    Edited by: 806583 on Oct 31, 2010 11:12 PM

    My Node class is public. It does not implement the List Interface. This is my Node class:package project3;
    public class Node
      private Card data; //a reference to an object of type T
      private Node next; //the address of the next node in the list
       * default constructor - initializes data and next to null
      public Node()
           data = null;
           next = null;
       * parameterized constructor - initializes data to the user
       * specified value; next is set to null
       * @param newItem the value to be stored in the node
      public Node(Card newItem)
        data = newItem;
        next = null;
       * parameterized constructor - initializes data and next to user
       * specified values
       * @param newItem the object reference to be stored in the node
       * @param nextItem the reference to the next node in the list
      public Node(Card newItem, Node nextItem)
        data = newItem;
        next = nextItem;
       * setItem - stores a new value in data
       * @param newItem the object reference to be stored in the node
      public void setItem(Card newItem)
        data = newItem;
       * setNext - stores a new value in next
       * @param nextItem the reference to be stored in next
      public void setNext(Node nextItem)
        next = nextItem;
       * getItem - returns the reference stored in data
       * @return a reference to the data stored in the node
      public Card getItem()
        return data;
       * getNext - returns the reference stored in next
       * @return the reference stored in next
      public Node getNext()
        return next;
    }

  • ObservableList - "Linked list" or "Dynamic array"?

    I always assumed ObservableList (or more precisely, its implementation that is used to store child nodes) to be a linked list. Well, is it? :)
    Thanks for reading!

    stepan wrote:
    Unfortunately, java.util.List is itself only an interface. What I'm concerned with is an actual implementation (i.e. data structure used).
    Let me clarify my motivation by formulating the question more specifically: When dealing with an instance of ObservableList obtained by calling Parent's getChildren() method, will the get(int) method run in O(1) or O(size())? The latter would suggest it really may be a linked list...Previous answers mine included doesn't help much after I re-read your actual question :).
    Barring an actual answer from the Source (One of the Oracle engineers) vs the Source (code.....) I found an answer to your question after digging around in the private packages for a bit. Children nodes to a Parent are initially created as an ArrayList. I suppose its possible that ArrayList could be replaced later by some other implementation of List during a Class's use at runtime (some corner use-case where LinkedList is favored for insertion speed) - but when they are born they are ArrayLists.
    The javafx.scene.Parent class creates children as a VetoableObservableList()..
    private final ObservableList children = new VetoableObservableList() {
    };The constructor for class com.sun.javafx.collections.VetoableObservableList
    public VetoableObservableList()
            super(new ArrayList());
        }

  • After Delete in Linked list...unable to display the linked list

    Hi...i know that there is an implementation of the class Linked Link but i am required to show how the linked list works in this case for my project...please help...
    Yes..I tried to delete some objects in a linked list but after that i am not able to display the objects that were already in the linked list properly and instead it throws an NullPointerException.
    Below shows the relevant coding for deleting and listing the linked list...
    public Node remove(Comparator comparer) throws Exception {
         boolean found = false;
         Node prevnode = head;          //the node before the nextnode
         Node deletedNode = null;     //node deleted...
         //get next node and apply removal criteria
         for(Node nextnode = head.getNextNode(); nextnode != null; nextnode = nextnode.getNextNode()) {
              if(comparer.equals(nextnode)) {
                   found = true;
                   //remove the next node from the list and return it
                   prevnode.setNextNode(nextnode.getNextNode());
                   nextnode.setNextNode(null);
                   deletedNode = nextnode;
                   count = count - 1;
                   break;
         if (found) return deletedNode;
         else throw new Exception ("Not found !!!");
    public Object[] list() {
         //code to gather information into object array
         Node node;
         Object[] nodes = new Object[count];
         node = head.getNextNode();
         for (int i=0; i<count; i++) {
              nodes[i] = node.getInformation();  // this is the line that cause runtime error after deleting...but before deleting, it works without problem.
              node = node.getNextNode();
         return nodes;
    }Please help me in figuring out what went wrong with that line...so far i really can't see any problem with it but it still throws a NullPointerException
    Thanks

    OK -- I've had a cup and my systems are coming back on line...
    The problem looks to be the way that you are handling the pointer to the previous node in your deletion code. Essentially, that is not getting incremented along with the nextNode -- it is always pointing to head. So when you find the node to delete then the line
       prevnode.setNextNode(nextnode.getNextNode());will set the nextNode for head to be null in certain situations (like if you are removing the tail, for instance).
    Then when you try to print out the list, the first call you make is
    node = head.getNextNode();Which has been set to null, so you get an NPE when you try to access the information.
    Nothing like my favorite alkaloid to help things along on a Monday morning...
    - N

  • Need help regarding Linked List

    I'm a beginner who just spent ages working on the following code.. but need help on re-implementing the following using a linked list, i.e. no array is allowed for customer records but you still can use arrays for names, address, etc.. Hopefully I've inserted enough comments..
    Help very much appreciated!! Thanks! =]
    import java.util.Scanner;
    import java.io.*;
    public class Bank
    /* Private variables declared so that the data is only accessible to its own
         class, but not to any other class, thus preventing other classes from
         referring to the data directly */
    private static Customer[] customerList = new Customer[30];               
         //Array of 30 objects created for storing information of each customer
    private static int noOfCustomers;                                                       
         //Integer used to store number of customers in customerList
         public static void main(String[] args)
              Scanner sc = new Scanner(System.in);
              menu();
         public static void menu()
              char choice;
              String filename;
              int custId,counter=0;
              double interestRate;
    Scanner sc = new Scanner(System.in);
              do
              //Displaying of Program Menu for user to choose
         System.out.println("ABC Bank Customer Management System Menu");     
         System.out.println("========================================");
         System.out.println("(1) Input Data from File");
         System.out.println("(2) Display Data");
         System.out.println("(3) Output Data to File");
                   System.out.println("(4) Delete Record");
                   System.out.println("(5) Update Record");
         System.out.println("(Q) Quit");
                   System.out.println();
                   System.out.print("Enter your choice: ");
                   String input = sc.next();
                   System.out.println();
                   choice = input.charAt(0);     
              //switch statement used to assign each 'selection' to its 'operation'               
         switch(choice)
         case '1': int noOfRecords;
                                       System.out.print("Enter file name: ");
              sc.nextLine();                                             
              filename = sc.nextLine();
                                       System.out.println();
              noOfRecords = readFile(filename);
    System.out.println(+noOfRecords+" records read.");
              break;
         case '2': displayRecords();
              break;
         case '3': writeFile();
         break;
                        case '4': System.out.print("Enter account ID to be deleted: ");
                                       sc.nextLine();
                                       custId = sc.nextInt();
                                       deleteRecord(custId);
                                       break;
                        case '5': if(counter==0)
              System.out.print("Enter current interest rate for saving account: ");
                                            sc.nextLine();
                                            interestRate = sc.nextDouble();
                                            update(interestRate);
                                            counter++;
                                       else
              System.out.println("Error: Accounts have been updated for the month.");
                                            break;
                   }System.out.println();
         }while(choice!='Q' && choice!='q');
    /* The method readFile() loads the customer list of a Bank from a specified
         text file fileName into customerList to be stored as array of Customer
         objects in customerList in ascending alphabetical order according to the
         customer names */
    public static int readFile(String fileName)
         int custId,i=0;
              String custName,custAddress,custBirthdate,custPhone,custAccType;
              double custBalance,curRate;
              boolean d;
    /* Try block to enclose statements that might throw an exception, followed by
         the catch block to handle the exception */
    try
                   Scanner sc = new Scanner(new File(fileName));
    while(sc.hasNext())          
    /* sc.next() gets rid of "Account", "Id" and "=" */
    sc.next();sc.next();sc.next();
    custId = sc.nextInt();
                        d=checkDuplicate(custId);               
    /* checkDuplicate() is a method created to locate duplicating ids in array */
    if(d==true)
    /* A return value of true indicates duplicating record and the sc.nextLine()
         will get rid of all the following lines to read the next customer's record */
                             sc.nextLine();sc.nextLine();sc.nextLine();
                             sc.nextLine();sc.nextLine();sc.nextLine();
                             continue;     
    /* A return value of false indicates no duplicating record and the following
         lines containing the information of that customer's record is being read
         in */
                        if(d==false)
    /* sc.next() gets rid of "Name" and "=" and name is changed to upper case*/
         sc.next();sc.next();
         custName = sc.nextLine().toUpperCase();
    /* sc.nextLine get rids of the following lines to read the next customer's
         record if length of name is more than 20 characters*/
         if(custName.length()>21)
    System.out.println("Name of custId "+custId+" is more than 20 characters");
                                  System.out.println();
         sc.nextLine();sc.nextLine();sc.nextLine();sc.nextLine();
         continue;
    /* sc.next() gets rid of "Address" and "=" */           
         sc.next();sc.next();
         custAddress = sc.nextLine();
    /* sc.nextLine get rids of the following lines to read the next customer's
         record if length of address is more than 80 characters*/                         
                             if(custAddress.length()>81)
    System.out.println("Address of custId "+custId+" is more than 80 characters");
                                  System.out.println();
         sc.nextLine();sc.nextLine();sc.nextLine();sc.nextLine();
         continue;
    /* sc.next() gets rid of "DOB" and "=" */                              
         sc.next();sc.next();
         custBirthdate = sc.nextLine();
    /* sc.nextLine get rids of the following lines to read the next customer's
         record if length of date of birth is more than 10 characters*/                         
                             if(custBirthdate.length()>11)
    System.out.println("D.O.B of custId "+custId+" is more than 10 characters");
                                  System.out.println();
         sc.nextLine();sc.nextLine();sc.nextLine();sc.nextLine();
         continue;
    /* sc.next() gets rid of "Phone", "Number" and "=" */                              
         sc.next();sc.next();sc.next();
         custPhone = sc.nextLine();
    /* sc.nextLine get rids of the following lines to read the next customer's
         record if length of phone number is more than 8 characters*/                         
                             if(custPhone.length()>9)
    System.out.println("Phone no. of custId "+custId+" is more than 8 characters");
                                  System.out.println();
         sc.nextLine();sc.nextLine();sc.nextLine();sc.nextLine();
         continue;
    /* sc.next() gets rid of "Account", "Balance" and "=" */                              
         sc.next();sc.next();sc.next();
         custBalance = sc.nextDouble();
    /* sc.next() gets rid of "Account", "Type" and "=" */                              
                             sc.next();sc.next();sc.next();
                             custAccType = sc.next();
                             if(custAccType.equals("Saving"))
    customerList[noOfCustomers] = new Account1(custId,custName,custAddress,custBirthdate,custPhone,custBalance,custAccType);
    sc.nextLine();
                                                 noOfCustomers++;
                                                 i++;
    else if(custAccType.equals("Checking"))
    customerList[noOfCustomers] = new Account2(custId,custName,custAddress,custBirthdate,custPhone,custBalance,custAccType);
                                                 sc.nextLine();
                                                 noOfCustomers++;
                                                 i++;
    else if(custAccType.equals("Fixed"))
    sc.next();sc.next();sc.next();sc.next();
                                                 curRate = sc.nextDouble();
                                                 Account3 temp = new Account3(custId,custName,custAddress,custBirthdate,custPhone,custBalance,custAccType,curRate);
                                                 customerList[noOfCustomers]=temp;
                                                 sc.nextLine();
                                                 noOfCustomers++;
                                                 i++;
                             else
                                  System.out.println("Account type not defined.");
         if(noOfCustomers==30)
         System.out.println("The customer list has reached its maximum limit of 30 records!");
         System.out.println();
         return noOfCustomers;
    //Exceptions to be caught
    catch (FileNotFoundException e)
    System.out.println("Error opening file");
    System.exit(0);
    catch (IOException e)
    System.out.println("IO error!");
    System.exit(0);
    /* Bubblesort method used to sort the array in ascending alphabetical order
         according to customer's name */
    bubbleSort(customerList);
              return i;
    /* The method displayRecords() displays the data of the customer records on
         screen */
    public static void displayRecords()
    int k;
    /* Displaying text using the printf() method */
         for(k=0;k<noOfCustomers;k++)
         System.out.printf("Name = %s\n", customerList[k].getName());
         System.out.printf("Account Balance = %.2f\n", customerList[k].getBalance());
         System.out.printf("Account Id = %d\n", customerList[k].getId());
    System.out.printf("Address = %s\n", customerList[k].getAddress());
    System.out.printf("DOB = %s\n", customerList[k].getBirthdate());
    System.out.printf("Phone Number = %s\n", customerList[k].getPhone());
         String type = customerList[k].getAccType();
         System.out.println("Account Type = " +type);
    if(type.equals("Fixed"))
         System.out.println("Fixed daily interest = "+((Account3)customerList[k]).getFixed());
         System.out.println();               
    /* The method writeFile() saves the content from customerList into a
         specified text file. Data is printed on the screen at the same time */
    public static void writeFile()
    /* Try block to enclose statements that might throw an exception, followed by
    the catch block to handle the exception */
    try
    int i;
              int n=0;
    //PrintWriter class used to write contents of studentList to specified file
              FileWriter fwStream = new FileWriter("newCustomers.txt");
              BufferedWriter bwStream = new BufferedWriter(fwStream);
              PrintWriter pwStream = new PrintWriter(bwStream);     
    for(i=0;i<noOfCustomers;i++)
         pwStream.println("Account Id = "+customerList.getId());
              pwStream.println("Name = "+customerList[i].getName());
    pwStream.println("Address = "+customerList[i].getAddress());
    pwStream.println("DOB = "+customerList[i].getBirthdate());
    pwStream.println("Phone Number = "+customerList[i].getPhone());
              pwStream.printf("Account Balance = %.2f\n", customerList[i].getBalance());
              pwStream.println("Account Type = "+customerList[i].getAccType());
                   if(customerList[i].getAccType().equals("Fixed"))
                        pwStream.println("Fixed Daily Interest = "+((Account3)customerList[i]).getFixed());
              pwStream.println();
              n++;
    //Closure of stream
    pwStream.close();
              System.out.println(+n+" records written.");
    catch(IOException e)
    System.out.println("IO error!");     
    System.exit(0);
         //Deletes specified record from list
    public static void deleteRecord(int id)
    int i;
              i=locate(id);
    if(i==200)
    //checking if account to be deleted does not exist
    System.out.println("Error: no account with the id of "+id+" found!");
              //if account exists
    else
                        while(i<noOfCustomers)
                             customerList[i] = customerList[i+1];
                             i++;
                        System.out.println("Account Id: "+id+" has been deleted");
                        --noOfCustomers;
         //Updates the accounts
    public static void update(double interest)
    int i,j,k;
              double custBalance,addition=0;
    for(i=0;i<noOfCustomers;i++)
                        if(customerList[i] instanceof Account1)
                             for(j=0;j<30;j++)
                                  addition=customerList[i].getBalance()*interest;
                                  custBalance=customerList[i].getBalance()+addition;
                                  customerList[i].setBalance(custBalance);
                        else if(customerList[i] instanceof Account2)
                             continue;
                        else if(customerList[i] instanceof Account3)
                             for(j=0;j<30;j++)
    addition=customerList[i].getBalance()*((Account3)customerList[i]).getFixed();
    custBalance=customerList[i].getBalance()+addition;
    customerList[i].setBalance(custBalance);
                        else
                             System.out.println("Account type not defined");
              System.out.println("The updated balances are: \n");
              for(k=0;k<noOfCustomers;k++)
    System.out.printf("Name = %s\n", customerList[k].getName());
    System.out.printf("Account Balance = %.2f\n", customerList[k].getBalance());
    System.out.println();
    /* ================== Additional methods ==================== */     
    /* Bubblesort method to sort the customerList in ascending alphabetical
         order according to customer's name */
    public static void bubbleSort(Customer[] x)
    int pass, index;
    Customer tempValue;      
    for(pass=0; pass<noOfCustomers-1; pass++)          
    for(index=0; index<noOfCustomers-1; index++)
    if(customerList[index].getName().compareToIgnoreCase(customerList[index+1].getName()) > 0)
    tempValue = x[index];
    x[index] = x[index+1];
    x[index+1]= tempValue;
    /* Method used to check for duplicated ids in array */     
         public static boolean checkDuplicate(int id)
              int i;
              for(i=0;i<noOfCustomers;i++)
                   if(id == customerList[i].getId())
    System.out.println("Account Id = "+id+" already exists");
                        System.out.println();
    return true;
              }return false;
    /* Method to seach for account id in array */
         public static int locate(int id)
              int j;
              for(j=0;j<noOfCustomers;j++)
                   if(customerList[j].getId()==id)
                        return j;
              j=200;
              return j;
    import java.util.Scanner;
    public class Customer
    /* The following private variables are declared so that the data is only
         accessible to its own class,but not to any other class, thus preventing
         other classes from referring to the data directly */
         protected int id;               
         protected String name,address,birthdate,phone,accType;                              
         protected double balance;               
    // Null constructor of Customer
         public Customer()
              id = 0;
              name = null;
              address = null;
              birthdate = null;
              phone = null;
              balance = 0;
              accType = null;
    /* The following statements with the keyword this activates the Customer
         (int id, String name String address, String birthdate, String phone, double
         balance) constructor that has six parameters of account id, name, address,
         date of birth, phone number, account balance and assign the values of the
         parameters to the instance variables of the object */     
         public Customer(int id, String name, String address, String birthdate, String phone, double balance, String accType)
    //this is the object reference that stores the receiver object     
              this.id = id;
              this.name = name;                         
              this.address = address;
              this.birthdate = birthdate;
              this.phone = phone;
              this.balance = balance;
              this.accType = accType;
    /* The following get methods getId(), getName(), getAddress(), getBirthdate(),
         getPhone(), getBalance() return the values of the corresponding instance
         properties */     
         public int getId()
              return id;
         public String getName()
              return name;
         public String getAddress()
              return address;
         public String getBirthdate()
              return birthdate;
         public String getPhone()
              return phone;
         public double getBalance()
              return balance;
         public String getAccType()
              return accType;
    /* The following set methods setId(), setName(), setAddress(), setBirthdate(),
         setPhone and setBalance() set the values of the corresponding instance
         properties */
         public void setId (int custId)
              id = custId;
         public void setName(String custName)
              name = custName;
         public void setAddress (String custAddress)
              address = custAddress;
         public void setBirthdate (String custBirthdate)
              birthdate = custBirthdate;
         public void setPhone (String custPhone)
              phone = custPhone;
         public void setBalance (double custBalance)
              balance = custBalance;
         public void setAccType (String custAccType)
              accType = custAccType;
    class Account1 extends Customer
         public Account1(int id, String name, String address, String birthdate, String phone, double balance, String accType)
              super(id,name,address,birthdate,phone,balance,accType);
              this.id = id;
              this.name = name;                         
              this.address = address;
              this.birthdate = birthdate;
              this.phone = phone;
              this.balance = balance;
              this.accType = accType;
    class Account2 extends Customer
         public Account2(int id, String name, String address, String birthdate, String phone, double balance, String accType)
              super(id,name,address,birthdate,phone,balance,accType);
              this.id = id;
              this.name = name;                         
              this.address = address;
              this.birthdate = birthdate;
              this.phone = phone;
              this.balance = balance;
              this.accType = accType;
    class Account3 extends Customer
         protected double fixed=0;
         public Account3(int id, String name, String address, String birthdate, String phone, double balance, String accType, double fixed)
              super(id,name,address,birthdate,phone,balance,accType);
              this.id = id;
              this.name = name;                         
              this.address = address;
              this.birthdate = birthdate;
              this.phone = phone;
              this.balance = balance;
              this.accType = accType;
              this.fixed = fixed;
         public double getFixed()
              return fixed;
    Example of a customers.txt
    Account Id = 123
    Name = Matt Damon
    Address = 465 Ripley Boulevard, Oscar Mansion, Singapore 7666322
    DOB = 10-10-1970
    Phone Number = 790-3233
    Account Balance = 405600.00
    Account Type = Fixed
    Fixed Daily Interest = 0.05
    Account Id = 126
    Name = Ben Affleck
    Address = 200 Hunting Street, Singapore 784563
    DOB = 25-10-1968
    Phone Number = 432-4579
    Account Balance = 530045.00
    Account Type = Saving
    Account Id = 65
    Name = Salma Hayek
    Address = 45 Mexican Boulevard, Hotel California, Singapore 467822
    DOB = 06-04-73
    Phone Number = 790-0000
    Account Balance = 2345.00
    Account Type = Checking
    Account Id = 78
    Name = Phua Chu Kang
    Address = 50 PCK Avenue, Singapore 639798
    DOB = 11-08-64
    Phone Number = 345-6780
    Account Balance = 0.00
    Account Type = Checking
    Account Id = 234
    Name = Zoe Tay
    Address = 100 Blue Eyed St, Singapore 456872
    DOB = 15-02-68
    Phone Number = 456-1234
    Account Balance = 600.00
    Account Type = Saving

    1) When you post code, please use[code] and [/code] tags as described in Formatting tips on the message entry page. It makes it much easier to read.
    2) Don't just post a huge pile of code and ask, "How do I make this work?" Ask a specific question, and post just enough code to demonstrate the problem you're having.
    3) Don't just write a huge pile of code and then test it. Write a tiny piece, test it. Then write the piece that will work with or use the first piece. Test that by itself--without the first piece. Then put the two together and test that. Only move on to the next step after the current step produces the correct results. Continue this process until you have a complete, working program.

Maybe you are looking for

  • Regarding  File name schema in  Receiver  com. Channel

    Hello, I have gone thru  the blog The specified item was not found. "The same filename from a sender to a receiver file adapter - SP14 for Dynamic configuration"  by Michal Krawczyk....And here in this Scenario in ID (in Reeiver communiation channel)

  • OBIEE 11g Ago Function

    Hi All, I am using ago function in Answers it works fine But when observing the data, data is mismatched at particular Product category, why because two category s (A,B)   has same subcategory name (Basic) CAT       Sub Cat A  ------        Basic A 

  • SAP-BW Properties not available in Crystal & Missing Context Menu

    Dear experts, Creating a crystal report on a SAP-BW 3.5 query we have the following problem: In SAP-BW query we defined a restricted key figure with property 'Calculate single value as Ranked list (olympic)'. Within SAP-BW it works correctly; in Crys

  • Transaction being exected thrice

    Hello , my scenario has an transaction query which has transaction to insert few rows and then a grid-display template. whenever i execute transaction or transaction query independently,insertion of rows into database happens once as needed where as

  • How to install Reader X onto D:/

    Previously Adobe Reader version 9 was installed on drive D:/Program Files/Adobe/... During upgrade to Reader X, Adobe DLM did not offer option to select location.  Installation went to C:/Program Files/Adobe/... and all of version 9 was removed from