please I want 3 or 2 calsses with full codes to represent Employees in a small c
ID: 3771512 • Letter: P
Question
please I want 3 or 2 calsses with full codes to represent Employees in a small company according to the following requirements:
1- An employee has three attributes: name , salary and jobTitle
2- Add one constructor without parameters. In initialization of objects, Name is set to the value “NEW” and salary value is unspecified but it has to be an arbitrary number between 100 and 20000.
3- Add the following methods to the class:
getSalary- Returns employee’s salary.
getName- Returns employee’s name.
getJobTitle- Returns employee’s job title.
setName- Sets the employee’s name to a given value. Precondition: the number of characters in the given name is not less than 3 characters.
setSalary - Sets the employee’s salary to a given value. Precondition: the given salary value should be greater than 100.
4- All employees in this company have the same permanent job title: “Accountant” and it can’t be changed.
Explanation / Answer
program:
import java.io.*;
import java.util.Scanner;
class Employee
{
private String name;
private double salary;
protected String jobTitle;
Employee()
{
name="new";
salary=1000;
}
void setSalary(double sal)
{
salary=sal;
}
void setName(String nam)
{
name=nam;
}
double getSalary()
{
return salary;
}
String getName()
{
return name;
}
String getJobTitle()
{
return jobTitle;
}
}
class Accountant extends Employee
{
Accountant(){
super();
jobTitle="Accountant";
}
}
public class EmployeeData {
public static void main(String[] args)
{
int num;
String name;
double salary;
Employee[] a=new Accountant[2];
Employee a1=new Accountant();
Employee a2=new Accountant();
a[0]=a1;
a[1]=a2;
System.out.println("enter employees details");
Scanner scan=new Scanner(System.in);
for(int i=0;i<2;i++)
{
System.out.println("enter employee name: ");
name=scan.next();
while(name.length()<3)
{
System.out.println("name is not less than 3 characters please enter the name");
name=scan.next();
}
a[i].setName(name);
System.out.println("enter employee salary: ");
salary=scan.nextDouble();
while(salary<100||salary>20000)
{
System.out.println("salary is not less than 100 and greater than 20000 please enter the salary");
salary=scan.nextDouble();
}
a[i].setSalary(salary);
}
for(int i=0;i<2;i++)
{
System.out.println("Employee Name: "+a[i].getName());
System.out.println("Employee Salary: "+a[i].getSalary());
System.out.println("Employee Job Title: "+a[i].getJobTitle());
}
}
}
output:
enter employees details
enter employee name:
du
name is not less than 3 characters please enter the name
durgarao
enter employee salary:
20
salary is not less than 100 and greater than 20000 please enter the salary
2000
enter employee name:
nagendra
enter employee salary:
30000
salary is not less than 100 and greater than 20000 please enter the salary
3000
Employee Name: durgarao
Employee Salary: 2000.0
Employee Job Title: Accountant
Employee Name: nagendra
Employee Salary: 3000.0
Employee Job Title: Accountant
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.