Answer to Question #298934 in Java | JSP | JSF for abhirami

Question #298934

Compose an Employee class with the attributes personalia, employeeNo, yearofAppointment, monthSalary, and taxPercent. In addition to get methods for all the attributes, the following operations should be available :

Find the employee’s monthly tax.

Find the gross annual salary

Find tax savings per year. To our employees June is tax free, and in December there’s only half the usual tax.

Find name (in the format last name, first name.)

Find age

Find number of years employed at the company.

Find out if the person has been employed for more than a given number of years

Set methods to change attributes that it makes sense to change.

Find out in which cases an instance of the Employee class has to collaborate with its personalia object in order to complete these tasks. Draw sequence diagrams for these operations.Write a simple program that puts data into an instance of the Employee class and calls all the methods you’ve created. Check that the results are correct


1
Expert's answer
2022-02-19T16:57:07-0500
import java.util.Scanner;


class Person {
	private String lastName;
	private String firstName;
	private int age;


	public Person(String lastName, String firstName, int age) {
		this.lastName = lastName;
		this.firstName = firstName;
		this.age = age;
	}


	/**
	 * @return the lastName
	 */
	public String getLastName() {
		return lastName;
	}


	/**
	 * @param lastName the lastName to set
	 */
	public void setLastName(String lastName) {
		this.lastName = lastName;
	}


	/**
	 * @return the firstName
	 */
	public String getFirstName() {
		return firstName;
	}


	/**
	 * @param firstName the firstName to set
	 */
	public void setFirstName(String firstName) {
		this.firstName = firstName;
	}


	/**
	 * @return the age
	 */
	public int getAge() {
		return age;
	}


	/**
	 * @param age the age to set
	 */
	public void setAge(int age) {
		this.age = age;
	}


}


class Employee {


	private Person personalia;
	private int employeeNo;
	private int yearOfAppointment;
	private double monthlySalary;
	private double taxPercent;


	public Employee() {
	}


	public Employee(Person personalia, int employeeNo, int yearOfAppointment, double monthlySalary, double taxPercent) {
		this.personalia = personalia;
		this.employeeNo = employeeNo;
		this.yearOfAppointment = yearOfAppointment;
		this.monthlySalary = monthlySalary;
		this.taxPercent = taxPercent;
	}


	/**
	 * Find the employee’s monthly tax.
	 */
	public double monthlyTax() {
		return monthlySalary * taxPercent / 100.0;
	}


	public double grossSalary() {
		return monthlySalary * 12;
	}


	public double taxSavingsPerYear() {
		return monthlyTax() * 10 + monthlyTax() / 2;
	}


	public String getName() {
		return personalia.getLastName() + " " + personalia.getFirstName();
	}


	public int getAge() {
		return personalia.getAge();
	}


	public int getYearsAtCompany() {
		return 2022 - yearOfAppointment;
	}


	public boolean isWorksLongerThan(int years) {
		return getYearsAtCompany() > years;
	}


	public Person getPersonalia() {
		return personalia;
	}


	public void setPersonalia(Person personalia) {
		this.personalia = personalia;
	}


	public int getEmployeeNo() {
		return employeeNo;
	}


	public void setEmployeeNo(int employeeNo) {
		this.employeeNo = employeeNo;
	}


	public int getYearOfAppointment() {
		return yearOfAppointment;
	}


	public void setYearOfAppointment(int yearOfAppointment) {
		this.yearOfAppointment = yearOfAppointment;
	}


	public double getMonthlySalary() {
		return monthlySalary;
	}


	public void setMonthlySalary(double monthlySalary) {
		this.monthlySalary = monthlySalary;
	}


	public double getTaxPercent() {
		return taxPercent;
	}


	public void setTaxPercent(double taxPercent) {
		this.taxPercent = taxPercent;
	}
}


class App {


	public static void main(String[] args) {
		Scanner keyBoard = new Scanner(System.in);
		System.out.print("Ente the last name: ");
		String lastName = keyBoard.nextLine();
		System.out.print("Ente the first name: ");
		String firstName = keyBoard.nextLine();
		System.out.print("Ente the age: ");
		int age = keyBoard.nextInt();
		System.out.print("Ente employee No: ");
		int employeeNo = keyBoard.nextInt();
		System.out.print("Ente the year of appointment: ");
		int yearOfAppointment = keyBoard.nextInt();
		System.out.print("Ente the monthly salary: ");
		double monthlySalary = keyBoard.nextDouble();
		System.out.print("Ente the tax percent: ");
		double taxPercent = keyBoard.nextDouble();


		Employee employee = new Employee(new Person(lastName, firstName, age), employeeNo, yearOfAppointment,
				monthlySalary, taxPercent);
		System.out.println("The employee's monthly tax: " + employee.monthlyTax());
		System.out.println("The gross annual salary: " + employee.grossSalary());
		System.out.println("Tax savings per year: " + employee.taxSavingsPerYear());
		System.out.println("The name (in the format last name, first name.): " + employee.getName());
		System.out.println("Find age: " + employee.getAge());
		System.out.println("The number of years employed at the company: " + employee.getYearsAtCompany());
		if (employee.getYearsAtCompany() > employee.getYearOfAppointment()) {
			System.out.println("The person has been employed for more than a given number of year ");
		}
		keyBoard.close();


	}


}









Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS