Class Person is already loaded in this activity. No need to add the class to your cod
OOPs
In today's technology-driven world, computer programming skills are in high demand. The object-oriented programming (OOP) approach is very much useful while designing and maintaining software programs. Object-oriented programming (OOP) is a basic programming paradigm that almost every developer has used at some stage in their career.
Constructor
The easiest way to think of a constructor in object-oriented programming (OOP) languages is:
Complete the java code given below:
Note:
Class Person is already loaded in this activity. No need to add the class to your code.
Test Result that should be seen.
Test | Result |
---|---|
HourlyEmployee h = new HourlyEmployee("Yule Josef Ato","Cebu City",23,"Accenture",40, 550.98); System.out.println(h); System.out.println("\nEarnings: "+h.earnings()); |
Name: Yule Josef Ato Address: Cebu City Age: 23 Company name: Accenture Hours worked: 40 Rate: 550.98 Earnings: 22039.2 |
HourlyEmployee h = new HourlyEmployee("Linc Josef Ato","Talisay City",28,"Alliance",41, 600.00); h.display(); System.out.println("\nEarnings: "+h.earnings()); |
Name : Linc Josef Ato Address : Talisay City Age : 28 Company Name: Alliance Earnings: 36900.0 |
HourlyEmployee h1 = new HourlyEmployee("Yule Josef Ato","Cebu City",23,"Accenture",40, 550.98); HourlyEmployee h2 = new HourlyEmployee("Linc Josef Ato","Talisay City",28,"Alliance",41, 600.00); System.out.println(h1.equals(h2)); |
false |
complete this code:
class Employee extends Person {
private String companyName;
public Employee(String name,String address,int age,String companyName) {
super(name,address,age);
this.companyName = companyName;
}
public Employee() {
}
public void setCompanyName(String cname){
companyName = cname;
}
public String getCompanyName(){
return companyName;
}
// Override the display method in the Person class
// define earnings as an abstract method with a return type of double
// override the toString() and equals() methods
}
class HourlyEmployee extends Employee
{
private int hoursWorked; //total number of hours worked
private double rate; // rate per hour
public HourlyEmployee(String name,String address,int age,String cName,int hoursWorked,double rate) {
}
public HourlyEmployee(String name,String address,int age,String cName) {
hoursWorked = 0;
rate = 0;
}
// provide the setters and getters of your data members
//earnings is computed by having the product of
//the total number of hours worked and the rate.
// but if the number of hours worked exceeds 40,
// the rate increases to 150% of the current rate.
// (ex. rate=200; 150% = 300)
// override the toString() and equals() methods
}
Step by step
Solved in 3 steps with 4 images