Java Programming. Please answer according to question using classes. LAB 1 PROGR
ID: 3709569 • Letter: J
Question
Java Programming. Please answer according to question using classes.
LAB 1 PROGRAM
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.Explanation / Answer
The code is updated as below:
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 ArrayList<Person> persons;
AddressBook(){
persons = new ArrayList<Person>();
}
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"));
}
}
import java.util.*;
public class student extends Person {
public ArrayList<String> class_taken;
public ArrayList<String> grades;
System.out.println("Marks in various subjects are as follows: ");
void print_transcript()
{
for(int i=0;i<class_taken.size();i++){
System.out.println(class_taken[i] + ": " + grades[i]);
}
}
}
import java.util.*;
public class employee extends Person {
public String department;
public int working_hours;
}
import java.util.*;
public class full_employee extends employee {
public int salary;
void hours_worked(){
return working_hours;
}
void print_wage(){
return salary;
}
}
import java.util.*;
public class hourly_employee extends employee {
public int hourly_rate;
public int hours_worked;
void no_hours_worked(){
return working_hours;
}
void print_wage(){
return hourly_rate*hours_worked;
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.