Fill in the find method and numMale method
public class ComparableDemo
{
public void init(Object arr[])
{
arr[0] = new Employee("Abby", 3000,
1, null, 'f');
arr[1] = new Employee("John", 2000,
2, (Employee)arr[0], 'm');
arr[2] = new Employee("Tim", 2000,
2, (Employee)arr[0], 'm');
arr[3] = new Employee("Tony", 1000,
3, (Employee)arr[0], 'm');
}
//this method finds and returns the Employee object in
the array whose name equals to
//the name string. If the name is not found it returns
null.
public Object find(String name, Object arr[])
{
}
//this method finds how many male Employees are stored
in the array arr
public int numMale(Object arr[])
{
}
public static void main(String args[])
{
ComparableDemo demo = new
ComparableDemo();
Object arr[] = new Object[4];
demo.init(arr);
Object target = demo.find("john",
arr);
System.out.println("Employee with
name John is found:\n" + target);
int n = demo.numMale(arr);
System.out.println("There are " + n
+ " male employees in the array.");
}
}
public class ComparableDemo
{
public void init(Object arr[])
{
arr[0] = new Employee("Abby", 3000, 1, null, 'f');
arr[1] = new Employee("John", 2000, 2, (Employee)arr[0], 'm');
arr[2] = new Employee("Tim", 2000, 2, (Employee)arr[0], 'm');
arr[3] = new Employee("Tony", 1000, 3, (Employee)arr[0], 'm');
}
//this method finds and returns the Employee object in the array whose name equals to
//the name string. If the name is not found it returns null.
public Object find(String name, Object arr[])
{
for(int i = 0;i<arr.length;i++){
if (arr[i].name.equals(name)){
return arr[i];
}
}
return null;
}
//this method finds how many male Employees are stored in the array arr
public int numMale(Object arr[])
{
int count = 0;
for(int i = 0;i<arr.length;i++){
if(arr[i].gender == 'm'){
count += 1;
}
}
return count;
}
public static void main(String args[])
{
ComparableDemo demo = new ComparableDemo();
Object arr[] = new Object[4];
demo.init(arr);
Object target = demo.find("john", arr);
System.out.println("Employee with name John is found:\n" + target);
int n = demo.numMale(arr);
System.out.println("There are " + n + " male employees in the array.");
}
}
Fill in the find method and numMale method public class ComparableDemo { public void init(Object...
Java you are required to add a public Object get( Object key) method into the Hashtable class. As defined in the Java documentation, the get() method returns the value with which the specified key is associated, or null if this hash table contains no record for the key. More formally, if this hash table contains a mapping from a key k to a value v such that (key.equals(k)), then this method returns v; otherwise it returns null. (There can be...
must provide the following public interface: public static void insertSort(int [] arr); public static void selectSort(int [] arr); public static void quickSort(int [] arr); public static void mergeSort(int [] arr); The quick sort and merge sort must be implemented by using recursive thinking. So the students may provide the following private static methods: //merge method //merge two sorted portions of given array arr, namely, from start to middle //and from middle + 1 to end into one sorted portion, namely,...
departmentstore: package departmentstorepkg; import java.util.ArrayList; public class DepartmentStore { private static final int DEFAULT_SIZE = 10; private StaffMember [] myEmployees; private int myNumberEmployees; private String myFileName; private StaffMember[] employee; public DepartmentStore (String filename){ myFileName = filename; myEmployees = employee; } public String toString(){ return this.getClass().toString() + ": " + myFileName; } public void addEmployee(Employee emp){ } /** * prints out all the employees in the array list held in this class */ public void print(){ for(int i =...
import java.util.Random; import java.util.ArrayList; /** * */ public class hw5_task8 { public static void main(String[] args) { int[] grades = randomIntArr(10); printIntArray("grades", grades); ArrayList<Integer> indexesF_AL = selectIndexes_1(grades); System.out.println(" indexesF_AL: " + indexesF_AL); int[] indexesF_Arr = selectIndexes_2(grades); printIntArray("indexesF_Arr",indexesF_Arr); } public static int[] randomIntArr(int N){ int[] res = new int[N]; Random r = new Random(0); for(int i = 0; i < res.length; i++){ res[i] = r.nextInt(101); // r.nextInt(101) returns an in in range [0, 100] } return res; } public static void...
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'm attempting to convert ch object array to double array public void calculateSalesPrice() { double salePrice[] = new double[ch.length]; int p = 0; for (int i = 0; i < ch.length; i += 3) { p = i + 1; for(int j = 0;j } } error message:items.java:16: error: cannot find symbol for(int j = 0;j ^ symbol: variable length location: class Object items.java:17: error: array required, but Object found salePrice[j] = (double full program import java.io.File; import java.util.Scanner; import...
Write a toString method for the Scores class. It should print the Scores object as follows: [(EntryName, EntryScore), (EntryName, EntryScore), (EntryName, EntryScore) , (EntryName, EntryScore), (EntryName, EntryScore), (EntryName, EntryScore) ,(EntryName, EntryScore), (EntryName, EntryScore), (EntryName, EntryScore) , (EntryName, EntryScore)] GameEntry.java public class GameEntry { protected String name; // name of the person earning this score protected int score; // the score value /** Constructor to create a game entry */ public GameEntry(String n, int s) { name = n; score =...
In the Employee class, add an implementation for the calculatePension() method declared in the interface. Calculate the pension to date as the equivalent of a monthly salary for every year in service. 4) Print the calculated pension for all employees. ************** I added the interface and I implemented the interface with Employee class but, I don't know how can i call the method in main class ************ import java.io.*; public class ManagerTest { public static void main(String[] args) { InputStreamReader...
//*Manager.java*//
public interface Manager {
public void handleCrisis();
}
_________________________________________________________
/**Employee.java**/
Public abstract class Employee {
protected final String name;
protected final int id;
public Employee(String empName, int empId) {
name = empName;
id = empId;
}
public Employee() {
name = generatedNames[lastGeneratedId];
id = lastGeneratedId++;
}
public String getName() {
return name;
}
public int getId() {
return id;
}
//returns true if work was successful. otherwise returns false (crisis)
public abstract boolean work();
public String toString() {
return...
Rewrite following code down below using Factory Pattern. -------------------------Staff.java--------------------------- import java.util.*; public class Staff extends Employee { private int HourlyRate; /**Constructor Staff which initiates the values*/ public Staff() { super(); HourlyRate=0; } /**Overloaded constructor method * @param ln last name * @param fn first name * @param ID Employee ID * @param sex Sex * @param hireDate Hired Date * @param hourlyRate Hourly rate for the work...