Question: need help formatting output, the codes what is should do i just cant get it to print the way the question is asking, please dont

need help formatting output, the codes what is should do i just cant get it to print the way the question is asking, please dont change anything but what is necessary to format
/**
* Employee class representing an employee with a first name, last name, and monthly salary.
* This class includes methods for getting and setting these fields and
* for representing the employee as a formatted string.
*
* @author
* @version 03/11/2024
*/
public class Employee
{
// Step 3: Private instance variables
private String firstName;
private String lastName;
private double monthlySalary;
/**
* Constructor to initialize the Employee with first name, last name, and monthly salary.
* Ensures that the monthly salary is non-negative.
*
* @param firstName The first name of the employee.
* @param lastName The last name of the employee.
* @param monthlySalary The monthly salary of the employee.
*/
public Employee(String firstName, String lastName, double monthlySalary)
{
this.firstName = firstName;
this.lastName = lastName;
// Step 4: Check salary before initializing
this.monthlySalary = monthlySalary >=0? monthlySalary : 0;
}
// Step 5: Mutator (setter) methods
/**
* Sets the first name of the employee.
*
* @param firstName The first name to set.
*/
public void setFirstName(String firstName)
{
this.firstName = firstName;
}
/**
* Sets the last name of the employee.
*
* @param lastName The last name to set.
*/
public void setLastName(String lastName)
{
this.lastName = lastName;
}
/**
* Sets the monthly salary of the employee, ensuring it is non-negative.
*
* @param monthlySalary The monthly salary to set.
*/
public void setMonthlySalary(double monthlySalary)
{
if (monthlySalary >=0)
{
this.monthlySalary = monthlySalary;
}
}
// Step 6: Accessor (getter) methods
/**
* Gets the first name of the employee.
*
* @return The first name of the employee.
*/
public String getFirstName()
{
return this.firstName;
}
/**
* Gets the last name of the employee.
*
* @return The last name of the employee.
*/
public String getLastName()
{
return this.lastName;
}
/**
* Gets the monthly salary of the employee.
*
* @return The monthly salary of the employee.
*/
public double getMonthlySalary()
{
return this.monthlySalary;
}
// Step 7: toString method
/**
* Returns a formatted string representing the employee.
*
* @return A formatted string with the employee's name and monthly salary.
*/
@Override
public String toString()
{
// Format to match example output
return String.format("%-10s %-10s %8.2f", this.firstName, this.lastName, this.monthlySalary);
}
// Additional method for yearly salary calculation after 10% increase
/**
* Increases the monthly salary by 10% and calculates the yearly salary.
*
* @return The yearly salary after a 10% increase.
*/
public double getYearlySalaryWithIncrease()
{
return this.monthlySalary *12*1.10;
}
}
picture attached show the difference
need help formatting output, the codes what is

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 Programming Questions!