Computer Science, asked by Hritik3125, 9 months ago

Write a program by creating an 'Employee' class having the following functions and print the final salary. 1 - 'getInfo()' which takes the salary, number of hours of work per day of employee as parameters 2 - 'AddSal()' which adds $10 to the salary of the employee if it is less than $500. 3 - 'AddWork()' which adds $5 to the salary of the employee if the number of hours of work per day is more than 6 hours.

Answers

Answered by ramabisa
24

Answer:

Explanation:

This is the JAVA program of your question:

import java.util.Scanner;

class Employee

{

getInfo()

{

Scanner in = new Scanner(System.in);

System.out.println("Enter your salary");

double salary = in.nextDouble();

System.out.println("Enter the no.of working hours");

int hours = in.nextInt();

}

AddSal()

{

double sal;

if(sal < 500)

sal = sal + 10;

System.out.println("Salary: " + sal);

}

AddWork()

{

double sal; //local variable this will be limited to this AddWork function

int hours;

if(hours > 6)

sal =sal + 5;

System.out.println("Salary: " + sal);

}

public static void main()

{

Scanner in = new Scanner(System.in);

Employee obj = new Employee();

obj.getInfo();

obj.AddSal();

obj.AddWork();

}

}

}

Answered by baasithtaj321
3

Answer:

Explanation:

import java.util.*;

class EmployeeDetail {

private String name;

private float salary, hours;

public EmployeeDetail() {

 name = " ";

 salary = 0;

 hours = 0;

}

public void getInfo(String n, float sal, float hr) {

 name = n;

 salary = sal;

 hours = hr;

}

public float AddSal() {

 if(salary<500) {

  salary = salary + 10;

 }

 return salary;

}

public float AddWork() {

 if(hours > 6) {

  salary = salary + 5;

 }

 return salary;

}

}

class TestEmployee {

float salary;

public TestEmployee(float sal) {

 salary = sal;

}

public void printSal() {

 System.out.println("Salary : " + salary);

}

}

class Employee

{

public static void main (String[] args)

{

 EmployeeDetail emp = new EmployeeDetail();

 Scanner sc = new Scanner(System.in);

 System.out.println("Enter name");

 String name = sc.nextLine();

 System.out.println("Enter salary");

 float salary = sc.nextFloat();

 System.out.println("Enter no. of hours of work");

 float hours = sc.nextFloat();

 

 emp.getInfo(name, salary, hours);

 salary = emp.AddSal();

 salary = emp.AddWork();

 

 TestEmployee test = new TestEmployee(salary);

 test.printSal(); }

}

Similar questions