Question

In: Computer Science

We have to solve only problem 2, I'm sharing Problem 1 only for reference purpose. Problem...

We have to solve only problem 2, I'm sharing Problem 1 only for reference purpose.

Problem 1. (25 points)
Alice is going to create a notebook including the profile of all her friends. For each of her friends, she would
like to keep first-name, last-name, cell number, and birthdate (month and day). At the beginning, she doesn’t
know how many spaces she should reserve for recording her friends, so she gradually inputs her friends’
information into it.
• Please help her by first creating a Java class, called Person, with the required information from
description above, along with any required setter/getter methods. (5 points)
• Then create, a Java class, called FriendsList, that keeps the list of some persons as someone’s
friends, using the Person class above, and performs the required operations, such as add new friends,
delete/ modify an existing one, return the list of her friends sorted by last-names, report the number of
her friends, report the list of her friends who born in a given month sorted by their day of birth, and
report the list of her friends who born in a given day of a month, sorted by their last-names. She also
needs to get the cell number of a friend by giving her/his first-name and last-name. (10 points)
• Create a tester class, called MyFriends, to test the FriendList class by creating a new object of this
class, adding some friends, modifying and deleting some existing friends, retrieving and printing all
friends, retrieving and printing the list of friends who born in a given month, retrieving and printing
the list of friends who born in a given day of a month, and finding the cell number of an existing
friend by giving her/his first-name and last-name. Also, create a separate copy of the FriendList
object you have already created, and remove all friends with first-name “Shane” from the new object.
(10 points)
Java file names: Person.Java, FriendList.java, and MyFriends.java.

Problem 2. (40 points)
In this problem, we are going to reuse the Person class created in the previous problem. Therefore, first make
2
sure that you have already created Person.java based on the description provided above.
• Create a subclass of Person, called Employee, such that it can keep extra information of a person
including year of hiring, annual salary, vacation days, and unused vacation days. Provide required
setter/getter methods for this class. (10 points)
• Create a subclass of Employee, called Manager, which also has monthly bonus, and the list of all
her/his employees. Provide required setter/getter methods for this class. (10 points)
• Create a class, called Company, with the following information: name of the company, starting year,
and the list of all its employees/managers. Provide required setter/getter methods for this class. (10
points)
• Create a tester class, called MyCompany, in which you should test all the above classes by creating a
company, adding some employees/managers into it. (10 points)
• Bonus: Provide two listings of the company’s employees/managers, one sorted by last-names, and
one sorted by each manager and then her/his employees. (5 points)
Java file names: Person.Java, Employee.java, Manager.java, Company.java, and MyCompany.java.

Solutions

Expert Solution

Short Summary:

  1. Implemented the classes as per requirement
  2. As the Person class is not provided, I have created the same and intialized all variables through constructors
  3. Attached source code and output

**************Please do upvote to appreciate our time. Thank you!******************

Source Code:

Person.java

//This class holds person details
public class Person implements Comparable<Person>{
//Instance variables
   private String firstName;
   private String lastname;
   private String cellnumber;
   private String birthdate ;
   //Constructor
   public Person(String firstName, String lastname, String cellnumber, String birthdate) {
       super();
       this.firstName = firstName;
       this.lastname = lastname;
       this.cellnumber = cellnumber;
       this.birthdate = birthdate;
   }
   //Compare using lastname
   @Override
   public int compareTo(Person arg0) {
return this.lastname.compareTo(arg0.lastname);
   }
   @Override
   public String toString() {
       return "firstName=" + firstName + ", lastname=" + lastname + ", cellnumber=" + cellnumber
               + ", birthdate=" + birthdate ;
   }
   //Getters
   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 getCellnumber() {
       return cellnumber;
   }
   public void setCellnumber(String cellnumber) {
       this.cellnumber = cellnumber;
   }
   public String getBirthdate() {
       return birthdate;
   }
   public void setBirthdate(String birthdate) {
       this.birthdate = birthdate;
   }
  
  
}

Employee.java

package com.core.java;

//This class extends person
public class Employee extends Person {
//Instance variables
   private int yearOfHiring;
   private double annualSalary;
   private int vacationDays;
   private int unusedVacationDays;
   //Constructor
   public Employee(String firstName, String lastname, String cellnumber, String birthdate,int yearOfHiring, double annualSalary, int vacationDays, int unusedVacationDays) {
       super(firstName, lastname, cellnumber, birthdate);
       this.yearOfHiring = yearOfHiring;
       this.annualSalary = annualSalary;
       this.vacationDays = vacationDays;
       this.unusedVacationDays = unusedVacationDays;
   }
   @Override
   public String toString() {
       return "Employee "+super.toString()+",yearOfHiring=" + yearOfHiring + ", annualSalary=" + annualSalary + ", vacationDays="
               + vacationDays + ", unusedVacationDays=" + unusedVacationDays+"\n" ;
   }
   //Getters & setters
   public int getYearOfHiring() {
       return yearOfHiring;
   }
   public void setYearOfHiring(int yearOfHiring) {
       this.yearOfHiring = yearOfHiring;
   }
   public double getAnnualSalary() {
       return annualSalary;
   }
   public void setAnnualSalary(double annualSalary) {
       this.annualSalary = annualSalary;
   }
   public int getVacationDays() {
       return vacationDays;
   }
   public void setVacationDays(int vacationDays) {
       this.vacationDays = vacationDays;
   }
   public int getUnusedVacationDays() {
       return unusedVacationDays;
   }
   public void setUnusedVacationDays(int unusedVacationDays) {
       this.unusedVacationDays = unusedVacationDays;
   }
  
  
}

Manager.java

package com.core.java;

import java.util.List;

//This class extends Employee class
public class Manager extends Employee{
   //Instance variables
   private double monthlyBonus;
   private List<Employee> employeeList;
   //Constructor
   public Manager(String firstName, String lastname, String cellnumber, String birthdate,int yearOfHiring, double annualSalary, int vacationDays, int unusedVacationDays, double monthlyBonus,
           List<Employee> employeeList) {
       super(firstName, lastname, cellnumber, birthdate,yearOfHiring, annualSalary, vacationDays, unusedVacationDays);
       this.monthlyBonus = monthlyBonus;
       this.employeeList = employeeList;
   }

   @Override
   public String toString() {
       return "Manager "+super.toString()+" [monthlyBonus=" + monthlyBonus + ", employeeList=" + employeeList + "]";
   }
   //Getters & setters
   public double getMonthlyBonus() {
       return monthlyBonus;
   }
   public void setMonthlyBonus(double monthlyBonus) {
       this.monthlyBonus = monthlyBonus;
   }
   public List<Employee> getEmployeeList() {
       return employeeList;
   }
   public void setEmployeeList(List<Employee> employeeList) {
       this.employeeList = employeeList;
   }

}

Company.java

package com.core.java;

import java.util.List;

//This class holds the company details
public class Company {
   //Instance variables
   private String companyName;
   private int startingYear;
   private List<Employee> employeeList;
   private List<Manager> managerList;
   //Constructor
   public Company(String companyName, int startingYear, List<Employee> employeeList, List<Manager> managerList) {
       super();
       this.companyName = companyName;
       this.startingYear = startingYear;
       this.employeeList = employeeList;
       this.managerList = managerList;
   }
   @Override
   public String toString() {
       return "Company [companyName=" + companyName + ", startingYear=" + startingYear + ", employeeList="
               + employeeList + ", managerList=" + managerList + "]";
   }
   //Getters and setters
   public String getCompanyName() {
       return companyName;
   }
   public void setCompanyName(String companyName) {
       this.companyName = companyName;
   }
   public int getStartingYear() {
       return startingYear;
   }
   public void setStartingYear(int startingYear) {
       this.startingYear = startingYear;
   }
   public List<Employee> getEmployeeList() {
       return employeeList;
   }
   public void setEmployeeList(List<Employee> employeeList) {
       this.employeeList = employeeList;
   }
   public List<Manager> getManagerList() {
       return managerList;
   }
   public void setManagerList(List<Manager> managerList) {
       this.managerList = managerList;
   }

}

MyCompany.java

package com.core.java;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

//This class operates on Person,employee,manager and Company classes
public class MyCompany {

   public static void main(String[] args) {
       //Create a company object
       Company company=new Company("ABC pvt ltd", 2010, new ArrayList<>(), new ArrayList<>());
       //Create employees
       Employee emp1=new Employee("Tom","Cruise","100","Nov 14",2011, 50000, 90, 30);
       Employee emp2=new Employee("John","Abr","200","Jan 5",2010, 20000, 80, 25);
       Employee emp3=new Employee("AK","Einstien","50","Dec 20",2012, 30000, 70, 40);
       //Create employee list
       List<Employee> empList=new ArrayList<>();
       empList.add(emp1);
       empList.add(emp2);
       empList.add(emp3);
       //Create Managers
       Manager man1=new Manager("Lisa","Ray","100","Jul 14",2012, 75000, 100, 50,10,empList);
       empList=new ArrayList<>();
       empList.add(new Employee("Sachin","Tend","100","Feb 1",2013, 80000, 90, 30));
       empList.add(new Employee("Ajay","J","50","Oct 19",2014, 25000, 90, 30));
       Manager man2=new Manager("Alice","John","70","Aug 14",2013, 80000, 120, 60,10,empList);
       //Create manager list
       List<Manager> manList=new ArrayList<>();
       manList.add(man1);
       manList.add(man2);
       company.setEmployeeList(empList);
       company.setManagerList(manList);
       //Sort by employee last name
       Collections.sort(empList);
       System.out.println("***********Displaying sorted list of employees***********");
       System.out.println(empList);
       //Sort by manager last name
Collections.sort(manList);
       System.out.println("***********Displaying sorted list of managers***********");
       System.out.println(manList);

              
   }

}

Output:


**************Please do upvote to appreciate our time. Thank you!******************


Related Solutions

**** LOOKING TO SOLVE THE SECOND PART TO THIS 2 PART QUESTION; PROBLEM 4 ONLY PLEASE...
**** LOOKING TO SOLVE THE SECOND PART TO THIS 2 PART QUESTION; PROBLEM 4 ONLY PLEASE **** Automobiles arrive at the drive-through window at a post office at the rate of 4 every 10 minutes. The average service time is 2 minutes. The Poisson distribution is appropriate for the arrival rate and service times are exponentially distributed. a) What is the average time a car is in the system? 10 minutes b) What is the average number of cars in...
Because I'm trying to learn how to solve this kind of problem in the future please...
Because I'm trying to learn how to solve this kind of problem in the future please show all intermediate steps so I can follow Suppose F= <xy+y, x-y^2> Let R be the triangular regiorn bounded by the curves y=x, y=4-x, and y=0, Let C be the boundary of this region, oriented counterclock wise. a) Can you use Fundamental theorem for Line integrals to find ∮ F•dr? explain why or why not? What are the other two possible methods of finding...
Description Construct a personal retirement problem and solve it. The purpose of this exercise is to...
Description Construct a personal retirement problem and solve it. The purpose of this exercise is to use the chapter’s concepts of future values, annuities, and compounding to your personal financial planning. Instructions ◦Determine the amount of investment funds you currently have available in all personal investments and self-directed and vested retirement accounts ◦Then, determine how much you will be adding to your investments a year in the future ◦Next, decide at what age you plan to retire. Determine what annual...
What is The Buyer’s Problem and how we solve it?
What is The Buyer’s Problem and how we solve it?
1. In this problem, we assume for convenience that we consider call options for only one...
1. In this problem, we assume for convenience that we consider call options for only one share of a stock. We consider only one stock, and all options are for this stock. We denote the expiration date of the options by T, and we assume that it is the same date for all options considered below. We denote prices as pure numbers, omitting any notation for a currency such as the dollar sign. You may assume that the price C(K)...
For the Yield Management Model, we have learned to solve the problem with two prices (Full...
For the Yield Management Model, we have learned to solve the problem with two prices (Full fare vs Discount fare). Briefly describe how you will apply the model to practice.
SOLVE THE FOLLOWING USING STATISTICAL SOFTWARE R, POST YOUR CODE: PROBLEM 1. Suppose we have 100...
SOLVE THE FOLLOWING USING STATISTICAL SOFTWARE R, POST YOUR CODE: PROBLEM 1. Suppose we have 100 independent draws from some population distribution whose shape is unknown but where the population mean is 10 and SD is 2.5. Suppose tha tn=100 is sufficiently large that for the sample mean to have an approximately normal distribution. (a) What is the chance that the sample mean is within 0.1 units of the population mean? (b) What is the chance that the sample mean...
The purpose of this assignment is to identify an organizational problem to solve within your current...
The purpose of this assignment is to identify an organizational problem to solve within your current workplace or industrywhiuch is in the research field conducting surveys and construct a problem statement that can be used as the basis for an action research project. For this assignment, the first step is to identify an organizational problem to solve within your current workplace or industry. This is an opportunity for you to apply your learning while addressing a real-world problem. Part of...
The purpose of this assignment is to identify an organizational problem to solve within your current...
The purpose of this assignment is to identify an organizational problem to solve within your current workplace or industry and construct a problem statement that can be used as the basis for an action research project. For this assignment, the first step is to identify an organizational problem to solve within your current workplace or industry. This is an opportunity for you to apply your learning while addressing a real-world problem. Part of completing an action research project is clearly...
Use the following class for the following problem. The only purpose of the class is to...
Use the following class for the following problem. The only purpose of the class is to display a message both when the constructor is invoked and when the destructor is executed. class Trace { public: Trace(string n); ~Trace(); private: string name; }; Trace::Trace(string n) : name(n) { cout << "Entering " << name << "\n"; } Trace::~Trace() { cout << "Exiting " << name << "\n"; } Requirement: Extend the class Trace with a copy constructor and an assignment operator,...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT