Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Java Programming. Please answer according to question using classes. LAB 1 PROGRAM import java.util.*; public class Person { public String lastname; public String Identification; public
Java Programming. Please answer according to question using classes.
LAB 1 PROGRAM
import java.util.*; public class Person { public String lastname; public String Identification; public String address; public String firstname; Person(String p_id, String fname, String lname, String addr) { Identification = p_id; firstname = fname; lastname = lname; address = addr; } public String toString() { return "Person Id: " + Identification + ", Name: " + firstname + ", Lastname: " + lastname + ", Address: " + address; } }
import java.util.*; public class AddressBook { private ArrayListpersons; AddressBook(){ persons = new ArrayList (); } public boolean addPerson(Person p){ boolean exists = false; for(Person ps: persons){ if(ps.Identification==p.Identification){ exists = true; } } if(!exists){ persons.add(p); return true; } else{ return false; } } public String searchPerson(String word){ String str = ""; for(Person p: persons){ if(p.firstname.contains(word) || p.lastname.contains(word) || p.Identification.contains(word)){ str += p.toString()+" "; } } return str; } public void display(){ for(Person p: persons){ System.out.println(p.toString()); } } public void deletePerson(Person p){ persons.remove(p); } }
import java.util.*; public class AddressBookTester { public static void main(String args[]){ AddressBook book = new AddressBook(); Person p1 = new Person("0030", "Stephen", "Curry", "Warriors"); book.addPerson(p1); Person p2 = new Person("0024", "LeBron", "James", "Cavaliers"); book.addPerson(p2); Person p3 = new Person("0007", "Christiano", "Ronaldo", "Real Madrid"); book.addPerson(p3); Person p4 = new Person("0030", "Leo", "Messi", "Barcalona"); book.addPerson(p4); Person p5 = new Person("0010", "Monkey D", " Luffy", "One Piece"); if(!book.addPerson(p5)){ System.out.println(" Address already existed "); } System.out.println("Address Book Data: "); book.display(); System.out.println(" Searching of 0030: "); System.out.println(book.searchPerson("0030")); } }
Extend the Person class developed in labl to derive classes for students, hourly employees, and full-time salaried employees. Determine an appropriate class inheritance hierarchy. These class Should have following fields, necessary constructors, and appropriate access and modifier es methods For all employees: . Department Full-time employees: Salary Hourly employees: Hourly rate Number of hours worked each week (4 weeks) Student: . Classes taken and grades for each class (Use an ArrayList) The employee class should contain the necessary methods that will print the total hours (four- week total), average hours per week worked by each employee, and the total wages during a f s during a four week period. The student class should contain the necessary methods to print the transcript for each student
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started