473,385 Members | 1,769 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

<disconnected>arrayproject

nomad
664 Expert 512MB
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>EmployeeData (1) [Java Application]
<disconnected>arrayproject.EmployeeData at localhost:1253
<terminated, exit value: 0>C:\Program Files\EasyEclipse Desktop Java 1.2.1\jre\bin\javaw.exe (May 9, 2007 2:04:22 PM)

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

Expand|Select|Wrap|Line Numbers
  1. class PersonClass {
  2.     private String empid;
  3.     private String lname;
  4.     private String fname;
  5.     private String street;
  6.     private String city;
  7.     private String state;
  8.     private String zip;
  9.     private double payrate;
  10.     private int yearsworked;
  11.     public PersonClass(String id) {
  12.         empid = id;
  13.     }
  14.     public PersonClass(String id, String ln, String fn, String st, String ct, String se, String zp, double pr, int yw) {
  15.         empid = id;
  16.         lname = ln;
  17.         fname = fn;
  18.         street = st;
  19.         city = ct;
  20.         state = se;
  21.         zip = zp;
  22.         payrate = pr;
  23.         yearsworked = yw;
  24.  
  25.     }
  26.  
  27.     // accessors
  28.     public String getID() {return empid;}
  29.  
  30.     public String getFname() {return fname;}
  31.  
  32.     public String getLname() {return lname;}
  33.  
  34.     public String getStree() {return street;}
  35.  
  36.  
  37.     public String getCity() {return city;}
  38.  
  39.     public String getState() {return state;}
  40.  
  41.     public String getZip() {return zip;}
  42.  
  43.     public double getPayrate() {return payrate;}
  44.  
  45.     public int getYearsworked() {return yearsworked;}
  46.  
  47.  
  48. }
  49.  
  50.  
  51. public class EmployeeData {
  52.     static ArrayList<PersonClass> arlist;
  53.     static Scanner kbd;
  54.  
  55.     public static PersonClass makePerson() {
  56.         PersonClass temp = null;
  57.  
  58.         // prompt for data
  59.         String id;
  60.         String ln;
  61.         String fn;
  62.         String st;
  63.         String se;
  64.         String ct;
  65.         String zp;
  66.         double pr;
  67.         int years;
  68.  
  69.         System.out.print("Enter ID Number ==>");
  70.         id = kbd.next();
  71.  
  72.         System.out.print("Enter Last Name ==>");
  73.         ln = kbd.next();
  74.  
  75.         System.out.print("Enter First Name ==>");
  76.         fn = kbd.next();
  77.  
  78.         System.out.print("Enter the address==>");
  79.         st = kbd.next();
  80.  
  81.         System.out.print("Enter City ==>");
  82.         ct = kbd.next();
  83.  
  84.         System.out.print("Enter State ==>");
  85.         se = kbd.next();
  86.  
  87.         System.out.print("Enter Zip ==>");
  88.         zp = kbd.next();
  89.  
  90.         System.out.print("Enter payrate as double ==>");
  91.         pr = kbd.nextDouble();
  92.  
  93.         System.out.print("Enter years worked ==>");
  94.         years = kbd.nextInt();
  95.  
  96.         // make an object
  97.         temp = new PersonClass(id, ln,fn,st,ct,se, zp, pr,years);
  98.  
  99.         return temp;
  100.     }
  101.  
  102.     public void displayMatch() {
  103.  
  104.     String id_flag = "";
  105.     Scanner kbd = new Scanner(System.in);
  106.     System.out.println("Enter your info please ie: AB1234: ");
  107.     id_flag = kbd.next();
  108.     boolean notfound = true;
  109.     for (PersonClass e : arlist) {
  110.         String emp = e.getID();
  111.         if (emp.equals(id_flag)) {
  112.             System.out.println("Hello" + ("e.lname"));
  113.             notfound = false;
  114.         }
  115.     }
  116.     if (notfound == true) {
  117.         System.out.println("Error - Employee not found");
  118.         // back to menu?
  119. }
  120.  
  121.     }//close findperson
  122.  
  123.     public static void main(String[] args) {
  124.         EmployeeData emp = new EmployeeData();
  125.         // make array list object
  126.         arlist = new ArrayList<PersonClass>();
  127.  
  128.         // make a scanner
  129.         kbd = new Scanner(System.in);
  130.  
  131.         int choice;
  132.         System.out.println("Make a Section: ");
  133.         System.out.println("1. Enter Employees ");
  134.         System.out.println("2. Find Employees ");
  135.         System.out.println("3. Exit this Program ");
  136.         System.out.print("\nPlease press Enter afer each response");
  137.         System.out.println("Enter your chose please: ");
  138.         choice = kbd.nextInt();
  139.         kbd.nextLine();
  140.         if (choice == 1) { // if 1 is select go to makePerson
  141.  
  142.         // create people until select stop
  143.         boolean endData = false;
  144.  
  145.         while (!endData) {
  146.             PersonClass temp = makePerson();
  147.             arlist.add(temp);
  148.             System.out.println("Add More employees (Y/N)-->");
  149.  
  150.             String ans = kbd.next();
  151.  
  152.             if (ans.equalsIgnoreCase("N")) {
  153.                 endData = true;
  154.             }
  155.         }//close while loop
  156.         if (choice == 2) { // if 2 is select go to find
  157.             emp.displayMatch();
  158.  
  159.  
  160.         }// close the choice==2
  161.         if (choice == 3) {
  162.             System.out.printf("Good bye");
  163.         }// close the choice == 3
  164.  
  165.  
  166.         // print out all elements of array list
  167.         for (PersonClass idx : arlist) {
  168.             System.out.printf("Employee Id is %n", idx.getID());
  169.                 System.out.printf("Name is %s - %s%n", idx.getFname(),idx.getLname());
  170.                 System.out.printf("Street is %s%n", idx.getStree());
  171.                 System.out.printf("City is %s%n", idx.getCity());
  172.                 System.out.printf("State is %s%n", idx.getState());
  173.                 System.out.printf("Zip Code is %s%n", idx.getZip());
  174.                 System.out.printf("Payrate is %8.2f%n", idx.getPayrate());
  175.                 System.out.printf("Years worked are %d\n", idx.getYearsworked());
  176.                 System.out.println("--------------------");
  177.         }
  178.     }
  179. }

Thanks a bunch
nomad
May 10 '07 #1
5 1250
JosAH
11,448 Expert 8TB
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
May 10 '07 #2
r035198x
13,262 8TB
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>EmployeeData (1) [Java Application]
<disconnected>arrayproject.EmployeeData at localhost:1253
<terminated, exit value: 0>C:\Program Files\EasyEclipse Desktop Java 1.2.1\jre\bin\javaw.exe (May 9, 2007 2:04:22 PM)

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

Expand|Select|Wrap|Line Numbers
  1. class PersonClass {
  2. private String empid;
  3. private String lname;
  4. private String fname;
  5. private String street;
  6. private String city;
  7. private String state;
  8. private String zip;
  9. private double payrate;
  10. private int yearsworked;
  11. public PersonClass(String id) {
  12.         empid = id;
  13. }
  14. public PersonClass(String id, String ln, String fn, String st, String ct, String se, String zp, double pr, int yw) {
  15.     empid = id;
  16.     lname = ln;
  17. fname = fn;
  18. street = st;
  19. city = ct;
  20. state = se;
  21. zip = zp;
  22. payrate = pr;
  23. yearsworked = yw;
  24.  
  25. }
  26.  
  27. // accessors
  28. public String getID() {return empid;}
  29.  
  30. public String getFname() {return fname;}
  31.  
  32. public String getLname() {return lname;}
  33.  
  34. public String getStree() {return street;}
  35.  
  36.  
  37. public String getCity() {return city;}
  38.  
  39. public String getState() {return state;}
  40.  
  41. public String getZip() {return zip;}
  42.  
  43. public double getPayrate() {return payrate;}
  44.  
  45. public int getYearsworked() {return yearsworked;}
  46.  
  47.  
  48. }
  49.  
  50.  
  51. public class EmployeeData {
  52. static ArrayList<PersonClass> arlist;
  53. static Scanner kbd;
  54.  
  55. public static PersonClass makePerson() {
  56. PersonClass temp = null;
  57.  
  58. // prompt for data
  59. String id;
  60. String ln;
  61. String fn;
  62. String st;
  63. String se;
  64. String ct;
  65. String zp;
  66. double pr;
  67. int years;
  68.  
  69. System.out.print("Enter ID Number ==>");
  70. id = kbd.next();
  71.  
  72. System.out.print("Enter Last Name ==>");
  73. ln = kbd.next();
  74.  
  75. System.out.print("Enter First Name ==>");
  76. fn = kbd.next();
  77.  
  78. System.out.print("Enter the address==>");
  79. st = kbd.next();
  80.  
  81. System.out.print("Enter City ==>");
  82. ct = kbd.next();
  83.  
  84. System.out.print("Enter State ==>");
  85. se = kbd.next();
  86.  
  87. System.out.print("Enter Zip ==>");
  88. zp = kbd.next();
  89.  
  90. System.out.print("Enter payrate as double ==>");
  91. pr = kbd.nextDouble();
  92.  
  93. System.out.print("Enter years worked ==>");
  94. years = kbd.nextInt();
  95.  
  96. // make an object
  97. temp = new PersonClass(id, ln,fn,st,ct,se, zp, pr,years);
  98.  
  99. return temp;
  100. }
  101.  
  102. public void displayMatch() {
  103.  
  104. String id_flag = "";
  105.     Scanner kbd = new Scanner(System.in);
  106.     System.out.println("Enter your info please ie: AB1234: ");
  107.     id_flag = kbd.next();
  108.     boolean notfound = true;
  109.     for (PersonClass e : arlist) {
  110.         String emp = e.getID();
  111.         if (emp.equals(id_flag)) {
  112.             System.out.println("Hello" + ("e.lname"));
  113.             notfound = false;
  114.         }
  115.     }
  116.     if (notfound == true) {
  117.         System.out.println("Error - Employee not found");
  118.         // back to menu?
  119. }
  120.  
  121. }//close findperson
  122.  
  123. public static void main(String[] args) {
  124.     EmployeeData emp = new EmployeeData();
  125. // make array list object
  126. arlist = new ArrayList<PersonClass>();
  127.  
  128. // make a scanner
  129. kbd = new Scanner(System.in);
  130.  
  131. int choice;
  132.         System.out.println("Make a Section: ");
  133.         System.out.println("1. Enter Employees ");
  134.         System.out.println("2. Find Employees ");
  135.         System.out.println("3. Exit this Program ");
  136.         System.out.print("\nPlease press Enter afer each response");
  137.         System.out.println("Enter your chose please: ");
  138.         choice = kbd.nextInt();
  139.         kbd.nextLine();
  140.         if (choice == 1) { // if 1 is select go to makePerson
  141.  
  142. // create people until select stop
  143. boolean endData = false;
  144.  
  145. while (!endData) {
  146. PersonClass temp = makePerson();
  147. arlist.add(temp);
  148. System.out.println("Add More employees (Y/N)-->");
  149.  
  150. String ans = kbd.next();
  151.  
  152. if (ans.equalsIgnoreCase("N")) {
  153. endData = true;
  154. }
  155. }//close while loop
  156. if (choice == 2) { // if 2 is select go to find
  157.     emp.displayMatch();
  158.  
  159.  
  160. }// close the choice==2
  161.         if (choice == 3) {
  162.             System.out.printf("Good bye");
  163.         }// close the choice == 3
  164.  
  165.  
  166. // print out all elements of array list
  167. for (PersonClass idx : arlist) {
  168.     System.out.printf("Employee Id is %n", idx.getID());
  169. System.out.printf("Name is %s - %s%n", idx.getFname(),idx.getLname());
  170. System.out.printf("Street is %s%n", idx.getStree());
  171. System.out.printf("City is %s%n", idx.getCity());
  172. System.out.printf("State is %s%n", idx.getState());
  173. System.out.printf("Zip Code is %s%n", idx.getZip());
  174. System.out.printf("Payrate is %8.2f%n", idx.getPayrate());
  175. System.out.printf("Years worked are %d\n", idx.getYearsworked());
  176. System.out.println("--------------------");
  177. }
  178. }
  179. }

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?
May 10 '07 #3
nomad
664 Expert 512MB
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
May 10 '07 #4
JosAH
11,448 Expert 8TB
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 responsibilities another method could easily
do better. This lazy attitude leads to something like:
Expand|Select|Wrap|Line Numbers
  1. public static void main(String[] args) {
  2.    doApplication();
  3.    cleanUp();
  4. }
  5. private static void doApplication() {
  6.    int choice;
  7.    for (;;) { // keep on processing choices
  8.       switch (choice= selectChoice()) {
  9.          case 1: enterPerson(); break;
  10.          case 2: findPerson(); break;
  11.          case 3: return;
  12.       }
  13.    }
  14. }
  15.  
  16. private static void enterPerson() { ... }
  17. private static void findPerson() { ... }
  18. private static int selectChoice() { ... }
  19. // 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
May 10 '07 #5
nomad
664 Expert 512MB
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 responsibilities another method could easily
do better. This lazy attitude leads to something like:
Expand|Select|Wrap|Line Numbers
  1. public static void main(String[] args) {
  2.    doApplication();
  3.    cleanUp();
  4. }
  5. private static void doApplication() {
  6.    int choice;
  7.    for (;;) { // keep on processing choices
  8.       switch (choice= selectChoice()) {
  9.          case 1: enterPerson(); break;
  10.          case 2: findPerson(); break;
  11.          case 3: return;
  12.       }
  13.    }
  14. }
  15.  
  16. private static void enterPerson() { ... }
  17. private static void findPerson() { ... }
  18. private static int selectChoice() { ... }
  19. // 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.
May 10 '07 #6

Sign in to post your reply or Sign up for a free account.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.