Question: I am having issues with compiling my code. especially in the ''//Display the results'' section in EmployeeTest.java. i keep getting the error ''The method getFirstName()

 I am having issues with compiling my code. especially in the

I am having issues with compiling my code. especially in the ''//Display the results'' section in EmployeeTest.java. i keep getting the error ''The method getFirstName() is undefined for the type Employee'', ''The method getMonthlySalary() is undefined for the type Employee".

i have displayed the answers i have below. please help identify the error so my code can compile..

Employee.java answer:

public class Employee { private String firstName; private String lastName; private double monthlySalary; public Employee(String firstName, String lastName, double monthlySalary) { this.firstName = firstName; this.lastName = lastName; // ensure the monthlySalary is a positive value if(monthlySalary

EmployeeTest.java answer

import java.util.Scanner;

public class EmployeeTest { public void main(String [] args ) { Scanner input = new Scanner(System.in); // Prompt for employee one's information and // create an Employee object System.out.print("Enter employee one's first name: "); String firstName = input.nextLine(); System.out.print("Enter employee one's last name: "); String lastName = input.nextLine(); System.out.print("Enter employee one's monthly salary: "); double monthlySalary = input.nextDouble(); Employee employeeOne = new Employee(firstName, lastName, monthlySalary); // Clear the Scanner's input buffer input.nextLine(); // Prompt for employee two's information and // create an employee object System.out.print("Enter employee two's first name: "); firstName = input.nextLine(); System.out.print("Enter employee two's lastName: "); lastName = input.nextLine(); System.out.print("Enter employee two's monthly salary: "); monthlySalary = input.nextDouble(); Employee employeeTwo = new Employee(firstName, lastName, monthlySalary); // Display the results System.out.println("Employee One"); System.out.println("Employee One's name: "+ employeeOne.getLastName() + ", " + employeeOne.getFirstName()); String oneSalary = String.format("%.2f", employeeOne.getMonthlySalary()); System.out.println("Employee One's yearly salary: $" + oneSalary); System.out.println("Employee Two's name: "+ employeeTwo.getLastName() + ", " + employeeTwo.getFirstName()); String twoSalary = String.format("%.2f", employeeTwo.getMonthlySalary()); System.out.println("Employee Two's yearly salary: $"+ twoSalary); // close scanner input.close(); } }

Purpose: To write an Object-Oriented application that creates a Java class with several instance variables, a constructor to initialize the instance variables, and several methods to access the instance variables' values. Also, write a test class that instantiates the first class and tests the class's constructor and methods. Details: Create a class called Employee containing the following: Three instance variables, o An instance variable of type string used to hold the employee's first name. o An instance variable of type string used to hold the employee's last name. o An instance variable of type double used to hold the employee's monthly salary. Provide a constructor with three parameters used to initializes each instance variable. The constructor should check the specified monthly salary to ensure that it is positive. If it not, set it to 0.0. Provide get methods that return the values of each instance variables. No set methods are needed. Do not include them in the Employee class. . Create a second class called EmployeeTest that contains the main method. The method should prompt for an employee's first name, last name, and monthly salary, and use the values to create an Employee object. The class should then prompt for the values a second time to create a second Employee object. Note: After asking for the first employee's monthly salary, call the Sanner.nextLine method to clear the Sanner's input buffer before asking for the second employee's first name. The EmployeeTest class should then display the following: Employee One's name: last_name, first_name Employee One's yearly salary: $ nn.nn Employee Two's name: last_name, first_name Employee Two's yearly salary: $ nn.nn

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!