Question

create java application with the following specifications: -create an employee class with the following attibutes: name...

create java application with the following specifications:

-create an employee class with the following attibutes: name and salary

-add constuctor with arguments to initialize the attributes to valid values

-write corresponding get and set methods for the attributes

-add a method in Employee called verify() that returns true/false and validates that the salary falls in range1,000.00-99,999.99

Add a test application class to allow the user to enter employee information and display output:

-using input(either scanner or jOption), allow user to enter the number of employees

-create an array of employee objects preset to the employee number

-in your test class loop through to instantiate each Employee object. the loop body should allow the user to input the Employee attributes(choice of scanner or joption)

-use verify() mthod to validate that the salarty falls in range1000.00-99,999.99

-if the salary is valid, store Employee instance in the array. if the salary is invalid , do NOT add Employee instance to array; show error message

-if user enters "FINISH" in an input , stop allowing any more employee records to be entered. Display the output.

-after reaching the number of employee elements entered display the Employee information similar to the example below. Do not display null or empty elements if any.

EXAMPLE:    Employee    Salary

   ---------------    -----------

   Jane Doe    $45,025.75

   Jacob Park $45,025.79

0 0
Add a comment Improve this question Transcribed image text
Answer #1

import java.util.Scanner;

class Employee {
   private String name;
   private double salary;

   public Employee(String aName, double aSalary) {
       super();
       name = aName;
       salary = aSalary;
   }

   public String getName() {
       return name;
   }

   public void setName(String aName) {
       name = aName;
   }

   public double getSalary() {
       return salary;
   }

   public void setSalary(double aSalary) {
       salary = aSalary;
   }

   public boolean verify() {
       return salary >= 1000 && salary <= 99999.99;
   }

   @Override
   public String toString() {
       return name + "\t\t$" + salary;
   }

}

public class TestEmployee {
   public static void main(String[] args) {
       Scanner sc = new Scanner(System.in);
       System.out.println("Enter the number of employee : ");
       int n = sc.nextInt();
       sc.nextLine();
       Employee e[] = new Employee[n];
       String name = "";
       int index = 0;
       double sal;
       for (int i = 0; i < n; i++) {
           System.out.println("Enter name : ");
           name = sc.nextLine();
           if (name.equalsIgnoreCase("FINISH"))
               break;
           System.out.println("Enter salary");
           sal = sc.nextDouble();
           sc.nextLine();
           Employee em = new Employee(name, sal);
           if (em.verify())
               e[index++] = em;
       }
       System.out.println("Employee\tSalary");
       for (int i = 0; i < n; i++) {
           if (e[i] != null)
               System.out.println(e[i]);
       }
   }
}

Console 3 <terminated> TestEmployee (1) Java Application] C\Soft Pe Enter the number of employee: Enter name: Uday Enter sala

Add a comment
Know the answer?
Add Answer to:
create java application with the following specifications: -create an employee class with the following attibutes: name...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Create a Java application, that support the following: Create an Employee class, which holds following information:...

    Create a Java application, that support the following: Create an Employee class, which holds following information: Employee First Name Employee Last Name Employee Phone Number Employee Address Employee id Employee Title Employee salary Create an application that uses the Employee class Constructors –Getters and setters A minimum of 3 constructors including default constructor equals() method Helper methods toString() method Create an array of 5 Employee objects Use a Scanner to read in 5 employee information Change 2 employees information (3-items...

  • In Java Create a class Worker. Your Worker class should include the following attributes as String...

    In Java Create a class Worker. Your Worker class should include the following attributes as String variables: Name, Worker ID, Worker Address, Worker City, Worker State Create the constructor that initializes the above worker attributes. Then make another class name HourlyWorker that inherits from the Worker class.   HourlyWOrker has to use the inherited parent class variables and add in hourlySalary and billableHours. Your HourlyWorker class should contain a constructor that calls the constructor from the Worker class to initialize the...

  • In Java: Executable Class create an array of Employee objects. You can copy the array you...

    In Java: Executable Class create an array of Employee objects. You can copy the array you made for Chapter 20. create an ArrayList of Employee objects from that array. use an enhanced for loop to print all employees as shown in the sample output. create a TreeMap that uses Strings for keys and Employees as values. this TreeMap should map Employee ID numbers to their associated Employees. process the ArrayList to add elements to this map. print all employees in...

  • in Java Create an object class for the Employee Master (Employee). Select data types that will...

    in Java Create an object class for the Employee Master (Employee). Select data types that will best represent the data to be stored. All variables are to be declared with a private access modifier. Provide assessor/mutator methods for each instance field. Also provide a display data method that displays all of the instance fields of the class. Be sure each field is preceded by the text name of the field. Employee Master (Employee) Employee Number                              Numeric                 0 decimals, max size...

  • In Java. Write a GUI contact list application. The program should allow you to input names...

    In Java. Write a GUI contact list application. The program should allow you to input names and phone numbers. You should also be able to input a name and have it display the previously entered phone number. The GUI should look something like the following, although you are welcome to format it in any way that works. This should be a GUI application with a JFrame. The program should contain two arrays of Strings. One array will contain a list...

  • Create the Python code for a program adhering to the following specifications. Write an Employee class...

    Create the Python code for a program adhering to the following specifications. Write an Employee class that keeps data attributes for the following pieces of information: - Employee Name (a string) - Employee Number (a string) Make sure to create all the accessor, mutator, and __str__ methods for the object. Next, write a class named ProductionWorker that is a subclass of the Employee class. The ProductionWorker class should keep data attributes for the following information: - Shift number (an integer,...

  • Create an abstract class Employee. Your Employee class should include the following attributes: First name (string)...

    Create an abstract class Employee. Your Employee class should include the following attributes: First name (string) Last name (string) Employee id (string) Employee home street address (string) Employee home city (string) Employee home state (string) Write a constructor to initialize the above Employee attributes. Create an abstract method called earnings.      Create another class HourlyEmployee that inherits from the abstract Employee class.   HourEmployee must use the inherited parent class variables and add in attributes HourlyRate and HoursWorked. Your HourEmployee class should...

  • Create an abstract class Employee. Your Employee class should include the following attributes: First name (string)...

    Create an abstract class Employee. Your Employee class should include the following attributes: First name (string) Last name (string) Employee id (string) Employee home street address (string) Employee home city (string) Employee home state (string) Write a constructor to initialize the above Employee attributes. Create an abstract method called earnings.      Create another class HourlyEmployee that inherits from the abstract Employee class.   HourEmployee must use the inherited parent class variables and add in attributes HourlyRate and HoursWorked. Your HourEmployee class should...

  • In one file create an Employee class as per the following specifications: three private instance variables:...

    In one file create an Employee class as per the following specifications: three private instance variables: name (String), startingSalary (int), yearlyIncrement (int) a single constructor with three arguments: the name, the starting salary, and the yearly increment. In the constructor, initialize the instance variables with the provided values. get and set methods for each of the instance variables. A computation method, computeCurrentSalary, that takes the number of years in service as its argument. The method returns the current salary using...

  • python code? 1. Create a class called Person that has 4 attributes, the name, the age,...

    python code? 1. Create a class called Person that has 4 attributes, the name, the age, the weight and the height [5 points] 2. Write 3 methods for this class with the following specifications. a. A constructor for the class which initializes the attributes [2.5 points] b. Displays information about the Person (attributes) [2.5 points] c. Takes a parameter Xage and returns true if the age of the person is older than Xage, false otherwise [5 points] 3. Create another...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT