DataSetEmployee
Can you please help me the JAVA program? Here is the requirement.
Rewrite DataSetBook to be DataSetEmployee.
DataSetEmployee should extend
ArrayList<Employee> and have no instance variables.
You'll have to decide what replaces the getPages concept for
getMax/getMin. As a hint, what method of Employee returns
a numeric value?
Make a package com.acme.midmanager. This package should
contain the Manager class.
Make a package com.acme.personnel. This package should
contain the DataSetEmployee class.
Make a package com.acme.topmanagement. This package should
contain the Executive class.
Make a package com.acme.workers. This package should
contain the Employee class.
Make a package com.acme.tester. This package should
contain your test driver. Your test driver can be either a class
with a main method, or JUnit tests.
You'll have to add package and import statements. Your IDE can help
with that. All instance variables should be private. You should
have no static data (unless you need a constant value for some
reason--that would be static final).
If you use a main method to test your code and specify all of an
object's data on the constructor, one simple testcase would be the
following:
Employee dilbert = new Employee("sophie", 32);
Employee pointyHair = new Manager("sally", 45, "dogfood");
Employee dogbert = new Executive("jack", 43, "selfEnrichment", .1);
DataSetEmployee empStore = new DataSetEmployee();
empStore.add(dilbert);
empStore.add(pointyHair);
empStore.add(dogbert);
System.out.println(empStore);
In this example, min would be dilbert, max would be dogbert.
--------------here is Book.java code-------------------
public class Book {
private String author;
private String title;
private int pages;
public Book(String auth, String titl, int pag)
{
author = auth;
title = titl;
pages = pag;
}
public int getPages() {
return pages;
}
@Override
public String toString() {
return "Book [author=" + author +
", title=" + title + ", pages=" + pages + "]\n";
}
// this is a really poor way to compare Book
objects, but it will work for us
/* (non-Javadoc)
* @see java.lang.Object#equals(java.lang.Object)
*/
@Override
public boolean equals(Object obj) {
if (this == obj)
return
true;
if (obj == null)
return
false;
if (getClass() !=
obj.getClass())
return
false;
Book other = (Book) obj;
if (author == null) {
if (other.author
!= null)
return false;
} else if
(!author.equals(other.author))
return
false;
if (pages != other.pages)
return
false;
if (title == null) {
if (other.title
!= null)
return false;
} else if
(!title.equals(other.title))
return
false;
return true;
}
}
------------------------------------------------------------------------------------------------------------------------------
DataSetBook.java
import java.util.ArrayList;
import java.util.Arrays;
public class DataSetBook extends ArrayList <Book>{
public DataSetBook(){
}
public boolean add(Book objToAdd){
return super.add(objToAdd);
}
public int size(){
return super.size();
}
public Book getMin(){
int size = super.size();
if(size == 0){
return
null;
}
else{
Book minBook =
super.get(0);
for(int i=0;
i<size; i++){
Book b = super.get(i);
if(minBook.getPages() > b.getPages()){
minBook = super.get(i);
}
}
return
minBook;
}
}
public Book getMax(){
int size = super.size();
if(size == 0){
return
null;
}
else{
Book maxBook =
super.get(0);
for(int i=0;
i<size; i++){
Book b = super.get(i);
if(maxBook.getPages() < b.getPages()){
maxBook = super.get(i);
}
}
return
maxBook;
}
}
public java.lang.String toString(){
return "Number of Books:
"+super.size()+"\n"+"Minimum Book is
"+getMin().toString()+"\n"+"Maximum Book is
"+getMax().toString()+"\n"+"THe content of entire store
"+Arrays.toString(super.toArray());
}
}
----------------
Employee.java
public class Employee{
String name;
double salary;
Employee(){
}
Employee(String name, double salary){
this.name = name;
this.salary = salary;
}
public String toString(){
return "Employee Name : " + name + "\n" + "Employee Salary :" +
salary ;
}
}
===========================================================================
Manager.java
public class Manager extends Employee{
String department;
Manager(){
}
Manager(String name, double salary, String department){
super(name, salary);
this.department = department;
}
public String toString(){
return "Manager Name : " + name + "\n" + "Manager Salary :" +
salary +
"\n" + "Manager department :" + department ;
}
}
====================================================================================
Executive.java
public class Executive extends Manager{
double bonus;
Executive(){
}
Executive(String name, double salary, String department, double
bonus){
super(name, salary,department);
this.bonus = bonus;
}
public String toString(){
return "Executive Name : " + name + "\n" + "Executive Salary :"
+
(salary+salary*bonus) + "\n" + "Executive department :" +
department ;
}
}
====================================================================================
Test.java
public class Test{
public static void main(String args[]){
System.out.println("Employee Details:======");
Employee dilbert = new Employee("Dilbert",2000);
System.out.println(dilbert.toString());
System.out.println("Manager Details:========");
Employee pointyHairedBoss = new
Manager("Harry",2000,"Innovation");
System.out.println(pointyHairedBoss.toString());
System.out.println("Executive Details:=======");
Employee clueless = new
Executive("John",2000,"Innovation",0.2);
System.out.println(clueless.toString());
}
}
=================================================================================
Below are the Employee, Manager, Executive, DataSetEmployee, and Test classes along with the output.
You may change the test class in order to check the program for different inputs.
Also, I have modified you Employee, Executive and Manager classses as well, so that they meet the project instructions; changes I have done in them:
1. Made all instance variables private.
2. Added getters.
3. Made constructors public.
You may post a comment in case of any other doubts in the program.
Employee.java:
package com.acme.workers;
public class Employee{
private String name;
private double salary;
public Employee(){
}
public Employee(String name, double salary){
this.name = name;
this.salary = salary;
}
public double getSalary(){
return this.salary;
}
public String getName(){
return this.name;
}
public String toString(){
return "Employee Name : " + name + "\n" + "Employee Salary :" +
salary ;
}
}
Manager.java:
package com.acme.midmanager;
import com.acme.workers.Employee;
public class Manager extends Employee{
private String department;
public String getDepartment() {
return department;
}
public Manager(){
}
public Manager(String name, double salary, String
department){
super(name, salary);
this.department = department;
}
public String toString(){
return "Manager Name : " + getName() + "\n" + "Manager Salary :" +
getSalary() +
"\n" + "Manager department :" + department ;
}
}
Executive.java:
package com.acme.topmanagement;
import com.acme.midmanager.Manager;
public class Executive extends Manager{
private double bonus;
public Executive(){
}
public Executive(String name, double salary, String department,
double bonus){
super(name, salary,department);
this.bonus = bonus;
}
public double getSalary(){
return (super.getSalary() + (super.getSalary()*bonus))
;
}
public String toString(){
return "Executive Name : " + getName() + "\n" + "Executive Salary
:" + getSalary() + "\n" + "Executive department :" +
getDepartment() ;
}
}
DataSetEmployee.java:
package com.acme.personnel;
import java.util.ArrayList;
import java.util.Arrays;
import com.acme.workers.Employee;
public class DataSetEmployee extends ArrayList<Employee>
{
public DataSetEmployee() {
}
public boolean add(Employee objToAdd) {
return super.add(objToAdd);
}
public int size() {
return super.size();
}
public Employee getMin() {
int size = super.size();
if (size == 0) {
return
null;
} else {
Employee
minEmployee = super.get(0);
for (int i = 0;
i < size; i++) {
Employee e = super.get(i);
if (minEmployee.getSalary() > e.getSalary())
{
minEmployee =
super.get(i);
}
}
return
minEmployee;
}
}
public Employee getMax() {
int size = super.size();
if (size == 0) {
return
null;
} else {
Employee maxBook
= super.get(0);
for (int i = 0;
i < size; i++) {
Employee e = super.get(i);
if (maxBook.getSalary() < e.getSalary())
{
maxBook = super.get(i);
}
}
return
maxBook;
}
}
public java.lang.String toString() {
return "Number of Employees: " +
super.size() + "\n" + "Employee with Minimum salary is "
+ getMin().toString() + "\n" + "Employee with
maximum salary is "
+ getMax().toString() + "\n" + "All employees:
"
+ Arrays.toString(super.toArray());
}
}
Test.java:
package com.acme.tester;
import com.acme.midmanager.Manager;
import com.acme.personnel.DataSetEmployee;
import com.acme.topmanagement.Executive;
import com.acme.workers.Employee;
public abstract class Test {
public static void main(String[] args) {
// TODO Auto-generated method
stub
Employee dilbert = new
Employee("sophie", 32);
Employee pointyHair = new Manager("sally", 45, "dogfood");
Employee dogbert = new Executive("jack", 43, "selfEnrichment",
.1);
DataSetEmployee empStore = new DataSetEmployee();
empStore.add(dilbert);
empStore.add(pointyHair);
empStore.add(dogbert);
System.out.println(empStore);
}
}
Output I got:
Number of Employees: 3
Employee with Minimum salary is Employee Name : sophie
Employee Salary :32.0
Employee with maximum salary is Executive Name : jack
Executive Salary :47.3
Executive department :selfEnrichment
All employees: [Employee Name : sophie
Employee Salary :32.0, Manager Name : sally
Manager Salary :45.0
Manager department :dogfood, Executive Name : jack
Executive Salary :47.3
Executive department :selfEnrichment]
DataSetEmployee Can you please help me the JAVA program? Here is the requirement. Rewrite DataSetBook to...
JAVA: How do I output all the data included for each employee? I can only get it to output the name, monthly salary and annual salary, but only from the Employee.java file, not Salesman.java or Executive.java. Employee.java package project1; public class Employee { private String name; private int monthlySalary; public Employee(String name, int monthlySalary) { this.name = name; this.monthlySalary = monthlySalary; } public int getAnnualSalary() { int totalPay = 0; totalPay = 12 * monthlySalary; return totalPay; } public String...
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 =...
Hello, How can I make the program print out "Invalid data!!" and nothing else if the file has a grade that is not an A, B, C, D, E, or F or a percentage below zero? I need this done by tomorrow if possible please. The program should sort a file containing data about students like this for five columns: one for last name, one for first name, one for student ID, one for student grade percentage, one for student...
Please help me do the java project For this project you will be reading in a text file and evaluating it in order to create a new file that represents the Class that will represent the properties of the text file. For example, consider the following text file: students.txt ID Name Age IsMale GPA 1 Tom Ryan 22 True 3.1 2 Jack Peterson 31 True 2.7 3 Cindy LuWho 12 False 3.9 When you read in the header line, you...
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...
Please fill in the remaining code necessary and follow the instructions below this is an abstract class; it represents an department in the company. This class cannot be instantiated (objects created), but it serves as the parent for other classes. Department – This class represents a department within the company. 1. Provide the implementation (the body) for the following methods: public int getDepartmentID()) public String getDepartmentName()) public Manager getManager()) 2. Fix the implementation for the following method– substitute “blah” with...
Hi! Can someone can convert this java code to c++. ASAP thanks I will thumbs up Here's the code: package lists; import bookdata.*; public class DoublyLinkedList { int size; //Variable que define el tamano de la lista. Node head, tail; //Nodos que definen el Head y Tail en la lista. //Constructor public DoublyLinkedList(){ this.head = null; this.tail = null; this.size = 0; } //Insert a new book in alphabetic order. public void insert(Book nb){ //Creamos uno nuevo nodo con el...
(JAVA NetBeans) Write programs in java Example 9.13~9.15 //Book.Java public class Book { private String title; private String author; private double price; /** * default constructor */ public Book() { title = ""; author = ""; price = 0.0; } /** * overloaded constructor * * @param newTitle the value to assign to title * @param newAuthor the value to assign to author * @param newPrice the value to assign to price */ public Book(String newTitle, String newAuthor, double newPrice)...
Language is Java, any help is appreciated. Thank you! WHERE TO START FROM: import java.util.ArrayList; //PartTest.java //package simple; public class PartTest { public static void main(String[] args) { ArrayList<ExpendablePart> system=new ArrayList<ExpendablePart>(); // creating Part Object Part part1 = new ExpendablePart("Last, First"); part1.setNumber("AX-34R"); part1.setNcage("MN34R"); part1.setNiin("ABCD-RF-WDE-KLJM"); // printing information System.out.println(part1.toString()); //Create a part2 object of class Part Part part2=new ConsumablePart("Widget, purple"); part2.setNumber("12345"); part2.setNcage("OU812"); part2.setNiin("1234-12-123-1234"); // printing information System.out.println(part2.toString()); //checking equality of two Part class objects if(part1.equals(part2)) System.out.println("part1 and...