Question

In: Computer Science

Create a class called employee which has the following instance variables: Employee ID number Salary Years...

Create a class called employee which has the following instance variables:

Employee ID number

Salary

Years at the company

Your class should have the following methods:

New employee which reads in an employee’s ID number, salary and years of service

Anniversary which will up the years of service by 1

You got a raise which will read in how much the raise was (a percent) and then calculate the new salary

You get a bonus which gives a yearly bonus based on years of service so an employee gets a 5% bonus if they’ve been there 0-10 years and a 10% bonus if they’ve been there for over 10 years

You should also write main which should allow have an instance of your employee class, call the method that reads in the info and then allow the user to select between the anniversary, you got a raise and you got a bonus method and do the appropriate thing based on their selection. You may wish to loop this last part.

Solutions

Expert Solution

Code:

import java.util.*;

class Employee{
    String employeeId;
    double salary;
    int years;
    public static Scanner sc = new Scanner(System.in);
    public void newEmployee(){
        //taking user input
        System.out.print("Enter employee ID : ");
        this.employeeId = sc.nextLine();
        System.out.print("Enter salary : ");
        this.salary = sc.nextDouble();
        System.out.print("Enter years : ");
        this.years = sc.nextInt();
    }

    public void anniversary(){
        this.years++;//updating years worked
    }

    public void raise(double percentage){
        //calculating new salary based on percentage raise
        this.salary = this.salary + this.salary*percentage/100.0;
    }

    public void bonus(){
        //calculating and printing bonus based on the years worked
        double bonus;
        if(this.years <= 10){
            bonus = 0.05 * this.salary;
        }
        else{
          bonus = 0.10 * this.salary;
        }
        System.out.println("Bonus is "+ bonus);
    }

    public static void main(String args[]){
        Employee e = new Employee();
        e.newEmployee();
        int n = 1;//loop control variable
        while(n!=0){
          System.out.print("Enter 1 for raise and 2 for anniversary,3 to see bonus, 0 to quit : ");
          n = sc.nextInt();
          if(n == 1){
            System.out.print("Enter raise percentage : ");
            double percentage = sc.nextDouble();
            e.raise(percentage);
          }
          else if(n == 2){
            e.anniversary();
          }
          else if(n == 3){
              e.bonus();
          }
          else if(n != 0){
            System.out.println("Wrong input choice");
          }

          System.out.println("Current details : "+e.employeeId+ " " + e.salary+" " +e.years);
        }
    }
}



output:

Code screenshot:


Related Solutions

in Java, Create a class called EMPLOYEE that includes three instance variables – a first name...
in Java, Create a class called EMPLOYEE that includes three instance variables – a first name (type String), a last name (type String) and a monthly salary (double). Provide a constructor that initializes the three instance variables. Provide a set and a get method for each instance variable. If the monthly salary is not positive, do not set its value. Write a test app names EmployeeTest that demonstrates class EMLOYEE’s capabilities. Create two EMPLOYEE objects and display each object’s yearly...
with PHP Create a class called Employee that includes three instance variables—a first name (type String),...
with PHP Create a class called Employee that includes three instance variables—a first name (type String), a last name (type String) and a monthly salary int). Provide a constructor that initializes the three instance data member. Provide a set and a get method for each instance variable. If the monthly salary is not positive, do not set its 0. Write a test app named EmployeeTest that demonstrates class Employee’s capabilities. Create two Employee objects and display each object’s yearly salary....
Create a class called “Cycle” which has two instance integer variables as properties, “numberOfWheels” and “weight.”
Programming Problem 2 - Cycle[A] Create a class called “Cycle” which has two instance integer variables as properties, “numberOfWheels” and “weight.” Create a constructor with two parameters, using the same variable names in the parameter list. Assign each variable to numberOfWheels” and “weight” respectively. Write a separate application to test the class and display its properties. Note: Do not change the names of the instance variables or the variables listed in the constructor’s parameter list.[B] Edit your class Cycle by...
Create a C# Application. Create a class object called “Employee” which includes the following private variables:...
Create a C# Application. Create a class object called “Employee” which includes the following private variables: firstN lastN idNum wage: holds how much the person makes per hour weekHrsWkd: holds how many total hours the person worked each week regHrsAmt: initialize to a fixed amount of 40 using constructor. regPay otPay After going over the regular hours, the employee gets 1.5x the wage for each additional hour worked. Methods: constructor properties CalcPay(): Calculate the regular pay and overtime pay. Create...
Code in Java Write a Student class which has two instance variables, ID and name. This...
Code in Java Write a Student class which has two instance variables, ID and name. This class should have a two-parameter constructor that will set the value of ID and name variables. Write setters and getters for both instance variables. The setter for ID should check if the length of ID lies between 6 to 8 and setter for name should check that the length of name should lie between 0 to 20. If the value could not be set,...
JAVA Create an HourlyEmployee class that inherits from Employee and has two new instance variables: hours,...
JAVA Create an HourlyEmployee class that inherits from Employee and has two new instance variables: hours, which represents the hours worked, and wage, which represents the employee's pay per hour. (Both are doubles.) Create a constructor that takes the arguments first name, last name, social security number, hourly wage, and the number of hours worked. Also create accessors, mutators, an earnings method that returns the money earned by the employee this week, and a toString method that returns information about...
Create a class called Student. Include the following instance variables: name, address, phone, gpa Create all...
Create a class called Student. Include the following instance variables: name, address, phone, gpa Create all of the methods required for a standard user defined class: constructors, accessors, mutators, toString, equals Create the client for testing the Student class Create another class called CourseSection Include instance variables for: course name, days and times course meets (String), description of course, student a, student b, student c (all of type Student) Create all of the methods required for a standard user defined...
Create a UEmployee class that contains member variables for the university employee name and salary. The...
Create a UEmployee class that contains member variables for the university employee name and salary. The UEmployee class should contain member methods for returning the employee name and salary. Create Faculty and Staff classes that inherit the UEmployee class. The Faculty class should include members for storing and returning the department name. The Staff class should include members for storing and returning the job title. Write a runner program that creates one instance of each class and prints all of...
1)  Create a UEmployee class that contains member variables for the university employee name and salary. The...
1)  Create a UEmployee class that contains member variables for the university employee name and salary. The UEmployee class should contain member methods for returning the employee name and salary. Create Faculty and Staff classes that inherit the UEmployee class. The Faculty class should include members for storing and returning the department name. The Staff class should include members for storing and returning the job title. Write a runner program that creates one instance of each class and prints all of...
Create a class called Vehicle that includes four instance variables:      name, type,     tank size and...
Create a class called Vehicle that includes four instance variables:      name, type,     tank size and average petrol consumption. Provide 2 constructors, the first takes name and type as parameter, the second takes four parameters for the four instance variables. (2 pt) Provide also a method called distancePerTank that calculate the average distance that a vehicle can travel if the tank is full (multiplies the tank size by the average petrol consumption), then returns the value. (2 pt) Provide a...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT