| | |
I created the same program before But this one doesnt work ?
![]() |
•
•
Join Date: Oct 2009
Posts: 5
Reputation:
Solved Threads: 0
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
and here is the BusinessConcern class which also the main class ...
Thanks in Advance .
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
java Syntax (Toggle Plain Text)
import javax.swing.JOptionPane; class Employee { private String firstName; private String lastName; private String jobTitle; private String employeeID; private double monthlyIncome; private String joiningDate; private String mailingAddress; static int count=0; Employee() { firstName=" " ; lastName=" " ; jobTitle=" " ; employeeID=" " ; monthlyIncome=0.0; joiningDate=" " ; mailingAddress=" " ; count++; } Employee(String f,String l,String j,String e,double m,String join,String mail) { firstName=f ; lastName=l ; jobTitle=j ; employeeID=e ; monthlyIncome=m; joiningDate=join ; mailingAddress=mail ; count++; } Employee(Employee emp) { firstName=emp.firstName; lastName=emp.lastName; jobTitle=emp.jobTitle ; employeeID=emp.employeeID ; monthlyIncome=emp.monthlyIncome; joiningDate=emp.joiningDate ; mailingAddress=emp.mailingAddress ; count++; } void setfirstName(String f) { firstName=f; } void setlastName(String l) { lastName=l; } void setjobTitle(String j) { jobTitle=j; } void setemployeeID(String e) { employeeID=e; } void setmonthlyIncome(double m) { monthlyIncome=m; } void setjoiningDate(String join) { joiningDate=join; } void setmailingAddress(String mail) { mailingAddress=mail; } String getfirstName() { return firstName; } String getlastName() { return lastName; } String getjobTitle() { return jobTitle; } String getemployeeID() { return employeeID; } double getmonthlyIncome() { return monthlyIncome; } String getjoiningDate() { return joiningDate; } String getmailingAddress() { return mailingAddress; } //NEW EMPLOYEE void NewEmployee() { String f=JOptionPane.showInputDialog("Enter your First Name:"); setfirstName(f); String l=JOptionPane.showInputDialog("Enter your Last Name:"); setlastName(l); String j=JOptionPane.showInputDialog("Enter your Job Title:"); setjobTitle(j); String e=JOptionPane.showInputDialog("Enter your Employee ID:"); setemployeeID(e); double m=Double.parseDouble(JOptionPane.showInputDialog("Enter your Monthly Income:")); setmonthlyIncome(m); String join=JOptionPane.showInputDialog("Enter your Joining Date:"); setjoiningDate(join); String mail=JOptionPane.showInputDialog("Enter your Mailing Address:"); setmailingAddress(mail); } //JOB TITLE void JobTitle(String empID,Employee[] list,String n) { String test; for(int i=0;i<list.length;i++){ test=list[i].getjobTitle(); if(empID.equals(test)){ System.out.println("found it !"); list[i].setjobTitle(n); System.out.println("Your Job Title has been changed to "+ list[i].getjobTitle()); } else continue; } } /*void JobTitle(Employee[] list) { String empID=JOptionPane.showInputDialog("Enter your Employee ID:"); String n=JOptionPane.showInputDialog("Enter your New Job Title:"); for(int i=0;i<list.length;i++){ if(empID.equals(list[i].getjobTitle())){ list[i].setjobTitle(n); System.out.println("Your Job Title has been changed to "+ list[i].getjobTitle()); } else continue; } }*/ }//FINAL BRACKET
and here is the BusinessConcern class which also the main class ...
java Syntax (Toggle Plain Text)
import java.util.Scanner; import javax.swing.JOptionPane; class BusinessConcern{ public static void main(String []args){ String empID,n; //Scanner enter=new Scanner(System.in); //System.out.print("How many account(s) do wish to create ? "); //int num=enter.nextInt(); int num=Integer.parseInt(JOptionPane.showInputDialog("How many account(s) do wish to create ? ")); Employee acc[]=new Employee[num]; for(int i=0;i<acc.length;i++){ acc[i]=new Employee(); int choice=0; System.out.println("What do you want to do ? "); System.out.println("New Employee (1)"); System.out.println("Change Job Title (2)"); System.out.println("Change Monthly Income (3)"); System.out.println("Change Mailing Address (4)"); System.out.println("Employee Details (5)"); System.out.println("Available Records (6)"); System.out.println("Exit (7)"); choice=Integer.parseInt(JOptionPane.showInputDialog("Enter your choice")); switch(choice){ case 1: acc[i].NewEmployee(); System.out.println(acc[i].getjobTitle()); break; case 2: empID=JOptionPane.showInputDialog("Enter your Employee ID:"); n=JOptionPane.showInputDialog("Enter your New Job Title:"); acc[i].JobTitle(empID,acc,n); break; case 7: System.exit(0); break; } } }//2ND LAST }//LAST BRACKET
0
#2 33 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
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
•
•
Join Date: Oct 2009
Posts: 5
Reputation:
Solved Threads: 0
0
#3 33 Days Ago
this is what i did
and what i comprehended ...
Plz javaAddict help me out .... as helped me before ....
java Syntax (Toggle Plain Text)
import java.util.Scanner; import javax.swing.JOptionPane; class BusinessConcern{ public static void main(String []args){ String empID,n; //Scanner enter=new Scanner(System.in); //System.out.print("How many account(s) do wish to create ? "); //int num=enter.nextInt(); int num=Integer.parseInt(JOptionPane.showInputDialog("How many account(s) do wish to create ? ")); Employee acc[]=new Employee[num]; for(int i=0;i<acc.length;i++){ acc[i]=new Employee(); int choice=0; System.out.println("What do you want to do ? "); System.out.println("New Employee (1)"); System.out.println("Change Job Title (2)"); System.out.println("Change Monthly Income (3)"); System.out.println("Change Mailing Address (4)"); System.out.println("Employee Details (5)"); System.out.println("Available Records (6)"); System.out.println("Exit (7)"); choice=Integer.parseInt(JOptionPane.showInputDialog("Enter your choice")); switch(choice){ case 1: acc[i].NewEmployee(); System.out.println(acc[i].getjobTitle()); break; case 2: empID=JOptionPane.showInputDialog("Enter your Employee ID:"); /*acc[i].JobTitle(empID,acc,n); break;*/ for(int j=0;j<acc.length;j++){ if(empID.equals(acc[i].getjobTitle())){ acc[i].JobTitle(); System.out.println(acc[i].getjobTitle()); } } break; case 7: System.exit(0); break; } } }//2ND LAST }//LAST BRACKET
and what i comprehended ...
java Syntax (Toggle Plain Text)
import javax.swing.JOptionPane; class Employee { private String firstName; private String lastName; private String jobTitle; private String employeeID; private double monthlyIncome; private String joiningDate; private String mailingAddress; static int count=0; Employee() { firstName=" " ; lastName=" " ; jobTitle=" " ; employeeID=" " ; monthlyIncome=0.0; joiningDate=" " ; mailingAddress=" " ; count++; } Employee(String f,String l,String j,String e,double m,String join,String mail) { firstName=f ; lastName=l ; jobTitle=j ; employeeID=e ; monthlyIncome=m; joiningDate=join ; mailingAddress=mail ; count++; } Employee(Employee emp) { firstName=emp.firstName; lastName=emp.lastName; jobTitle=emp.jobTitle ; employeeID=emp.employeeID ; monthlyIncome=emp.monthlyIncome; joiningDate=emp.joiningDate ; mailingAddress=emp.mailingAddress ; count++; } void setfirstName(String f) { firstName=f; } void setlastName(String l) { lastName=l; } void setjobTitle(String j) { jobTitle=j; } void setemployeeID(String e) { employeeID=e; } void setmonthlyIncome(double m) { monthlyIncome=m; } void setjoiningDate(String join) { joiningDate=join; } void setmailingAddress(String mail) { mailingAddress=mail; } String getfirstName() { return firstName; } String getlastName() { return lastName; } String getjobTitle() { return jobTitle; } String getemployeeID() { return employeeID; } double getmonthlyIncome() { return monthlyIncome; } String getjoiningDate() { return joiningDate; } String getmailingAddress() { return mailingAddress; } //NEW EMPLOYEE void NewEmployee() { String f=JOptionPane.showInputDialog("Enter your First Name:"); setfirstName(f); String l=JOptionPane.showInputDialog("Enter your Last Name:"); setlastName(l); String j=JOptionPane.showInputDialog("Enter your Job Title:"); setjobTitle(j); String e=JOptionPane.showInputDialog("Enter your Employee ID:"); setemployeeID(e); double m=Double.parseDouble(JOptionPane.showInputDialog("Enter your Monthly Income:")); setmonthlyIncome(m); String join=JOptionPane.showInputDialog("Enter your Joining Date:"); setjoiningDate(join); String mail=JOptionPane.showInputDialog("Enter your Mailing Address:"); setmailingAddress(mail); } //JOB TITLE void JobTitle() { String n=JOptionPane.showInputDialog("Enter your New Job Title:"); setjobTitle(n); } /*void JobTitle(Employee[] list) { String empID=JOptionPane.showInputDialog("Enter your Employee ID:"); String n=JOptionPane.showInputDialog("Enter your New Job Title:"); for(int i=0;i<list.length;i++){ if(empID.equals(list[i].getjobTitle())){ list[i].setjobTitle(n); System.out.println("Your Job Title has been changed to "+ list[i].getjobTitle()); } else continue; } }*/ }//FINAL BRACKET
0
#4 33 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
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
•
•
Join Date: Oct 2009
Posts: 5
Reputation:
Solved Threads: 0
0
#5 33 Days Ago
javaAddict ! plz rectify me here .....
Java Syntax (Toggle Plain Text)
empID=JOptionPane.showInputDialog("Enter your Employee ID:"); /*acc[i].JobTitle(empID,acc,n); break;*/ for(int j=0;j<Employee.count;j++){ if(empID.equals(acc[i].getjobTitle())){ n=JOptionPane.showInputDialog("Enter your New Job Title:"); acc[i].JobTitle(n); System.out.println(acc[i].getjobTitle()); } }
0
#6 33 Days Ago
Java Syntax (Toggle Plain Text)
if(empID.equals(acc[i].getjobTitle())) { }
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
![]() |
Similar Threads
- Program Won't Work With Vista (C#)
- LAST_INSERT_ID doesnt work with servlets, please help (JSP)
- Pascal code doesnt work and i work out why (Pascal and Delphi)
- Internet explorer pop up blocker doesnt work (Web Browsers)
- python mysql doesnt work?plz help (Python)
- student grades program doesnt work how it should (C++)
- first website doesnt work well? (HTML and CSS)
- Creative webcam doesnt work!!! HELP!!!!! (USB Devices and other Peripherals)
- errors make me close program (C#)
- My phpbb forum doesnt work ? (PHP)
Other Threads in the Java Forum
- Previous Thread: convert degrees to decimal equivalent
- Next Thread: Event handling..need fast help....
| Thread Tools | Search this Thread |
.net 3d 6 access addressbook ajax android api apple applet array automation avg binary blogger blogging browser bug build c++ class code combo compiler component daniweb data database design development display dropdownlist eclipse educational error firefox firewall form foundation fractal function g2one game gdata google gui guitesting html image images infosec inheritance integer intellij java javafx javascript jetbrains julia lego linus linux loop mac method microsoft module mysql net netbeans newbie news php presentation problem program programming python recursive reuse rss security serial set software sort sorting source string sun swing threads tree variablebinding vb.net virus web windows wpf xml







