Question

In: Computer Science

Implementation Requirements: 1. Inheritance 2. Polymorphism 3. Linked List with appropriate payload 4. UML Diagrams (pre-coding...

Implementation Requirements:

1. Inheritance

2. Polymorphism

3. Linked List with appropriate payload

4. UML Diagrams (pre-coding design)

Project Problem Domain:

Write a program that tracks the faculty's information, such as id, names, rank, and number of allowed courses if the faculty is an adjunct. The hierarchy will be based on an abstract class Faculty and two derived classes, Professor and Adjunct. For this project, you will store all instances of faculty in a linked list! Have your program allow the user to enter records, display all records, find a record, and delete a record. Those options should be displayed in a menu at run time.

Solutions

Expert Solution

Here is the code,

Faculty.java

public abstract class Faculty{
    private int id;
    private String name;
    private String rank;
    public Faculty(int id, String name, String rank){
        this.id = id;
        this.name = name;
        this.rank = rank;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getRank() {
        return rank;
    }

    public void setRank(String rank) {
        this.rank = rank;
    }

    @Override
    public String toString() {
        return "id=" + id + ", name='" + name + "', rank='" + rank+"'";
    }
}

Professor.java

public class Professor extends Faculty{
    public Professor(int id, String name, String rank){
        super(id, name, rank);
    }

    @Override
    public String toString() {
        return "Adjunct{" + super.toString() + '}';
    }
}

Adjunct.java

public class Adjunct extends Faculty{
    private int numberOfAllowedCourses;
    public Adjunct(int id, String name, String rank, int numberOfAllowedCourses){
        super(id, name, rank);
        this.numberOfAllowedCourses = numberOfAllowedCourses;
    }

    public int getNumberOfAllowedCourses() {
        return numberOfAllowedCourses;
    }

    public void setNumberOfAllowedCourses(int numberOfAllowedCourses) {
        this.numberOfAllowedCourses = numberOfAllowedCourses;
    }

    @Override
    public String toString() {
        return "Adjunct{" + super.toString() +
                ", numberOfAllowedCourses=" + numberOfAllowedCourses + '}';
    }
}

Runner.java

import java.util.*;

public class Runner {

    private static final Scanner sc = new Scanner(System.in);
    private static LinkedList<Faculty> list;

    public static void main(String[] args) {
        /*
        For this project, you will store all instances of faculty in a linked list!
        Have your program allow the user to enter records, display all records, find a record, and delete a record.
        Those options should be displayed in a menu at run time.
         */

        list = new LinkedList<>();
        System.out.println("1. Enter Record\n2. Display all records\n3. Find a record.\n4. Delete a record.\n5. Exit");
        while (true){
            System.out.println("Chose one of the options :\n");
            int choice = sc.nextInt();
            switch (choice){
                case 1 : enterRecord();
                    break;
                case 2 : displayRecord();
                    break;
                case 3 : findRecord();
                    break;
                case 4 : deleteRecord();
                    break;
                case 5 : return;
                default:
                    System.out.println("Please enter correct choice.");
            }
        }

    }

    private static void enterRecord(){
        System.out.println("Enter id : ");
        int id = sc.nextInt();
        System.out.println("Enter name : ");
        String name = sc.next();
        System.out.println("Enter rank : ");
        String rank = sc.next();
        System.out.println("Is Adjunct? (y/n): ");
        boolean isAdjunct = sc.next().charAt(0) == 'y';
        Faculty faculty;
        if(isAdjunct){
            System.out.println("Enter number of allowed courses : ");
            int numberOfAllowedCourses = sc.nextInt();
            faculty = new Adjunct(id, name, rank, numberOfAllowedCourses);
        }
        else faculty = new Professor(id, name, rank);
        list.add(faculty);
        System.out.println("Successfully entered record.");
    }

    private static void displayRecord(){
        if(list.isEmpty()){
            System.out.println("No data records available.");
            return;
        }
        StringBuilder records = new StringBuilder();
        for(Faculty faculty : list){
            if(faculty instanceof Adjunct) {
                Adjunct adjunct = (Adjunct) faculty;
                records.append(adjunct.toString()).append("\n");
            }
            else{
                Professor professor = (Professor) faculty;
                records.append(professor.toString()).append("\n");
            }
        }
        System.out.println("Records in the list :\n"+records.toString());
    }

    private static void findRecord(){
        System.out.println("Enter id to search for a record : ");
        int id = sc.nextInt();
        for(Faculty faculty : list){
            if(faculty instanceof Adjunct) {
                Adjunct adjunct = (Adjunct) faculty;
                if(adjunct.getId() == id){
                    System.out.println("Record found : "+adjunct.toString());
                }
            }
            else{
                Professor professor = (Professor) faculty;
                if(professor.getId() == id){
                    System.out.println("Record found : "+professor.toString());
                }
            }
        }
    }

    private static void deleteRecord(){
        System.out.println("Enter id to delete a record : ");
        int id = sc.nextInt();
        for(Faculty faculty : list){
            if(faculty.getId() == id){
                list.remove(faculty);
                System.out.println("Record deleted.");
                return;
            }
        }
    }
}

OUTPUT :

If you have any doubt ask in the comments. Also don't forget to upvote the solution.


Related Solutions

Please use C++ and linked list to solve this problem Linked list 1 -> 3 ->...
Please use C++ and linked list to solve this problem Linked list 1 -> 3 -> 4 -> 5-> 6 ->7 replaceNode( 5 , 6) // Replace 5 with 6     result 1 -> 3 -> 4 -> 6 -> 6 ->7 Base code #include <iostream> using namespace std; class Node { public:     int data;     Node *next;     Node(int da = 0, Node *p = NULL) {         this->data = da;         this->next = p;     } };...
Please use C++ and linked list to solve this problem Linked list 1 -> 2 ->...
Please use C++ and linked list to solve this problem Linked list 1 -> 2 -> 3 -> 4 -> 5-> 6 ->7 replaceNode( 5 , 6) // Replace 5 with 6     result 1 -> 2 -> 3 -> 4 -> 6 -> 6 ->7 Base code #include <iostream> using namespace std; class Node { public:     int data;     Node *next;     Node(int da = 0, Node *p = NULL) {         this->data = da;         this->next =...
Task 1: [10 Marks] Write a function “reverse” in your queue class (linked list implementation) that...
Task 1: [10 Marks] Write a function “reverse” in your queue class (linked list implementation) that reverses the whole queue. In your driver file (main.cpp), create an integer queue, push some values in it, call the reverse function to reverse the queue and then print the queue.
Make following changes. step(A) step 1 Implementation a Generic Linked List using the program developed in...
Make following changes. step(A) step 1 Implementation a Generic Linked List using the program developed in the class. step 2  Implement StackImpl class using the generic linked list. step 3 Test the program with different type and number of matching and un-matching brackets. This is how it works! When you run the class MatchBrackets a popup dialog appears asking you to select a file. You are provided two input files in the project. input1.txt contains matching brackets and input2.txt does not...
(In Java) Inheritance Shapes: Write 5 Classes: 1) Shapes    2) Triangle 3) Rectangle    4)...
(In Java) Inheritance Shapes: Write 5 Classes: 1) Shapes    2) Triangle 3) Rectangle    4) Circle 5) TestAllShapes (create 1 object of each type and print the Area for each of them.)
SE-FamilySize 1 1 4 3 2 4 2 3 4 2 4 1 4 2 2...
SE-FamilySize 1 1 4 3 2 4 2 3 4 2 4 1 4 2 2 4 5 4 5 4 4 2 4 3 1 2 3 5 5 5 Make a confidence interval. Be sure you show all the steps you took. Include a screen shot of any applet you used in your calculations. 2. Choose a confidence level (1 – α). 3. What is xbar? 4. What is s? 5. What is t? (Show a screen shot...
A population consists of the following five values: 1, 2, 3, 3, and 4. (a) List...
A population consists of the following five values: 1, 2, 3, 3, and 4. (a) List all samples of size 2 from left to right using without replacement, and compute the mean of each sample. (Round your Mean values to 1 decimal place.)    Sample Values Sum Mean         1 (Click to select)1,23,41,42,31,3                  2 (Click to select)1,33,31,43,41,2                  3 (Click to select)1,21,41,33,43,3                  4 (Click to select)3,31,23,41,41,3                  5 (Click to select)3,32,31,23,42,4                  6 (Click to...
3. Appropriate Tendering process: required to explore various tendering processes. 4. Major requirements of a professional...
3. Appropriate Tendering process: required to explore various tendering processes. 4. Major requirements of a professional civil engineer: must discuss the responsibilities of civil engineering professional. In addition to should determine the major requirements of a civil engineer which may support the recruitment team further. 5. Construction methods: shall describe any FOUR major construction methods of the G+10 storey commercial building along with relevant images to be displayed during the induction program. Please get answers to this questions??‍♀️
4. (The last two questions are linked as a part 1 and 2, and they are...
4. (The last two questions are linked as a part 1 and 2, and they are each worth 4 points). You work in the HR department of a large corporation. Productivity is going down and the corporation is losing money, and everyone knows that a major reason for this is: many workers are showing up late or not at all while their colleagues are swiping their employee cards for them. For part 1, use the Fraud Triangle to identify why...
1. most appropriate statistical tst 2. null 3. Alternative hypothesis 4. Calculate appropriate test statistic 5....
1. most appropriate statistical tst 2. null 3. Alternative hypothesis 4. Calculate appropriate test statistic 5. A statistical conclusion The following are results of a protein standard curve assay for the presence of a protein. A standard protein of known concentration was added to each tube and the OD600 was measured on a spectrophotometer. Determine protein conc in unknown sample with a OD600 of 0.345. Protein Conc (ug/ul) OD600 0 0.000 10 0.081 20 0.118 30 0.203 60 0.378 90...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT