<disconnected>arrayproject

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • nomad
    Recognized Expert Contributor
    • Mar 2007
    • 664

    <disconnected>arrayproject

    I can not invoke the findPerson method. It should work because I have done this in the past.
    I did a debug and got this error.

    <terminated>Emp loyeeData (1) [Java Application]
    <disconnected>a rrayproject.Emp loyeeData at localhost:1253
    <terminated, exit value: 0>C:\Program Files\EasyEclip se Desktop Java 1.2.1\jre\bin\j avaw.exe (May 9, 2007 2:04:22 PM)

    I have attached my whole project and if someone can help me that would be great..

    Code:
    class PersonClass {
        private String empid;
        private String lname;
        private String fname;
        private String street;
        private String city;
        private String state;
        private String zip;
        private double payrate;
        private int yearsworked;
        public PersonClass(String id) {
    		empid = id;
        }
        public PersonClass(String id, String ln, String fn, String st, String ct, String se, String zp, double pr, int yw) {
        	empid = id;
        	lname = ln;
            fname = fn;
            street = st;
            city = ct;
            state = se;
            zip = zp;
            payrate = pr;
            yearsworked = yw;
     
        }
     
        // accessors
        public String getID() {return empid;}
     
        public String getFname() {return fname;}
     
        public String getLname() {return lname;}
     
        public String getStree() {return street;}
     
     
        public String getCity() {return city;}
     
        public String getState() {return state;}
     
        public String getZip() {return zip;}
     
        public double getPayrate() {return payrate;}
     
        public int getYearsworked() {return yearsworked;}
     
     
    }
     
     
    public class EmployeeData {
        static ArrayList<PersonClass> arlist;
        static Scanner kbd;
     
        public static PersonClass makePerson() {
            PersonClass temp = null;
     
            // prompt for data
            String id;
            String ln;
            String fn;
            String st;
            String se;
            String ct;
            String zp;
            double pr;
            int years;
     
            System.out.print("Enter ID Number ==>");
            id = kbd.next();
     
            System.out.print("Enter Last Name ==>");
            ln = kbd.next();
     
            System.out.print("Enter First Name ==>");
            fn = kbd.next();
     
            System.out.print("Enter the address==>");
            st = kbd.next();
     
            System.out.print("Enter City ==>");
            ct = kbd.next();
     
            System.out.print("Enter State ==>");
            se = kbd.next();
     
            System.out.print("Enter Zip ==>");
            zp = kbd.next();
     
            System.out.print("Enter payrate as double ==>");
            pr = kbd.nextDouble();
     
            System.out.print("Enter years worked ==>");
            years = kbd.nextInt();
     
            // make an object
            temp = new PersonClass(id, ln,fn,st,ct,se, zp, pr,years);
     
            return temp;
        }
     
        public void displayMatch() {
     
        String id_flag = "";
    	Scanner kbd = new Scanner(System.in);
    	System.out.println("Enter your info please ie: AB1234: ");
    	id_flag = kbd.next();
    	boolean notfound = true;
    	for (PersonClass e : arlist) {
    		String emp = e.getID();
    		if (emp.equals(id_flag)) {
    			System.out.println("Hello" + ("e.lname"));
    			notfound = false;
    		}
    	}
    	if (notfound == true) {
    		System.out.println("Error - Employee not found");
    		// back to menu?
    }
     
        }//close findperson
     
        public static void main(String[] args) {
        	EmployeeData emp = new EmployeeData();
            // make array list object
            arlist = new ArrayList<PersonClass>();
     
            // make a scanner
            kbd = new Scanner(System.in);
     
            int choice;
    		System.out.println("Make a Section: ");
    		System.out.println("1. Enter Employees ");
    		System.out.println("2. Find Employees ");
    		System.out.println("3. Exit this Program ");
    		System.out.print("\nPlease press Enter afer each response");
    		System.out.println("Enter your chose please: ");
    		choice = kbd.nextInt();
    		kbd.nextLine();
    		if (choice == 1) { // if 1 is select go to makePerson
     
            // create people until select stop
            boolean endData = false;
     
            while (!endData) {
                PersonClass temp = makePerson();
                arlist.add(temp);
                System.out.println("Add More employees (Y/N)-->");
     
                String ans = kbd.next();
     
                if (ans.equalsIgnoreCase("N")) {
                    endData = true;
                }
            }//close while loop
            if (choice == 2) { // if 2 is select go to find
            	emp.displayMatch();
     
     
            }// close the choice==2
    		if (choice == 3) {
    			System.out.printf("Good bye");
    		}// close the choice == 3
     
     
            // print out all elements of array list
            for (PersonClass idx : arlist) {
            	System.out.printf("Employee Id is %n", idx.getID());
                    System.out.printf("Name is %s - %s%n", idx.getFname(),idx.getLname());
                    System.out.printf("Street is %s%n", idx.getStree());
                    System.out.printf("City is %s%n", idx.getCity());
                    System.out.printf("State is %s%n", idx.getState());
                    System.out.printf("Zip Code is %s%n", idx.getZip());
                    System.out.printf("Payrate is %8.2f%n", idx.getPayrate());
                    System.out.printf("Years worked are %d\n", idx.getYearsworked());
                    System.out.println("--------------------");
            }
        }
    }
    }

    Thanks a bunch
    nomad
  • JosAH
    Recognized Expert MVP
    • Mar 2007
    • 11453

    #2
    Originally posted by nomad
    I can not invoke the findPerson method. It should work because I have done this in the past.
    Just color me silly but I can't find a method definition of 'findPerson' ...

    kind regards,

    Jos

    Comment

    • r035198x
      MVP
      • Sep 2006
      • 13225

      #3
      Originally posted by nomad
      I can not invoke the findPerson method. It should work because I have done this in the past.
      I did a debug and got this error.

      <terminated>Emp loyeeData (1) [Java Application]
      <disconnected>a rrayproject.Emp loyeeData at localhost:1253
      <terminated, exit value: 0>C:\Program Files\EasyEclip se Desktop Java 1.2.1\jre\bin\j avaw.exe (May 9, 2007 2:04:22 PM)

      I have attached my whole project and if someone can help me that would be great..

      Code:
      class PersonClass {
      private String empid;
      private String lname;
      private String fname;
      private String street;
      private String city;
      private String state;
      private String zip;
      private double payrate;
      private int yearsworked;
      public PersonClass(String id) {
      		empid = id;
      }
      public PersonClass(String id, String ln, String fn, String st, String ct, String se, String zp, double pr, int yw) {
      	empid = id;
      	lname = ln;
      fname = fn;
      street = st;
      city = ct;
      state = se;
      zip = zp;
      payrate = pr;
      yearsworked = yw;
       
      }
       
      // accessors
      public String getID() {return empid;}
       
      public String getFname() {return fname;}
       
      public String getLname() {return lname;}
       
      public String getStree() {return street;}
       
       
      public String getCity() {return city;}
       
      public String getState() {return state;}
       
      public String getZip() {return zip;}
       
      public double getPayrate() {return payrate;}
       
      public int getYearsworked() {return yearsworked;}
       
       
      }
       
       
      public class EmployeeData {
      static ArrayList<PersonClass> arlist;
      static Scanner kbd;
       
      public static PersonClass makePerson() {
      PersonClass temp = null;
       
      // prompt for data
      String id;
      String ln;
      String fn;
      String st;
      String se;
      String ct;
      String zp;
      double pr;
      int years;
       
      System.out.print("Enter ID Number ==>");
      id = kbd.next();
       
      System.out.print("Enter Last Name ==>");
      ln = kbd.next();
       
      System.out.print("Enter First Name ==>");
      fn = kbd.next();
       
      System.out.print("Enter the address==>");
      st = kbd.next();
       
      System.out.print("Enter City ==>");
      ct = kbd.next();
       
      System.out.print("Enter State ==>");
      se = kbd.next();
       
      System.out.print("Enter Zip ==>");
      zp = kbd.next();
       
      System.out.print("Enter payrate as double ==>");
      pr = kbd.nextDouble();
       
      System.out.print("Enter years worked ==>");
      years = kbd.nextInt();
       
      // make an object
      temp = new PersonClass(id, ln,fn,st,ct,se, zp, pr,years);
       
      return temp;
      }
       
      public void displayMatch() {
       
      String id_flag = "";
      	Scanner kbd = new Scanner(System.in);
      	System.out.println("Enter your info please ie: AB1234: ");
      	id_flag = kbd.next();
      	boolean notfound = true;
      	for (PersonClass e : arlist) {
      		String emp = e.getID();
      		if (emp.equals(id_flag)) {
      			System.out.println("Hello" + ("e.lname"));
      			notfound = false;
      		}
      	}
      	if (notfound == true) {
      		System.out.println("Error - Employee not found");
      		// back to menu?
      }
       
      }//close findperson
       
      public static void main(String[] args) {
      	EmployeeData emp = new EmployeeData();
      // make array list object
      arlist = new ArrayList<PersonClass>();
       
      // make a scanner
      kbd = new Scanner(System.in);
       
      int choice;
      		System.out.println("Make a Section: ");
      		System.out.println("1. Enter Employees ");
      		System.out.println("2. Find Employees ");
      		System.out.println("3. Exit this Program ");
      		System.out.print("\nPlease press Enter afer each response");
      		System.out.println("Enter your chose please: ");
      		choice = kbd.nextInt();
      		kbd.nextLine();
      		if (choice == 1) { // if 1 is select go to makePerson
       
      // create people until select stop
      boolean endData = false;
       
      while (!endData) {
      PersonClass temp = makePerson();
      arlist.add(temp);
      System.out.println("Add More employees (Y/N)-->");
       
      String ans = kbd.next();
       
      if (ans.equalsIgnoreCase("N")) {
      endData = true;
      }
      }//close while loop
      if (choice == 2) { // if 2 is select go to find
      	emp.displayMatch();
       
       
      }// close the choice==2
      		if (choice == 3) {
      			System.out.printf("Good bye");
      		}// close the choice == 3
       
       
      // print out all elements of array list
      for (PersonClass idx : arlist) {
      	System.out.printf("Employee Id is %n", idx.getID());
      System.out.printf("Name is %s - %s%n", idx.getFname(),idx.getLname());
      System.out.printf("Street is %s%n", idx.getStree());
      System.out.printf("City is %s%n", idx.getCity());
      System.out.printf("State is %s%n", idx.getState());
      System.out.printf("Zip Code is %s%n", idx.getZip());
      System.out.printf("Payrate is %8.2f%n", idx.getPayrate());
      System.out.printf("Years worked are %d\n", idx.getYearsworked());
      System.out.println("--------------------");
      }
      }
      }
      }

      Thanks a bunch
      nomad
      Are you able to "run other methods" besides the one that silly colored Jos couldn't find?
      Also can you explain how you are running the method and the exact behaviour of the system after running it?

      Comment

      • nomad
        Recognized Expert Contributor
        • Mar 2007
        • 664

        #4
        Yes if I choose 1 and type the info in it will print out the info.
        if I select 2 it will hang up and show no report.
        I think my for loop is wrong...but Don't know why.
        also it will not work in choose 1 if I type in a dup. id number.
        I'm using Eclipse and use debug to find the errors above.
        If the loop is bad I hope you can help me figure it out, because I want to do this the article... I don't want to look dumb.

        Sorry about that one jos
        I can not invoke the findPerson method it should say displayMatch()


        thanks
        sandyw

        Comment

        • JosAH
          Recognized Expert MVP
          • Mar 2007
          • 11453

          #5
          Personally I find the body of that mainI() method quite messy. As a rule of thumb
          create a separate method for every single task/action. Every method should do
          one thing and it should do it well. No more and no less, i.e. no convoluted and
          complicated control flow and no responsibilitie s another method could easily
          do better. This lazy attitude leads to something like:
          Code:
          public static void main(String[] args) {
             doApplication();
             cleanUp();
          }
          private static void doApplication() {
             int choice;
             for (;;) { // keep on processing choices
                switch (choice= selectChoice()) {
                   case 1: enterPerson(); break;
                   case 2: findPerson(); break;
                   case 3: return;
                }
             }
          }
          
          private static void enterPerson() { ... }
          private static void findPerson() { ... }
          private static int selectChoice() { ... }
          // etc. etc. etc.
          This way every method you write you can concentrate on the simpke task it
          is supposed to fullfill. Other program logic belongs to another method and this
          way you end up with simpler code which is easier to maintain too. Noone wants
          to maintain lenghts of wallpaper code that wobbles from left to right and back
          again over and over.

          kind regards,

          Jos

          Comment

          • nomad
            Recognized Expert Contributor
            • Mar 2007
            • 664

            #6
            Originally posted by JosAH
            Personally I find the body of that mainI() method quite messy. As a rule of thumb
            create a separate method for every single task/action. Every method should do
            one thing and it should do it well. No more and no less, i.e. no convoluted and
            complicated control flow and no responsibilitie s another method could easily
            do better. This lazy attitude leads to something like:
            Code:
            public static void main(String[] args) {
               doApplication();
               cleanUp();
            }
            private static void doApplication() {
               int choice;
               for (;;) { // keep on processing choices
                  switch (choice= selectChoice()) {
                     case 1: enterPerson(); break;
                     case 2: findPerson(); break;
                     case 3: return;
                  }
               }
            }
            
            private static void enterPerson() { ... }
            private static void findPerson() { ... }
            private static int selectChoice() { ... }
            // etc. etc. etc.
            This way every method you write you can concentrate on the simpke task it
            is supposed to fullfill. Other program logic belongs to another method and this
            way you end up with simpler code which is easier to maintain too. Noone wants
            to maintain lenghts of wallpaper code that wobbles from left to right and back
            again over and over.

            kind regards,

            Jos
            Thanks Jos.
            One learns from examples ie my instructor wrote his code simular to mine, I rather start doing your well, rather than later.

            Comment

            Working...