Question

In: Computer Science

JAVA Given the company and Employee interface, create a findLeastPaid() method (that will do the opposite...

JAVA

Given the company and Employee interface, create a findLeastPaid() method (that will do the opposite of whats below). instead of finding the the best paid convert it find the lowest paid person.

Given the Company and FullTimeEmployee classes and the Employee interface,
write a Java program that reads in a file of full time employees with each line of
input containing the name of the employee (String) and gross Salary (double) and stores
them in an array list. Then using the arraylist of stored employees, find and print the
less paid employee (name) and his/her pay. If there is more than one such, print any one
lesst paid employee information.

---------------------------------------------------------------------------------
import java.util.*; // for the Scanner class

import java.io.*;

public class Company
{

public static void main (String[ ] args) throws FileNotFoundException
{
new Company().run();
} // method main
  
/**
* Determines and prints out the best paid of the full-time employees
* scanned in from a specified file.
*
*/  
public void run() throws FileNotFoundException // see Section 2.3   
{
final String INPUT_PROMPT = "Please enter the path for the file of employees: ";
  
final String BEST_PAID_MESSAGE =
"\n\nThe best-paid employee (and gross pay) is ";
  
final String NO_INPUT_MESSAGE =
"\n\nError: There were no employees scanned in.";

String fileName;
  
System.out.print (INPUT_PROMPT);
fileName = new Scanner (System.in).nextLine();
Scanner sc = new Scanner (new File (fileName));
  
FullTimeEmployee bestPaid = findBestPaid (sc);
  
if (bestPaid == null)
System.out.println (NO_INPUT_MESSAGE);
else
System.out.println (BEST_PAID_MESSAGE + bestPaid.toString());
} // method run


/**
* Returns the best paid of all the full-time employees scanned in.
*  
* @param sc – the Scanner object used to scan in the employees.
*
* @return the best paid of all the full-time employees scanned in,
* or null there were no employees scanned in.
*
*/  
public FullTimeEmployee findBestPaid (Scanner sc)
{
FullTimeEmployee full,
bestPaid = new FullTimeEmployee();   

while (sc.hasNext())
{
full = getNextEmployee (sc);
if (full.getGrossPay() > bestPaid.getGrossPay())
bestPaid = full;
} //while
if (bestPaid.getGrossPay() == 0.00)   
return null;
return bestPaid;
} // method findBestPaid


/**
* Returns the next full-time employee from the file scanned by a specified Scanner
* object.
*  
* @param sc – the Scanner object over the file.
*
* @return the next full-time employee scanned in from sc.
*
*/  
protected /*private*/ FullTimeEmployee getNextEmployee (Scanner sc)
{
Scanner lineScanner = new Scanner (sc.nextLine());
  
String name = lineScanner.next();
  
double grossPay = lineScanner.nextDouble();

return new FullTimeEmployee (name, grossPay);
} // method getNextEmployee

} // class Company

---------------------------------------------------------------------------------
import java.text.DecimalFormat;

public interface Employee
{

final static DecimalFormat MONEY = new DecimalFormat (" $0.00");
// a class constant used in formatting a value in dollars and cents

/**
* Returns this Employee object’s name.  
*
* @return this Employee object’s name.
*
*/
String getName();


/**
* Returns this Employee object’s gross pay.  
*
* @return this Employee object’s gross pay.
*
*/
double getGrossPay();


/**
* Returns a String representation of this Employee object with the name
* followed by a space followed by a dollar sign followed by the gross
* weekly pay, with two fractional digits (rounded).
*
* @return a String representation of this Employee object.
*
*/
String toString();

} // interface Employee


---------------------------------------------------------------------------------
public class FullTimeEmployee implements Employee
{
protected /*private*/ String name;
protected /*private*/ double grossPay;
public FullTimeEmployee()
{
final String EMPTY_STRING = "";
name = EMPTY_STRING;
grossPay = 0.00;
} // default constructor


/**
* Initializes this FullTimeEmployee object's name and gross pay from a
* a specified name and gross pay.
*
* @param name - the specified name.
* @param grossPay - the specified gross pay.
*
*/
public FullTimeEmployee (String name, double grossPay)
{
this.name = name;
this.grossPay = grossPay;
} // 2-parameter constructor


/**
* Returns the name of this FullTimeEmployee object.
*
* @return the name of this FullTimeEmployee object.
*
*/
public String getName()
{
return name;
} // method getName


/**
* Returns the gross pay of this FullTimeEmployee object.
*
* @return the gross pay of this FullTimeEmployee object.
*
*/
public double getGrossPay()
{
return grossPay;
} // method getGrossPay


/**
* Returns a String representation of this FullTimeEmployee object with the
* name followed by a space followed by a dollar sign followed by the gross
* weekly pay, with two fractional digits (rounded), followed by " FULL TIME".
*
* @return a String representation of this FullTimeEmployee object.
*
*/
public String toString()
{
final String EMPLOYMENT_STATUS = " FULL TIME";

return name + MONEY.format (grossPay) + EMPLOYMENT_STATUS;
// the format method returns a String representation of grossPay.
} // method toString

} // class FullTimeEmployee

Solutions

Expert Solution


Related Solutions

In Java Create an interface Create an interface Printing, which have a method getPageNumber () that...
In Java Create an interface Create an interface Printing, which have a method getPageNumber () that return page number of any printing. Create an abstract class named Novel that implements Printing. Include a String field for the novel's title and a double field for the novel price. Within the class, include a constructor that requires the novel title, and add two get methods--one that returns the title and one that returns the price. Include an abstract method named setPrice().. Create...
Programming Language : JAVA Create an interface named Turner, with a single method called turn(). Then...
Programming Language : JAVA Create an interface named Turner, with a single method called turn(). Then create 4 classes: 1- Leaf: that implements turn(), which changes the color of the Leaf object and returns true. If for any reason it is unable to change color, it should return false (you can come up with a reason for failure). The new color can be determined at random. 2- Document: that implements turn(), which changes the page on the document to the...
JAVA 1. Create an Interface Vehicle. Declare one public void method in it paint( ). 2....
JAVA 1. Create an Interface Vehicle. Declare one public void method in it paint( ). 2. Create a class Car. Implements Vehicle. It's paint() method prints "Car Painted". It's drive( ) method prints "Car Driven". 3. Create a class Bus. Implements Vehicle. It's paint() method prints "Bus Painted" . It's drive( ) method prints "Bus Driven".   4. Create a method AutoWork which accepts an object of type Vehicle. The method makes a call to the vehicle's paint( ) and drive()...
Create a java program that will do the following: Create a method called getInt.Allow the user...
Create a java program that will do the following: Create a method called getInt.Allow the user to enter up to 20 student names,and for each student 3 quiz scores (in the range 0-100). Once input is done, display each student’s name, their three quiz scores, and their quiz score average, one student per line. The output table does not need to line up perfectly in columns.Use dialog boxes for all input and output.Use the method to input the three scores.Parameter...
Use the below info to create a java program A GUI interface to ensure a user...
Use the below info to create a java program A GUI interface to ensure a user is old enough to play a game. Properly formatted prompts to input name, address, phone number, and age. Remember that name, address, phone number, etc. can be broken out in additional fields. Refer to the tutorial from this week’s Reading Assignment Multiple vs. Single Field Capture for Phone Number Form Input for help with this. Instructions to ensure that the information is displayed back...
Using Java The given class SetInterface.java is : public interface SetInterface<T> {    /**    *...
Using Java The given class SetInterface.java is : public interface SetInterface<T> {    /**    * Gets the current number of entries in this set.    *    * @return The integer number of entries currently in the set.    */    public int getSize();    /**    * Sees whether this set is empty.    *    * @return True if the set is empty, or false if not.    */    public boolean isEmpty();    /**    *...
package design; public interface Employee { /*Employee is an Interface which contains multiple unimplemented methods.Again few...
package design; public interface Employee { /*Employee is an Interface which contains multiple unimplemented methods.Again few methods has been declared in below. you need to brainstorm to add more methods to meet the business requirements. */ //please read the following method and understand the business requirements of these following methods //and then implement these in a concrete class. //employeeId() will return employee id. public int employeeId(); //employeeName() will return employee name public String employeeName(); //assignDepartment() will assign employee to departments...
Java Coding Part A Create a class Employee. Employees have a name.   Also give Employee a...
Java Coding Part A Create a class Employee. Employees have a name.   Also give Employee a method paycheck() which returns a double. For basic employees, paycheck is always 0 (they just get health insurance). Give the class a parameterized constructor that takes the name; Add a method reportDeposit. This method prints a report for the employee with the original amount of the paycheck, the amount taken out for taxes (we will do a flat 17%), and the final amount (for...
Create an interface MessageEncoder that has a single abstract method encode(plainText) where the plainText is the...
Create an interface MessageEncoder that has a single abstract method encode(plainText) where the plainText is the message to be encoded. The method will return the encoded version of the message. Then create a class SubstitutionCipher that implements this interface. The constructor should have on parameter called shift. Define the method encode so that each letter is shifted by the value in shift. For example if shift is 3 a will be replaced by d, b will be replaced by e....
Java Create a method to display a menu. When this method is called it should receive...
Java Create a method to display a menu. When this method is called it should receive the user's name, great the user, and ask them to make a selection. 1 - Change your name, 2 - Test your IQ, 3 - Display a table, 4 - Play a game, 5 - Exit.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT