Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.ArrayList;
- public class Person {
- // Attributes
- static private int id;
- private String firstName;
- private String lastName;
- static int lastId = 1000;
- public Person() {
- firstName = "";
- lastName = "";
- id = ++lastId;
- }
- // Constructor
- public Person(String firstName, String lastName) {
- this.firstName = firstName;
- this.lastName = lastName;
- id = ++lastId;
- }
- // Getters
- public int getId() {
- return id;
- }
- public String getFirstName() {
- return firstName;
- }
- public String getLastName() {
- return lastName;
- }
- public String getFullName() {
- return firstName + " " + lastName;
- }
- // Setters
- public void setFirstName(String firstName) {
- this.firstName = firstName;
- }
- public void setLastName(String lastName) {
- this.lastName = lastName;
- }
- static void PersonTester(){ //tester method
- Person firstPerson = new Person();
- firstPerson.setFirstName("Dina");
- firstPerson.setLastName("Khatri");
- System.out.println(firstPerson.getFullName());
- System.out.println(firstPerson.getId() + "\n");
- Person secondPerson = new Person("Margarita", "Pepperoni");
- System.out.println(secondPerson.getFullName());
- System.out.println(secondPerson.getId() + "\n");
- Person thirdPerson = new Person("Carmen", "Sandiego");
- System.out.println(thirdPerson.getFullName());
- System.out.println(thirdPerson.getId() + "\n");
- }
- public static void main(String[] args) {
- PersonTester();
- AddressBook<Person> book = new AddressBook<>();
- book.add(new Student("Will",'A'));
- book.add(new FulltimeEmplyee(23000));
- book.printBook();
- }
- }
- class Student extends Person {
- ArrayList<Tuple> classes = new ArrayList<Tuple>();
- class Tuple<C, G> {
- public final C course;
- public final G grade;
- public Tuple(C course, G grade) {
- this.course = course;
- this.grade = grade;
- }
- public String toString() {
- return "Course: " + this.course.toString() + ", Grade: " + this.grade.toString();
- }
- }
- public Student(String course, char grade) {
- classes.add(new Tuple<String, Character>(course, grade));
- }
- }
- class Employee extends Person {
- String department;
- public void totalHours(HourlyEmployee person) {
- //
- }
- public void totalHours(FulltimeEmplyee person) {
- //
- }
- public void avgHours(HourlyEmployee person) {
- //
- }
- public void avgHours(FulltimeEmplyee person) {
- //
- }
- public void totalWages(HourlyEmployee person) {
- //
- }
- public void totalWages(FulltimeEmplyee person) {
- //
- }
- }
- class HourlyEmployee extends Employee {
- int hourlyRate;
- int hoursPerWeek;
- public HourlyEmployee(int hourlyRate, int hoursPerWeek) {
- this.hourlyRate = hourlyRate;
- this.hoursPerWeek = hoursPerWeek;
- }
- }
- class FulltimeEmplyee extends Employee {
- int salary;
- //40 hour workweek
- public FulltimeEmplyee(int salary) {
- this.salary = salary;
- }
- }
- import java.util.ArrayList;
- import java.util.Arrays;
- public class AddressBook<E extends Person> {
- public ArrayList<E> person = new ArrayList<E>();
- // public AddressBook(E person) {
- // this.person.add(person);
- // System.out.println("New addressbook, use methods to change it");
- // }
- public AddressBook() {
- System.out.println("New addressbook, use methods to change it");
- }
- public void add(E person) {
- if(!this.person.contains(person)) {
- this.person.add(person);
- } else {
- System.out.println("No duplicates");
- }
- }
- public void delete(E person) {
- if(!this.person.contains(person)) {
- System.out.println("Person not found");
- } else {
- this.person.remove(person);
- }
- }
- public void search(E person) {
- if(this.person.contains(person)) {
- System.out.println("Person found at index of " + this.person.indexOf(person));
- } else {
- System.out.println("Person not found");
- }
- }
- public void printBook() {
- for(E obj : person) {
- System.out.println(obj.toString());
- }
- }
- public static void main(String[] args) {
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement