Question

In: Computer Science

1) Create a class called Employee that includes three instance variables — a first name (type...

1) 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.

2) Create an app named EmployeeLinkedList that stores a collection of Employee objects in a LinkedList<Employee>. Test the app by creating five Employee objects and adding the Employees to the LinkedList<Employee> , then re-access the LinkedList<Employee> to display each Employee object’s yearly salary. Then give each Employee a 10% raise and display each Employee’s yearly salary again.

Provide a working java code and also display the output. NEED IT ASAP

Solutions

Expert Solution

Code :

public class EmployeeLinkedList

{

Employee head; // head of list

/* Linked list Employee*/

class Employee

{

String fName;

String lName;

double data;

Employee next;

  

// Constructor

Employee(String fN, String lN, double d) {

fName = fN;   

lName = lN;

data = d;

next = null;

}

}

/* Inserts a new Node at front of the list. */

public void push(String new_fN, String new_lN, double new_data)

{

/* 1 & 2: Allocate the Node &

Put in the data*/

Employee new_node = new Employee(new_fN, new_lN, new_data);

/* 3. Make next of new Node as head */

new_node.next = head;

/* 4. Move the head to point to new Node */

head = new_node;

}

/* This function raises each salary by 10% */

public void salRaise()

{

Employee tnode = head;

while (tnode != null)

{

tnode.data *= 1.1 ;

tnode = tnode.next;

}

}

/* This function prints contents of linked list starting from

the given node */

public void printList()

{

Employee tnode = head;

while (tnode != null)

{

System.out.print(tnode.fName + " " + tnode.lName + " ");

System.out.printf("%.2f\n", tnode.data);

tnode = tnode.next;

}

}

/* Driver program to test above functions. */

public static void main(String[] args)

{

/* Start with the empty list */

EmployeeLinkedList llist = new EmployeeLinkedList();

// Insert at the linked list

llist.push("Chandler", "Bing", 100000);

llist.push("Joey", "Tribbiani",200000);

llist.push("Ross", "Geller",300000);

llist.push("Pheobe", "Buffay",400000);

llist.push("Rachel", "Green",500000);

System.out.println("\n\nCreated Linked list is: ");

llist.printList();

System.out.println("\n\nGiving everyone a raise of 10%");

llist.salRaise();

System.out.println("\n\nUpdated Linked list is: ");

llist.printList();

}

}

Output Screenshot:


Related Solutions

1) Create a class called Employee that includes three instance variables — a first name (type...
1) 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. 2)Create an app named EmployeeLinkedList that stores a collection of Employee objects in a LinkedList<Employee>. Test the app by creating five...
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....
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...
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...
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...
Create a Java class named Trivia that contains three instance variables, question of type String that...
Create a Java class named Trivia that contains three instance variables, question of type String that stores the question of the trivia, answer of type String that stores the answer to the question, and points of type integer that stores the points’ value between 1 and 3 based on the difficulty of the question. Also create the following methods: getQuestion( ) – it will return the question. getAnswer( ) – it will return the answer. getPoints( ) – it will...
Create a Java class named Trivia that contains three instance variables, question of type String that...
Create a Java class named Trivia that contains three instance variables, question of type String that stores the question of the trivia, answer of type String that stores the answer to the question, and points of type integer that stores the points’ value between 1 and 3 based on the difficulty of the question. Also create the following methods: getQuestion( ) – it will return the question. getAnswer( ) – it will return the answer. getPoints( ) – it will...
Exercise #1: Create an abstract class called GameTester. The GameTester class includes a name for the...
Exercise #1: Create an abstract class called GameTester. The GameTester class includes a name for the game tester and a boolean value representing the status (full-time, part-time). Include an abstract method to determine the salary, with full-time game testers getting a base salary of $3000 and part-time game testers getting $20 per hour. Create two subclasses called FullTimeGameTester, PartTimeGameTester. Create a console application that demonstrates how to create objects of both subclasses. Allow the user to choose game tester type...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT