Question
Question 2: Create two simple classes; Employee and EmployeeData. The Employee class should have 4 instance variables; name, age, citizenship, and salary. The EmployeeData should
Question 2: Create two simple classes; Employee and EmployeeData. The Employee class should have 4 instance variables; name, age, citizenship, and salary.
The EmployeeData should create 2 instances of the class Employee and invokes the methods for each object to assign the values for each variable. [Micheal, 23, USA, 30000; Mohammed, 22, Oman, 310000]
Complete the code below for the assignment
import java.io.*;
public class Employee {
String name;
int age;
String citizenship;
double salary;
// This is the constructor of the class Employee
public Employee(String name) {
this.name = name;
}
// Assign the age of the Employee to the variable age.
public void empAge ( . )
{
}
/* Assign the citizenship to the variable citizenship.*/
public void empCitizenship()
{ ..;
}
/* Assign the salary to the variable salary.*/
public void empSalary(..)
{ ;
}
/* Print the Employee details */
public void printEmployee() {
System.out.println("Name:"+ name );
System.out.println("Age:" + age );
System.out.println("Citizenship:" + citizenship );
System.out.println("Salary:" + salary);
}
}
import java.io.*;
public class EmployeeTest {
public static void main(String args[]) {
/* Create two objects using constructor */
Employee empOne =
Employee empTwo = .
// Invoking methods for each object created
..
empOne.printEmployee();
..
..
empTwo.printEmployee();
}
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started