hello friends i m larning core java.i want some write code of some program by in which i can use the concept of opertors,inhertance so plz me assignment so that i can do practic.

Implement the way employee records are handled in an organization. The organization consists of Managers, Clerks and Salesmen.

Managers receive bonus, clerks get paid for overtime and salesmen get commission depending on their sales.

Also write a method which will calculate the net salary of any type of employee. For eg. for managers net salary would be "salary + bonus", for clerks it would be "salary + overtime" etc.

hiiiiii this is my code to slove above problem.but i think this code is much big and complex.as i m new so plz give me feedback.how can i reduce it time and space complxcity

class Employee
{
 double salary;
 double netSaraly;
 String[][] name={{"Mr. ","Mrs. ","Ms. "},{"Ajay ","Shakti ","Shubham"}};

 
 void showname(int i,int j )
 { 
  System.out.print("Name :"+name[0][i] +name[1][j] ); 
  
  }


 void getSalary(double x)
  {
   salary=x;
   System.out.print("  Salary :"+salary);
   }


 void showNetSalary( )
 {
  System.out.println(" netsalary " + netSaraly);
  }
 }



class Managers extends Employee 
{
 double bonus;
 

 void getBonus( )
 {
  if(salary>10000)
  {
   bonus=salary*0.1;
   netSaraly=salary+bonus;
   System.out.print(" bonus " + bonus);
   }
  }
 }


class Clerks extends Employee
{
 double overTime;
 int hours;
 


 void GetOvetTime(int x)
 { 
  hours=x;
  overTime=100*hours;
  netSaraly=salary+overTime;
  System.out.print(" overTime " + overTime);
  }
 }


class Salesmen extends Employee
{
 double commission;
 double sale;
 

 void getCommission(double x)
 {
  sale=x;
  if(sale>10000)
  {
   commission=sale*.02;
   }
   netSaraly=salary+commission;
   System.out.print(" commission " + commission);
  } 
 }

class NetSalary
{
 public static void main(String[] ar)
 {
  Managers e1 = new Managers();
  Clerks c1 =new Clerks();
  Salesmen s1= new Salesmen();
  
  e1.showname(0,1);
  e1.getSalary(12000);
  e1.getBonus();
  e1.showNetSalary();

  c1.showname(0,0);
  c1.getSalary(3000);
  c1.GetOvetTime(10);
  c1.showNetSalary();

  s1.showname(2,2);
  s1.getSalary(5000);
  s1.getCommission(120000);
  s1.showNetSalary();
  }
 }

Since nothing spectacular is involved here, there is no question of time and space complexity. What we are facing here are bad design issues.

  • Make the member variables of a class as private and always make it a habit to write mutators and accessors for them (get and set methods).
  • Stay away from hardcoding values into the class. Let the driver class or the test class handle such things for you.
  • The employee class needs to be abstract since you can't as such create an instance of an employee or it rather doesn't make sense. The employee in your organization would be either a clerk, salesman or manager but never just an employee.
  • Providing constructors for the classes you write is a good practice.
  • Avoid printing in get or set methods. Print out the values of variables in the driver or main class.
  • The show net salary is also better off as an abstarct fucntion in the employee class which has to be compulsorily overridden.

There can be many other minor glitches, but the above ones leap to the eye.

Hii all please i want the answer for this Question for JAVA program:")

** How to write a java program to read the value of salary (double). if the salary is above 5000,calculate the bonus as 20% of salary.otherwise, calculate the bonus as 10% of salary ???

> > THANK YOU ..

@B.A.A, please start another thread for your topic. Your post is not related to this thread.

To answer your question, try viewing some tutorials on java so that you will learn how to write a java program on your own and then post your code here if you got stucked or have errors.

Hii all please i want the answer for this Question for JAVA program:")

** How to write a java program to read the value of salary (double). if the salary is above 5000,calculate the bonus as 20% of salary.otherwise, calculate the bonus as 10% of salary ???

> > THANK YOU ..

So write one. We are not a homework service.

Closing this zombie.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.