0% found this document useful (0 votes)
87 views6 pages

Ass Java

This document defines an Employee abstract class with subclasses for SalariedEmployee and HourlyEmployee. It includes methods to set employee values by input, get employee values, compute taxes on salary, and compute hourly payment. The main method creates instances of each subclass, calls their setValues and getValues methods to input and output employee details, and calculates salaries and taxes.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
0% found this document useful (0 votes)
87 views6 pages

Ass Java

This document defines an Employee abstract class with subclasses for SalariedEmployee and HourlyEmployee. It includes methods to set employee values by input, get employee values, compute taxes on salary, and compute hourly payment. The main method creates instances of each subclass, calls their setValues and getValues methods to input and output employee details, and calculates salaries and taxes.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 6

Question Number #5

package javpack;

import java.util.Scanner;

public abstract class Employee {


Scanner sc = new Scanner(System.in);

static String employeeID,firstname,lastname;


static int salary;

public void computeTax(int salary){

double tax = salary*0.07;


System.out.println("Tax on Salary "+salary+" ETB is "+tax+" ETB");
System.out.println();
System.out.println("Total Salary plus Tax is "+(salary-tax)+" ETB");

class SalariedEmployee extends Employee{

public void setValues(){

System.out.println("Enter Salaried Employee Information");


System.out.println();
System.out.print("Enter Employee Id : ");
employeeID = sc.next();

System.out.print("Enter Employee FirstName : ");


firstname = sc.next();

System.out.print("Enter Employee LastName : ");


lastname = sc.next();

System.out.print("Enter Employee Salary : ");


Employee.salary = sc.nextInt();

}
public void getValues(){

System.out.println("Salaried Employee Information");


System.out.println();
System.out.println("Employee Id : "+employeeID);
System.out.println("Employee FirstName : "+firstname);
System.out.println("Employee LastName : "+lastname);
System.out.println("Employee Salary : "+Employee.salary);
computeTax(Employee.salary);

}
}
class HourlyEmployee extends Employee{
int hours;
public void setValues(){

System.out.println("Enter HourlySalaried Employee Information");


System.out.println();
System.out.print("Enter Employee Id : ");
employeeID = sc.next();

System.out.print("Enter Employee FirstName : ");


firstname = sc.next();

System.out.print("Enter Employee LastName : ");


lastname = sc.next();

System.out.print("Enter Employee Salary : ");


Employee.salary = sc.nextInt();

System.out.print("Enter Employee WorkingHours : ");


hours = sc.nextInt();

}
public void getValues(){

System.out.println("HourlySalaried Employee Information");


System.out.println();
System.out.println("Hourly Salaried Employee Information");
System.out.println("Employee Id : "+employeeID);
System.out.println("Employee FirstName : "+firstname);
System.out.println("Employee LastName : "+lastname);
System.out.println("Employee Salary : "+lastname);
computeSalary();
computeTax(Employee.salary);

}
public void computeSalary(){

int hrsalary = hours*Employee.salary;


System.out.println("Employee Hourly Payment : "+hrsalary);
}
public static void main(String args[]){

SalariedEmployee se = new SalariedEmployee();


se.setValues();
System.out.println();
System.out.println();
se.getValues();

System.out.println();

HourlyEmployee he = new HourlyEmployee();


he.setValues();
System.out.println();
System.out.println();
he.getValues();
}
}

Question Number #7

package javpack;

import java.util.Scanner;

public abstract class Employee {


Scanner sc = new Scanner(System.in);
static String employeeID,firstname,lastname;
static int salary;
public void computeTax(int salary){
double tax = salary*0.07;
System.out.println("Tax on Salary "+salary+" ETB is "+tax+" ETB");
}
}
class SalariedEmployee extends Employee{
public void setValues(){
System.out.print("Enter Employee Id : ");
employeeID = sc.next();
System.out.print("Enter Employee FirstName : ");
firstname = sc.next();
System.out.print("Enter Employee LastName : ");
lastname = sc.next();
System.out.print("Enter Employee Salary : ");
Employee.salary = sc.nextInt();
}
public void getValues(){
System.out.println("Employee Id : "+employeeID);
System.out.println("Employee FirstName : "+firstname);
System.out.println("Employee LastName : "+lastname);
System.out.println("Employee Salary : "+Employee.salary);
computeTax(Employee.salary);
}
}
class HourlyEmployee extends Employee{
int hours;
public void setValues(){
System.out.print("Enter Employee Id : ");
employeeID = sc.next();
System.out.print("Enter Employee FirstName : ");
firstname = sc.next();
System.out.print("Enter Employee LastName : ");
lastname = sc.next();
System.out.print("Enter Employee Salary : ");
Employee.salary = sc.nextInt();
System.out.print("Enter Employee WorkingHours : ");
hours = sc.nextInt();
}
public void getValues(){
System.out.println("Employee Id : "+employeeID);
System.out.println("Employee FirstName : "+firstname);
System.out.println("Employee LastName : "+lastname);
System.out.println("Employee Salary : "+lastname);
computeSalary();
computeTax(Employee.salary);
}
public void computeSalary(){
int hrsalary = hours*Employee.salary;
System.out.println("Employee Hourly Payment : "+hrsalary);
}
public static void main(String args[]){
SalariedEmployee se = new SalariedEmployee();
se.setValues();
System.out.println();
System.out.println();
se.getValues();
System.out.println();
HourlyEmployee he = new HourlyEmployee();
he.setValues();
System.out.println();
System.out.println();
he.getValues();
}
}

You might also like