Question: just need to fix the format error with Arik Haversham 1 3 0 0 . 2 5 so that line lines up with the rest

just need to fix the format error with Arik Haversham 1300.25so that line lines up with the rest as shown in picture
/**
*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.
*It also implements the Comparable interface to compare employees.
*
*@author
*@version 18/11/2024
*/
public class Employee implements Comparable
{
private String firstName;
private String lastName;
private double monthlySalary;
public Employee(String firstName, String lastName, double monthlySalary)
{
this.firstName =firstName;
this.lastName =lastName;
this.monthlySalary =monthlySalary >=0?monthlySalary : 0;
}
public void setFirstName(String firstName)
{
this.firstName =firstName;
}
public void setLastName(String lastName)
{
this.lastName =lastName;
}
public void setMonthlySalary(double monthlySalary)
{
if (monthlySalary >=0)
{
this.monthlySalary =monthlySalary;
}
}
public String getFirstName()
{
return this.firstName;
}
public String getLastName()
{
return this.lastName;
}
public double getMonthlySalary()
{
return this.monthlySalary;
}
@Override
public String toString()
{
return String.format("%-9s %-8s %8.2f",this.firstName, this.lastName, this.monthlySalary);
}
public double getYearlySalaryWithIncrease()
{
return this.monthlySalary *12*1.10;
}
/**
*Compares employees first by last name, then by first name, and finally by monthly salary.
*
*@param other The other employee to compare against.
*@return A negative integer, zero, or a positive integer if this employee is less than, equal to,or greater than the specified employee.
*/
@Override
public int compareTo(Employee other)
{
//Compare by last name
int lastNameComparison =this.lastName.compareTo(other.lastName);
//If last names are the same, compare by first name
if (lastNameComparison ==0)
{
int firstNameComparison =this.firstName.compareTo(other.firstName);
//If first names are the same, compare by monthly salary
if (firstNameComparison ==0)
{
return Double.compare(this.monthlySalary, other.monthlySalary);
}
return firstNameComparison;
}
return lastNameComparison;
}
}
import java.util.*;
public class EmployeeComparableDemo
{
public static void main(String[]args)
{
//Step 1: Create Employee objects
Employee e1=new Employee("Harry","Brown",2200.50);
Employee e2=new Employee("Nisha","Napier",5050.00);
Employee e3=new Employee("Huyen","Le",7860.25);
Employee e4=new Employee("Arik","Haversham",1300.25);
Employee e5=new Employee("Nina","Le",5640.35);
Employee e6=new Employee("Marticia","Brown",2200.50);
Employee e7=new Employee("William","Jones",3124.65);
Employee e8=new Employee("Naquita","Jones",4000.00);
//Step 2: Create ArrayList and add employees
ArrayList employees =new ArrayList>();
employees.add(e1);
employees.add(e2);
employees.add(e3);
employees.add(e4);
employees.add(e5);
employees.add(e6);
employees.add(e7);
employees.add(e8);
//Step 3: Print the unsorted list
System.out.println("Unsorted original list: ");
System.out.println();
for (Employee e : employees)
{
System.out.println(e);
}
//Step 4: Sort the employees using Collections.sort()
Collections.sort(employees);
//Step 5: Print the sorted list
System.out.println("
Sorted list by last name, first name, then Salary: ");
System.out.println();
for (Employee e : employees)
{
System.out.println(e);
}
}
}
just need to fix the error with Arik Haversham 1300.25so that line lines up with the rest as shown in picture
just need to fix the format error with Arik

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!