Question

In: Computer Science

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 salary. Then give each employee a 10% raise and display each employee’s yearly salary again.

Solutions

Expert Solution


class Employee{
        private String firstName;
        private String lastName;
        private double salary;
        //constructor to initialize the data
        public Employee(String aFirstName, String aLastName, double aSalary) {
                super();
                firstName = aFirstName;
                lastName = aLastName;
                salary = aSalary;
        }
        public String getFirstName() {
                return firstName;
        }
        public String getLastName() {
                return lastName;
        }
        public double getSalary() {
                return salary;
        }
        public void setFirstName(String aFirstName) {
                firstName = aFirstName;
        }
        public void setLastName(String aLastName) {
                lastName = aLastName;
        }
        public void setSalary(double aSalary) {
                if(aSalary>=0)
                        salary = aSalary;
        }
        @Override
        public String toString() {
                return "Employee [firstName=" + firstName + ", lastName=" + lastName + ", salary=" + salary + "]";
        }
        
}

public class TestEmployee {
        public static void main(String[] args) {
                //creating emp object
                Employee e1 = new Employee("Uday", "Kumar", 10000);
                System.out.println("Before salary hike");
                System.out.println(e1);
                // adding 10% hike to the salary
                e1.setSalary(e1.getSalary() + e1.getSalary() * 0.1);
                System.out.println("After salary hike");
                System.out.println(e1);
                
                
                Employee e2 = new Employee("Keerthi", "Kumar", 10000);
                System.out.println("Before salary hike");
                System.out.println(e2);
                // adding 10% hike to the salary
                e2.setSalary(e2.getSalary() + e2.getSalary() * 0.1);
                System.out.println("After salary hike");
                System.out.println(e2);
                
                
                
        }
}


Related Solutions

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 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...
IN JAVA PLEASE Create a class called Child with an instance data values: name and age....
IN JAVA PLEASE Create a class called Child with an instance data values: name and age. a. Define a constructor to accept and initialize instance data b. include setter and getter methods for instance data c. include a toString method that returns a one line description of the child
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...
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...
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...
(java) Write a class called CoinFlip. The class should have two instance variables: an int named...
(java) Write a class called CoinFlip. The class should have two instance variables: an int named coin and an object of the class Random called r. Coin will have a value of 0 or 1 (corresponding to heads or tails respectively). The constructor should take a single parameter, an int that indicates whether the coin is currently heads (0) or tails (1). There is no need to error check the input. The constructor should initialize the coin instance variable to...
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,...
In java Implement the class Book. It has the following instance variables: name, subject, year, maximumLoanPeriod,...
In java Implement the class Book. It has the following instance variables: name, subject, year, maximumLoanPeriod, and loanPeoriod. The following methods should be included: • Constructor(s), Accessors and Mutators as needed. • public double computeFine() => calculates the fine due on this item The fine is calculated as follows: • If the loanPeriod <= maximumLoanPeriod, there is no fine on the book. • If loanPeriod > maximumLoanPeriod o If the subject of the book is "CS" the fine is 10.00...
Using C# Create a class called Artist that contains 4 pieces of information as instance variables:...
Using C# Create a class called Artist that contains 4 pieces of information as instance variables: name (datatype string), specialization – i.e., music, pottery, literature, paintings (datatype string), number of art items (datatype int), country of birth (datatype string). Create a constructor that initializes the 4 instance variables. The Artist class must contain a property for each instance variable with get and set accessors. The property for number should verify that the Artist contributions is greater than zero. If a...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT