Create a class called Employee whose objects are records for an employee. This c
ID: 3668222 • Letter: C
Question
Create a class called Employee whose objects are records for an employee. This class will be a derived class of the class Person shown below. An employee record has an employee's name (inherited from the class Person), an annual salary represented as a single value of type double, a year the employee started work as a single value of type int and a national insurance number, which is a value of type String. Your class should have a reasonable number of constructors and accessor methods, as well as an equals method. Write another class containing a main method to fully test your class definition.
Explanation / Answer
package com.dq.thematrix.main.java.javapns.content;
class Person {
String name;
public Person(String empName) {
name=empName; }
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
class Employee extends Person
{
double annual_salary;
int year;
String national_insurance_number;
Employee(String name,double sal,int years, String insurance)
{
super(name);
annual_salary=sal;
years=year;
national_insurance_number=insurance;
}
public double getAnnual_salary() {
return annual_salary;
}
public void setAnnual_salary(double annual_salary) {
this.annual_salary = annual_salary;
}
public int getYear() {
return year;
}
public void setYear(int year) {
this.year = year;
}
public String getNational_insurance_number() {
return national_insurance_number;
}
public void setNational_insurance_number(String national_insurance_number) {
this.national_insurance_number = national_insurance_number;
}
public static void main(String args[])
{
Employee e=new Employee("My Name",7864578.99,6,"875");
//Now call any method you want to! :)
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.