View the step-by-step solution to:

The file Salesperson.java partially defines a class that represents a sales person. Complete the compareTo method in the Salesperson class.

The file Salesperson.java partially defines a class that represents a sales person. Complete the compareTo method in the Salesperson class. The comparison should be based on total sales; that is, return a negative number if the executing object has total sales less than the other object and return a positive number if the sales are greater. Use the name of the sales person to break a tie (alphabetical order).

// *******************************************************
// Salesperson.java
//
// Represents a sales person who has a first name, last
// name, and total number of sales.
// *******************************************************

public class Salesperson implements Comparable
{
private String firstName, lastName;
private int totalSales;

//------------------------------------------------------
// Constructor: Sets up the sales person object with
// the given data.
//------------------------------------------------------
public Salesperson (String first, String last, int sales)
{
firstName = first;
lastName = last;
totalSales = sales;
}

//-------------------------------------------
// Returns the sales person as a string.
//-------------------------------------------
public String toString()
{
return lastName + ", " + firstName + ": t" + totalSales;
}


//-------------------------------------------
// Returns true if the sales people have
// the same name.
//-------------------------------------------
public boolean equals (Object other)
{
return (lastName.equals(((Salesperson)other).getLastName()) &&
firstName.equals(((Salesperson)other).getFirstName()));
}

//--------------------------------------------------
// Order is based on total sales with the name
// (last, then first) breaking a tie.
//--------------------------------------------------
public int compareTo(Object other)
{
int result;


return result;
}


//-------------------------
// First name accessor.
//-------------------------
public String getFirstName()
{
return firstName;
}

//-------------------------
// Last name accessor.
//-------------------------
public String getLastName()
{
return lastName;
}

//-------------------------
// Total sales accessor.
//-------------------------
public int getSales()
{
return totalSales;
}
}
Sign up to view the entire interaction

Top Answer

Dear Student Please find... View the full answer

Computer Science-8085377.zip - Preview not available

Sign up to view the full answer

Why Join Course Hero?

Course Hero has all the homework and study help you need to succeed! We’ve got course-specific notes, study guides, and practice tests along with expert tutors.

-

Educational Resources
  • -

    Study Documents

    Find the best study resources around, tagged to your specific courses. Share your own to gain free Course Hero access.

    Browse Documents
  • -

    Question & Answers

    Get one-on-one homework help from our expert tutors—available online 24/7. Ask your own questions or browse existing Q&A threads. Satisfaction guaranteed!

    Ask a Question
Ask a homework question - tutors are online