Question

In: Computer Science

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 the data for each object.

As always, comment the code! And please do it in Java.

Solutions

Expert Solution

Program:

import java.util.*;

class UEmployee
{
//delaration of name and salary
String empName;
double salary;
//constructor of UEmployee
UEmployee(String empName,double salary)
{
this.empName=empName;
this.salary=salary;
}
//function to return the employee name
String getName()
{
return empName;
}

//function to return the salary
double getSalary()
{
return salary;
}
}


class Faculty extends UEmployee
{
String deptName;
//constructor of the Faculty
Faculty(String nm,double sal,String dnm)
{
//passing the name and salary to superclass constructor
super(nm,sal);
deptName=dnm;
}

//function to return department name
String getDeptName()
{
return deptName;
}
}

class Staff extends UEmployee
{
String jobTitle;

//constructor of Staff class
Staff(String nm,double sal,String title)
{
//passing the name and salary to superclass constructor
super(nm,sal);
jobTitle=title;
}

//function to return job title
String getJobTitle()
{
return jobTitle;
}
}


//test or driver class
class Test
{
public static void main(String args[])
{

//accepting the required values from user using Scanner class
String nameF,nameS,dname,title;
double salF,salS;
Scanner sc=new Scanner(System.in);
System.out.print("\nEnter the faculty name: ");
nameF=sc.nextLine();
System.out.print("Enter the salary: ");
salF=sc.nextDouble();
System.out.print("Enter the department name: ");
dname=sc.next();

sc.nextLine();
System.out.print("\nEnter the staff name: ");
nameS=sc.nextLine();
System.out.print("Enter the salary: ");
salS=sc.nextDouble();
System.out.print("Enter the Job title: ");
title=sc.next();


//Instantiation of Faculty class
Faculty fac=new Faculty(nameF,salF,dname);
System.out.println("\n\nDetails of Faculty:");
System.out.println("----------------------------------");
//calling all the methods of Faculty
System.out.println("Name: "+fac.getName());
System.out.println("Salary: $"+fac.getSalary());
System.out.println("Departname: "+fac.getDeptName());


//Instantiation of staff class
Staff st=new Staff(nameS, salS,title);
System.out.println("\n\nDetails of Staff:");
System.out.println("----------------------------------");
//calling all the methods of Staff
System.out.println("Name: "+st.getName());
System.out.println("Salary: $"+st.getSalary());
System.out.println("Job Title: "+st.getJobTitle());
System.out.println("\n");

}
}

Output:


Related Solutions

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...
directions: use c++ Create a  ContactInfo class that contains the following member variables: name age phoneNumber The...
directions: use c++ Create a  ContactInfo class that contains the following member variables: name age phoneNumber The ContactInfo class should have a default constructor that sets name = "", phoneNumber = "", and age = 0. The ContactInfo class should have a constructor that accepts the name and phone number as parameters and sets name = <value of parameter name>, aAge = 0, and phoneNumber = <value of parameter phone number>. The ContactInfo class should have accessor and mutator functions for...
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...
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...
First lab: Create a Fraction class Create member variables to store numerator denominator no additional member...
First lab: Create a Fraction class Create member variables to store numerator denominator no additional member variable are allowed Create accessor and mutator functions to set/return numerator denominator Create a function to set a fraction Create a function to return a fraction as a string ( common name ToString(), toString())  in the following format: 2 3/4 use to_string() function from string class to convert a number to a string; example return to_string(35)+ to_string (75) ; returns 3575 as a string Create...
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....
THIS IS JAVA PROGRAMMING 1. Create a class named Name that contains the following: • A...
THIS IS JAVA PROGRAMMING 1. Create a class named Name that contains the following: • A private String to represent the first name. • A private String to represent the last name. • A public constructor that accepts two values and assigns them to the above properties. • Public methods named getProperty (e.g. getFirstName) to return the value of the property. • Public methods named setProperty ( e.g. setFirstName)to assign values to each property by using a single argument passed...
# List the two private member variables (including name and functionality) in the node class. #Write...
# List the two private member variables (including name and functionality) in the node class. #Write a general pattern for a loop statement that traverses all the nodes of a linked list
Write a program that reads in the name and salary of an employee. Here the salary...
Write a program that reads in the name and salary of an employee. Here the salary will denote an hourly wage, such as $9.25. Then, ask how many hours the employee worked in the past week. Be sure to accept fractional hours. Compute the pay. Any overtime work (over 40 hours per week) is paid at 150 percent of the regular wage.4 pts Your code with comments A screenshot of the execution Test Cases: Enter name: Jorge Enter wage: 9.25...
Java Coding Part A Create a class Employee. Employees have a name.   Also give Employee a...
Java Coding Part A Create a class Employee. Employees have a name.   Also give Employee a method paycheck() which returns a double. For basic employees, paycheck is always 0 (they just get health insurance). Give the class a parameterized constructor that takes the name; Add a method reportDeposit. This method prints a report for the employee with the original amount of the paycheck, the amount taken out for taxes (we will do a flat 17%), and the final amount (for...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT