Skip to content
Snippets Groups Projects
Commit 12463aa3 authored by Colin Richards's avatar Colin Richards Committed by GitHub
Browse files

Add files via upload

parent 9ba01bfc
No related branches found
No related tags found
No related merge requests found
Showing
with 167 additions and 0 deletions
File added
File added
File added
File added
File added
File added
File added
File added
File added
File added
package unl.cse.company;
import java.util.ArrayList;
public class CompanyList<T> {
public CompanyList() {
tarray = new ArrayList<T>();
}
private ArrayList<T> tarray;
public void addToArray(T t) {
tarray.add(t);
}
//TODO: Add a toString method for employees for displaying (optional)
public void print() {
System.out.println(tarray.toString());
}
}
package unl.cse.company;
public interface CompanyPortfolio {
public void computeProductivity();
}
package unl.cse.company;
public abstract class Employee implements Serializable,CompanyPortfolio{
int id;
String firstName;
String lastName;
String title;
/* TODO - Do you need any more fields here ? (e.g netPay, grossPay etc)
*
*/
/* TODO Add other methods (e.g getName(), computeSalary())
* Which of them do you think should be abstract ?
*/
/* TODO What other subclasses do you need ? (e.g Hourly, Temporary etc)
* What methods can be implemented there ? (e.g hourlyPay/overtimePay?, getpay? getName? etc)
* Which of them can be abstract here ?*/
public Employee(String firstName, String lastName) {
this.firstName = firstName;
this.lastName = lastName;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
}
package unl.cse.company;
public class GenericsDemo {
public static void main(String args[]) {
// TODO: Make 2 different types of employees (change as appropriate to your design)
Employee e1 = new Permanent("","");
Permanent e2 = new Permanent("","");
//Temporary e3 = new Temporary("E","F");
// TODO: Add them to non-generic company c1 and generic company c2.
CompanyList c1 = new CompanyList();
//c1.addToArray(e1);
c1.print();
CompanyList<Permanent> c2 = new CompanyList<Permanent>();
c2.print();
// TODO: Create a product and try adding to c1 and c2
}
}
package unl.cse.company;
public class PayrollDemo {
public static void main(String[] args) {
//TODO - Create two different employees of each type , update their details
// and print their names and salaries(change as appropriate to your design)
Employee employee1 = new Temporary("John","Smith");
Employee employee2 = new Permanent("Richard","Feymann");
printSalary(employee1);
printSalary(employee2);
}
public static void printSalary(Employee e) {
System.out.println("Salary of " + e.getName() + " is: "
+ e.getPay());
}
}
\ No newline at end of file
package unl.cse.company;
import java.io.File;
import java.io.IOException;
public class PortfolioDemo {
public static void main(String[] args) {
//TODO: Create employees and products with details, export to JSON
// and compute their productivity (change as appropriate to your design)
Serializable serializableEmployee = new Temporary("Smith","John");
Serializable serializableProduct = new Product();
try {
serializableEmployee.serializeToJSON(serializableEmployee, new File("data/Employee.json"));
serializableProduct.serializeToJSON(serializableProduct, new File("data/Product.json"));
} catch (IOException e) {
e.printStackTrace();
}
CompanyPortfolio customerPortfolio = (CompanyPortfolio) serializableEmployee;
CompanyPortfolio productPortfolio = (CompanyPortfolio) serializableProduct;
customerPortfolio.computeProductivity();
productPortfolio.computeProductivity();
}
}
package unl.cse.company;
import java.io.File;
import java.io.IOException;
public interface Serializable {
public void serializeToJSON(Serializable jsonSerializable, File file) throws IOException;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment