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...
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...
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...
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) ExceptionSum The objective of this exercise is to create a method that adds all the...
(JAVA) ExceptionSum The objective of this exercise is to create a method that adds all the numbers within an array with an exception you cant sum the 6, and the 7, and the numbers between them cannot be added too, taking into account that whenever a 6 appears will be followed by a 7. If we have an array such that [1,2,3,6,10,9,8,7,5] when we pass it through the method it will give us an int such that the sum will...
Java Programming Create a class named Problem1, and create a main method, the program does the...
Java Programming Create a class named Problem1, and create a main method, the program does the following: - Prompt the user to enter a String named str. - Prompt the user to enter a character named ch. - The program finds the index of the first occurrence of the character ch in str and print it in the format shown below. - If the character ch is found in more than one index in the String str, the program prints...
in Java, Create a class called EMPLOYEE that includes three instance variables – a first name...
in Java, Create a class called EMPLOYEE that includes three instance variables – a first name (type String), a last name (type String) and a monthly salary (double). Provide a constructor that initializes the three instance variables. Provide a set and a get method for each instance variable. If the monthly salary is not positive, do not set its value. Write a test app names EmployeeTest that demonstrates class EMLOYEE’s capabilities. Create two EMPLOYEE objects and display each object’s yearly...
Java program In this assignment you are required to create a text parser in Java/C++. Given...
Java program In this assignment you are required to create a text parser in Java/C++. Given a input text file you need to parse it and answer a set of frequency related questions. Technical Requirement of Solution: You are required to do this ab initio (bare-bones from scratch). This means, your solution cannot use any library methods in Java except the ones listed below (or equivalent library functions in C++). String.split() and other String operations can be used wherever required....
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT