JAVA... THIS IS THE PARENT CLASS public class Person { String name; String compa
ID: 3710018 • Letter: J
Question
JAVA... THIS IS THE PARENT CLASS
public class Person {
String name;
String company;
int id;
int hours;
double rate;
Person(String n, String c, int i, int h, double r)
{
name=n;
company=c;
id=i;
hours=h;
rate=r;
}
public void showInfo()
{
System.out.println("Name "+name);
System.out.println("Company "+company);
System.out.println("ID "+id);
System.out.println("Hours "+hours);
System.out.println("Rate "+rate);
}
public double calcSalary(int n)
{
return n*(hours*rate);
}}
JAVA VIA ECLIPSE....
Create a class called SalariedEmployee that inherits from Employee
It will have a double value for taxes
It will have a constructor as an argument constructor that will set all the values from super class and the taxes
It will have a showInfo method that will display all the values from the super class and this class
It will have a calcCost method that will take in the numberOfEmployees in the company and then return the cost from person minus the taxes per person that are deducted. That is what the total amount the company will pay out for the week for its employees.
In the main method create one object e1 and assign it at time of object creation any values you choose.
Output the values of each and also the cost (be sure to use the proper calls)
Create a second object e2 that will pass any values that you choose AFTER you type them in as questions interactively from the keyboard.
Explanation / Answer
Person.java
public class Person {
String name;
String company;
int id;
int hours;
double rate;
Person(String n, String c, int i, int h, double r)
{
name=n;
company=c;
id=i;
hours=h;
rate=r;
}
public void showInfo()
{
System.out.println("Name "+name);
System.out.println("Company "+company);
System.out.println("ID "+id);
System.out.println("Hours "+hours);
System.out.println("Rate "+rate);
}
public double calcSalary(int n)
{
return n*(hours*rate);
}}
SalariedEmployee.java
public class SalariedEmployee extends Person {
private double taxes;
public SalariedEmployee(String n, String c, int i, int h, double r, double taxes) {
super(n,c,i,h,r);
this.taxes = taxes;
}
public void showInfo() {
super.showInfo();
System.out.println("Taxes "+taxes);
}
public double calcCost(int n) {
double sal = calcSalary(n);
return sal - (sal * taxes)/100;
}
}
Test.java
import java.util.Scanner;
public class Test{
public static void main(String []args){
SalariedEmployee e1 = new SalariedEmployee("Suresh", "AA Company", 10,50,5.5, 10);
e1.showInfo();
System.out.println("Cost: "+e1.calcCost(5));
Scanner scan = new Scanner(System.in);
System.out.println("Enter the name: ");
String n = scan.next();
System.out.println("Enter the company name: ");
String c = scan.next();
System.out.println("Enter the ID: ");
int i = scan.nextInt();
System.out.println("Enter the hours: ");
int h = scan.nextInt();
System.out.println("Enter the pay rate: ");
double r = scan.nextDouble();
System.out.println("Enter the tax: ");
double t = scan.nextDouble();
SalariedEmployee e2 = new SalariedEmployee(n,c, i,h,r,t);
e2.showInfo();
System.out.println("Cost: "+e2.calcCost(5));
}
}
Output:
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.