I created the same program before But this one doesnt work ?

Reply

Join Date: Oct 2009
Posts: 5
Reputation: ahmedshayan is an unknown quantity at this point 
Solved Threads: 0
ahmedshayan ahmedshayan is offline Offline
Newbie Poster

I created the same program before But this one doesnt work ?

 
0
  #1
34 Days Ago
Write a class Employee. An employee has a private first name (string), private last name (string), private job title (string), private employment ID (string), private monthly income (double), private joining date (string), and private mailing address (string). Provide a default constructor, a parameterized constructor, and a clone constructor. Write separate setters and getters for each private instance variable. Your Employee class should also keep track of number of employees that have been added to your system.

Write another class BusinessConcern, which acts as your main class. Inside main method, create a one-dimensional array of objects of Employee type. At the start of your program, it should prompt for total number of employee records to be added to the system. After creating an array of desired number of employees, your program shall provide a console-based menu to user with following options:
1) New Employee Record (input: values for initialization of instance variables of new employee object/instance)
2) Change Job Title (required input: employment ID, new job title)
3) Change Monthly Income (required input: employment ID, new monthly income)
4) Change Mailing Address (required input: employment ID, new mailing address)
5) Employee Details (required input: employment ID)
6) List All Available Records
7) Exit Program
I have been working on this project for quit some hours .... But it seems to be not working ... here is the class Employee
  1. import javax.swing.JOptionPane;
  2. class Employee
  3. {
  4. private String firstName;
  5. private String lastName;
  6. private String jobTitle;
  7. private String employeeID;
  8. private double monthlyIncome;
  9. private String joiningDate;
  10. private String mailingAddress;
  11. static int count=0;
  12.  
  13. Employee()
  14. {
  15. firstName=" " ;
  16. lastName=" " ;
  17. jobTitle=" " ;
  18. employeeID=" " ;
  19. monthlyIncome=0.0;
  20. joiningDate=" " ;
  21. mailingAddress=" " ;
  22. count++;
  23. }
  24. Employee(String f,String l,String j,String e,double m,String join,String mail)
  25. {
  26. firstName=f ;
  27. lastName=l ;
  28. jobTitle=j ;
  29. employeeID=e ;
  30. monthlyIncome=m;
  31. joiningDate=join ;
  32. mailingAddress=mail ;
  33. count++;
  34. }
  35. Employee(Employee emp)
  36. {
  37. firstName=emp.firstName;
  38. lastName=emp.lastName;
  39. jobTitle=emp.jobTitle ;
  40. employeeID=emp.employeeID ;
  41. monthlyIncome=emp.monthlyIncome;
  42. joiningDate=emp.joiningDate ;
  43. mailingAddress=emp.mailingAddress ;
  44. count++;
  45. }
  46.  
  47. void setfirstName(String f)
  48. {
  49. firstName=f;
  50. }
  51. void setlastName(String l)
  52. {
  53. lastName=l;
  54. }
  55. void setjobTitle(String j)
  56. {
  57. jobTitle=j;
  58. }
  59. void setemployeeID(String e)
  60. {
  61. employeeID=e;
  62. }
  63. void setmonthlyIncome(double m)
  64. {
  65. monthlyIncome=m;
  66. }
  67. void setjoiningDate(String join)
  68. {
  69. joiningDate=join;
  70. }
  71. void setmailingAddress(String mail)
  72. {
  73. mailingAddress=mail;
  74. }
  75.  
  76. String getfirstName()
  77. {
  78. return firstName;
  79. }
  80. String getlastName()
  81. {
  82. return lastName;
  83. }
  84. String getjobTitle()
  85. {
  86. return jobTitle;
  87. }
  88. String getemployeeID()
  89. {
  90. return employeeID;
  91. }
  92. double getmonthlyIncome()
  93. {
  94. return monthlyIncome;
  95. }
  96. String getjoiningDate()
  97. {
  98. return joiningDate;
  99. }
  100. String getmailingAddress()
  101. {
  102. return mailingAddress;
  103. }
  104. //NEW EMPLOYEE
  105. void NewEmployee()
  106. {
  107. String f=JOptionPane.showInputDialog("Enter your First Name:");
  108. setfirstName(f);
  109. String l=JOptionPane.showInputDialog("Enter your Last Name:");
  110. setlastName(l);
  111. String j=JOptionPane.showInputDialog("Enter your Job Title:");
  112. setjobTitle(j);
  113. String e=JOptionPane.showInputDialog("Enter your Employee ID:");
  114. setemployeeID(e);
  115. double m=Double.parseDouble(JOptionPane.showInputDialog("Enter your Monthly Income:"));
  116. setmonthlyIncome(m);
  117. String join=JOptionPane.showInputDialog("Enter your Joining Date:");
  118. setjoiningDate(join);
  119. String mail=JOptionPane.showInputDialog("Enter your Mailing Address:");
  120. setmailingAddress(mail);
  121. }
  122. //JOB TITLE
  123. void JobTitle(String empID,Employee[] list,String n)
  124. {
  125. String test;
  126. for(int i=0;i<list.length;i++){
  127. test=list[i].getjobTitle();
  128. if(empID.equals(test)){
  129. System.out.println("found it !");
  130. list[i].setjobTitle(n);
  131. System.out.println("Your Job Title has been changed to "+ list[i].getjobTitle());
  132. }
  133. else
  134. continue;
  135. }
  136. }
  137. /*void JobTitle(Employee[] list)
  138. {
  139. String empID=JOptionPane.showInputDialog("Enter your Employee ID:");
  140. String n=JOptionPane.showInputDialog("Enter your New Job Title:");
  141. for(int i=0;i<list.length;i++){
  142. if(empID.equals(list[i].getjobTitle())){
  143. list[i].setjobTitle(n);
  144. System.out.println("Your Job Title has been changed to "+ list[i].getjobTitle());
  145. }
  146. else
  147. continue;
  148. }
  149. }*/
  150. }//FINAL BRACKET

and here is the BusinessConcern class which also the main class ...
  1. import java.util.Scanner;
  2. import javax.swing.JOptionPane;
  3. class BusinessConcern{
  4. public static void main(String []args){
  5. String empID,n;
  6. //Scanner enter=new Scanner(System.in);
  7. //System.out.print("How many account(s) do wish to create ? ");
  8. //int num=enter.nextInt();
  9. int num=Integer.parseInt(JOptionPane.showInputDialog("How many account(s) do wish to create ? "));
  10. Employee acc[]=new Employee[num];
  11. for(int i=0;i<acc.length;i++){
  12. acc[i]=new Employee();
  13.  
  14. int choice=0;
  15.  
  16. System.out.println("What do you want to do ? ");
  17. System.out.println("New Employee (1)");
  18. System.out.println("Change Job Title (2)");
  19. System.out.println("Change Monthly Income (3)");
  20. System.out.println("Change Mailing Address (4)");
  21. System.out.println("Employee Details (5)");
  22. System.out.println("Available Records (6)");
  23. System.out.println("Exit (7)");
  24.  
  25. choice=Integer.parseInt(JOptionPane.showInputDialog("Enter your choice"));
  26.  
  27. switch(choice){
  28. case 1:
  29. acc[i].NewEmployee();
  30. System.out.println(acc[i].getjobTitle());
  31. break;
  32. case 2:
  33. empID=JOptionPane.showInputDialog("Enter your Employee ID:");
  34. n=JOptionPane.showInputDialog("Enter your New Job Title:");
  35. acc[i].JobTitle(empID,acc,n);
  36. break;
  37. case 7:
  38. System.exit(0);
  39. break;
  40.  
  41. }
  42. }
  43.  
  44. }//2ND LAST
  45. }//LAST BRACKET
Thanks in Advance .
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 1,658
Reputation: javaAddict is a name known to all javaAddict is a name known to all javaAddict is a name known to all javaAddict is a name known to all javaAddict is a name known to all javaAddict is a name known to all 
Solved Threads: 223
Featured Poster
javaAddict's Avatar
javaAddict javaAddict is online now Online
Posting Virtuoso
 
0
  #2
34 Days Ago
Like I mentioned in this link:
http://www.daniweb.com/forums/thread232042.html

The JobTitle method shouldn't be in the Employee class but in the main method
Check out my New Bike at my Public Profile at the "About Me" tab
Reply With Quote Quick reply to this message  
Join Date: Oct 2009
Posts: 5
Reputation: ahmedshayan is an unknown quantity at this point 
Solved Threads: 0
ahmedshayan ahmedshayan is offline Offline
Newbie Poster
 
0
  #3
34 Days Ago
this is what i did
  1. import java.util.Scanner;
  2. import javax.swing.JOptionPane;
  3. class BusinessConcern{
  4. public static void main(String []args){
  5. String empID,n;
  6. //Scanner enter=new Scanner(System.in);
  7. //System.out.print("How many account(s) do wish to create ? ");
  8. //int num=enter.nextInt();
  9. int num=Integer.parseInt(JOptionPane.showInputDialog("How many account(s) do wish to create ? "));
  10. Employee acc[]=new Employee[num];
  11. for(int i=0;i<acc.length;i++){
  12. acc[i]=new Employee();
  13.  
  14. int choice=0;
  15.  
  16. System.out.println("What do you want to do ? ");
  17. System.out.println("New Employee (1)");
  18. System.out.println("Change Job Title (2)");
  19. System.out.println("Change Monthly Income (3)");
  20. System.out.println("Change Mailing Address (4)");
  21. System.out.println("Employee Details (5)");
  22. System.out.println("Available Records (6)");
  23. System.out.println("Exit (7)");
  24.  
  25. choice=Integer.parseInt(JOptionPane.showInputDialog("Enter your choice"));
  26.  
  27. switch(choice){
  28. case 1:
  29. acc[i].NewEmployee();
  30. System.out.println(acc[i].getjobTitle());
  31. break;
  32.  
  33. case 2:
  34. empID=JOptionPane.showInputDialog("Enter your Employee ID:");
  35.  
  36. /*acc[i].JobTitle(empID,acc,n);
  37. break;*/
  38. for(int j=0;j<acc.length;j++){
  39. if(empID.equals(acc[i].getjobTitle())){
  40. acc[i].JobTitle();
  41. System.out.println(acc[i].getjobTitle());
  42. }
  43. }
  44. break;
  45. case 7:
  46. System.exit(0);
  47. break;
  48.  
  49. }
  50. }
  51.  
  52. }//2ND LAST
  53. }//LAST BRACKET

and what i comprehended ...
  1. import javax.swing.JOptionPane;
  2. class Employee
  3. {
  4. private String firstName;
  5. private String lastName;
  6. private String jobTitle;
  7. private String employeeID;
  8. private double monthlyIncome;
  9. private String joiningDate;
  10. private String mailingAddress;
  11. static int count=0;
  12.  
  13. Employee()
  14. {
  15. firstName=" " ;
  16. lastName=" " ;
  17. jobTitle=" " ;
  18. employeeID=" " ;
  19. monthlyIncome=0.0;
  20. joiningDate=" " ;
  21. mailingAddress=" " ;
  22. count++;
  23. }
  24. Employee(String f,String l,String j,String e,double m,String join,String mail)
  25. {
  26. firstName=f ;
  27. lastName=l ;
  28. jobTitle=j ;
  29. employeeID=e ;
  30. monthlyIncome=m;
  31. joiningDate=join ;
  32. mailingAddress=mail ;
  33. count++;
  34. }
  35. Employee(Employee emp)
  36. {
  37. firstName=emp.firstName;
  38. lastName=emp.lastName;
  39. jobTitle=emp.jobTitle ;
  40. employeeID=emp.employeeID ;
  41. monthlyIncome=emp.monthlyIncome;
  42. joiningDate=emp.joiningDate ;
  43. mailingAddress=emp.mailingAddress ;
  44. count++;
  45. }
  46.  
  47. void setfirstName(String f)
  48. {
  49. firstName=f;
  50. }
  51. void setlastName(String l)
  52. {
  53. lastName=l;
  54. }
  55. void setjobTitle(String j)
  56. {
  57. jobTitle=j;
  58. }
  59. void setemployeeID(String e)
  60. {
  61. employeeID=e;
  62. }
  63. void setmonthlyIncome(double m)
  64. {
  65. monthlyIncome=m;
  66. }
  67. void setjoiningDate(String join)
  68. {
  69. joiningDate=join;
  70. }
  71. void setmailingAddress(String mail)
  72. {
  73. mailingAddress=mail;
  74. }
  75.  
  76. String getfirstName()
  77. {
  78. return firstName;
  79. }
  80. String getlastName()
  81. {
  82. return lastName;
  83. }
  84. String getjobTitle()
  85. {
  86. return jobTitle;
  87. }
  88. String getemployeeID()
  89. {
  90. return employeeID;
  91. }
  92. double getmonthlyIncome()
  93. {
  94. return monthlyIncome;
  95. }
  96. String getjoiningDate()
  97. {
  98. return joiningDate;
  99. }
  100. String getmailingAddress()
  101. {
  102. return mailingAddress;
  103. }
  104. //NEW EMPLOYEE
  105. void NewEmployee()
  106. {
  107. String f=JOptionPane.showInputDialog("Enter your First Name:");
  108. setfirstName(f);
  109. String l=JOptionPane.showInputDialog("Enter your Last Name:");
  110. setlastName(l);
  111. String j=JOptionPane.showInputDialog("Enter your Job Title:");
  112. setjobTitle(j);
  113. String e=JOptionPane.showInputDialog("Enter your Employee ID:");
  114. setemployeeID(e);
  115. double m=Double.parseDouble(JOptionPane.showInputDialog("Enter your Monthly Income:"));
  116. setmonthlyIncome(m);
  117. String join=JOptionPane.showInputDialog("Enter your Joining Date:");
  118. setjoiningDate(join);
  119. String mail=JOptionPane.showInputDialog("Enter your Mailing Address:");
  120. setmailingAddress(mail);
  121. }
  122. //JOB TITLE
  123. void JobTitle()
  124. {
  125. String n=JOptionPane.showInputDialog("Enter your New Job Title:");
  126. setjobTitle(n);
  127. }
  128. /*void JobTitle(Employee[] list)
  129. {
  130. String empID=JOptionPane.showInputDialog("Enter your Employee ID:");
  131. String n=JOptionPane.showInputDialog("Enter your New Job Title:");
  132. for(int i=0;i<list.length;i++){
  133. if(empID.equals(list[i].getjobTitle())){
  134. list[i].setjobTitle(n);
  135. System.out.println("Your Job Title has been changed to "+ list[i].getjobTitle());
  136. }
  137. else
  138. continue;
  139. }
  140. }*/
  141. }//FINAL BRACKET
Plz javaAddict help me out .... as helped me before ....
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 1,658
Reputation: javaAddict is a name known to all javaAddict is a name known to all javaAddict is a name known to all javaAddict is a name known to all javaAddict is a name known to all javaAddict is a name known to all 
Solved Threads: 223
Featured Poster
javaAddict's Avatar
javaAddict javaAddict is online now Online
Posting Virtuoso
 
0
  #4
34 Days Ago
Follow the instructions at the link.
Also at the options where the user enters employee number, loop through the array until you find the employee and call that employee's methods. You don't loop the array and call everybody's method, only the employee[i] that has the employee number that you entered
Check out my New Bike at my Public Profile at the "About Me" tab
Reply With Quote Quick reply to this message  
Join Date: Oct 2009
Posts: 5
Reputation: ahmedshayan is an unknown quantity at this point 
Solved Threads: 0
ahmedshayan ahmedshayan is offline Offline
Newbie Poster
 
0
  #5
34 Days Ago
javaAddict ! plz rectify me here .....
  1. empID=JOptionPane.showInputDialog("Enter your Employee ID:");
  2.  
  3. /*acc[i].JobTitle(empID,acc,n);
  4. break;*/
  5. for(int j=0;j<Employee.count;j++){
  6. if(empID.equals(acc[i].getjobTitle())){
  7. n=JOptionPane.showInputDialog("Enter your New Job Title:");
  8. acc[i].JobTitle(n);
  9. System.out.println(acc[i].getjobTitle());
  10. }
  11. }
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 1,658
Reputation: javaAddict is a name known to all javaAddict is a name known to all javaAddict is a name known to all javaAddict is a name known to all javaAddict is a name known to all javaAddict is a name known to all 
Solved Threads: 223
Featured Poster
javaAddict's Avatar
javaAddict javaAddict is online now Online
Posting Virtuoso
 
0
  #6
34 Days Ago
  1. if(empID.equals(acc[i].getjobTitle())) {
  2.  
  3. }
empId is the employee id, so Why do you compare it with the job title:
empID.equals(acc[i].getjobTitle()) Compare it with the empId of the employee in the array. Then set the job title
Check out my New Bike at my Public Profile at the "About Me" tab
Reply With Quote Quick reply to this message  
Join Date: Oct 2009
Posts: 5
Reputation: ahmedshayan is an unknown quantity at this point 
Solved Threads: 0
ahmedshayan ahmedshayan is offline Offline
Newbie Poster
 
0
  #7
34 Days Ago
Thanks javaAddict . Problem solved .
Reply With Quote Quick reply to this message  
Reply

Tags
code, java, method, newbie, problem

Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC