I need to use the verify method I have built in the Employee class and check if the salary falls in the range. If not I shouldn't store it in the array. I have tried various ways but it still gets stored in the array...
here is my employee class: https://pastebin.com/iLzTuWe4
here is my test class: https://pastebin.com/Z33Q6h8E
/**
*
* @author Ivan Filipov
* @version 28Jun2019
*/
/*
* Mistake you have made is you have create an object in array
itself.
* array[i] = new Employee(name, salary);
* above statement will insert this object with
valid/invalid data in array.
* but if it is invalid you are not removing it.
* that's why it's inserting.
* first you store it in a Employee object separately.
* then verify that object, it it is valid
* then put it in array.
* While inserting array[i] is used. if you give an invalid
data
* i will increment, and and the next valid object will be in
incremented i position.
* so, increment i only if valid details are
given.
*
*/
import javax.swing.JOptionPane;
public class TestEmployee {
public static void main(String[] args) {
String name;
int salary;
int numberOfEmployees;
numberOfEmployees =
Integer.parseInt(JOptionPane.showInputDialog("Enter the number of
employees: " ));
Employee[] array = new
Employee[numberOfEmployees];{
for(int i = 0; i <
numberOfEmployees; )//don't increment i for each execution of
statments in for loop.
{
//increment i
only if valid data is entered.
name =
JOptionPane.showInputDialog("Enter name of employee " +
(i+1));
salary =
Integer.parseInt(JOptionPane.showInputDialog("Enter the salary of
the employee " + (i+1)));
//create an
employee object
Employee emp =
new Employee(name, salary);
//verify the emp
object
if(emp.verify())
{
//if valid insert in employee object
array[i] = emp;
//increment the i
i++;
}
else
{
JOptionPane.showMessageDialog(null, "The salary
should be 1000 - 99999$");
}
//check here
only emp object
if(emp.name.equals("FINISH"))
{
break;
}
}
String result = "";
for(int i = 0; i <
numberOfEmployees; i++)
{
result += "\n" +
array[i].name + " $ " + array[i].salary;
}
JOptionPane.showMessageDialog(null,
"Employee Salary" + "\n ------
-------"
+ result);
}
}
}
//Employee.java
/**
*
* @author Ivan Filipov
* @version 28Jun2019
*/
public class Employee {
String name;
int salary;
Employee(String name, int salary){
this.name = name;
this.salary = salary;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getSalary() {
return salary;
}
public void setSalary(int salary) {
this.salary = salary;
}
public boolean verify() {
if(this.salary < 1000 || this.salary > 99999) {
return false;
}else {
return true;
}
}
}
//outputs
I need to use the verify method I have built in the Employee class and check...
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...
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...
I need help with this one method in java. Here are the guidelines. Only public Employee[] findAllBySubstring(String find). EmployeeManager EmployeeManager - employees : Employee[] - employeeMax : final int = 10 -currentEmployees : int <<constructor>> EmployeeManager + addEmployee( type : int, fn : String, ln : String, m : char, g : char, en : int, ft : boolean, amount : double) + removeEmployee( index : int) + listAll() + listHourly() + listSalary() + listCommision() + resetWeek() + calculatePayout() :...
I need you guys help with my Java Class( use netbean if you can, thank a lot ). Please help me out, I may need full working code Question: An array A contains n−1 unique integers in the range [0,n−1], that is, there is one number from this range that is not in A. Design an O(n)-time algorithm for finding that number. You are only allowed to use O(1) additional space besides the array A itself. DO NOT SORT THE...
DatabaseFilter Design a DatabaseFilter class that will manage the file 1/O (input/output) of an employee ArrayList object. For a Database Filter class to actually store an ArrayList object, it must know the file to which the list must be read from or written to. Note: It is expected that you may have more methods within your class design than requested in the specifications described below. However, your class should support at a minimum the following data and operations: encapsulated data...
Please use Java only. Write a class, ZeroException, which is an Exception, and is used to signal that something is zero when it shouldn't be. -- Not needed Write the class ArrayManipulator which creates an array and provides several methods to manipulate values taken from an array. --needed ZeroException Task: -- Not needed Exceptions are used to signal many types of problems in a program. We can write our own as well to describe specific exceptional conditions which may arise....
Hi, for my Java class I have built a number guessing game. I need to separate my code into two classes and incorporate a try-catch statement. Any help would be appreciated! Here is my code. import javax.swing.JOptionPane; import javax.swing.UIManager; import java.awt.Color; import java.awt.color.*; import java.util.Random; public class game { public static void main (String [] args) { UIManager.put("OptionPane.backround", Color.white); UIManager.put("Pandelbackround", Color.white); UIManager.put("Button.background", Color.white); Random nextRandom = new Random(); int randomNum = nextRandom.nextInt(1000); boolean playerCorrect = false; String keyboardInput; int playerGuess...
Zander Inc. stores employee IDs and salaries in a sequential
access file named Employees.txt. Open the VB2015\Chap10\Zander
Solution\Zander Solution (Zander Solution.sln) file. Open the
Employees.txt file, which is contained in the project’s bin\Debug
folder. The ID and salary information appear on separate lines in
the file. Close the Employees.txt window. a. Define a structure
named Employee. The structure should contain two member
variables:
a String variable to store the ID and a Double variable to store
the salary.
b. Declare...
Java Description Write a program to compute bonuses earned this year by employees in an organization. There are three types of employees: workers, managers and executives. Each type of employee is represented by a class. The classes are named Worker, Manager and Executive and are described below in the implementation section. You are to compute and display bonuses for all the employees in the organization using a single polymorphic loop. This will be done by creating an abstract class Employee...