Question

create a java prgram that have UniversityDriver Class The UniversityDriver contains the main method. The following...

create a java prgram that have UniversityDriver Class

The UniversityDriver contains the main method.

The following commands can be entered:

(a) "hire" //to hire a new faculty member
(b) "admit" //to admit a new student
(c) "find student" //to display information about a specific student: name, date of birth, and major
(d)"find faculty" //display information about a specific faculty: name, date of birth, and courses;
(e) “list students” // list the first and last names of all students
(f) “list faculty” // list the first and last names of all faculty
(g)"quit"// terminates the program and saves all Person data in a “UniversityPersons.per” file, including the ones hired and admitted by the user

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Hi, Please find the solution and rate the answer.

import java.time.LocalDate;
import java.util.ArrayList;
import java.util.List;

public class Faculty {
    private String name;
    private LocalDate dateOfBirth;
    List<Course> courses;

    @Override
    public String toString() {
        String str="";
        if (courses.size() != 0) {
            str = courses.stream().map(it -> (it.getName() + ", ")).reduce(String::concat).get();
        }
        if (courses.size() == 0)
            return "Faculty{" +
                    "name='" + name + '\'' +
                    ", dateOfBirth=" + dateOfBirth +
                    ", courses=" + null +
                    '}';
        else return "Faculty{" +
                "name='" + name + '\'' +
                ", dateOfBirth=" + dateOfBirth +
                ", courses=" + str +
                '}';
    }

    public void addCourse(Course c) {
        courses.add(c);
    }

    public void resetCourses() {
        courses.clear();
    }

    public Faculty(String name) {
        this.name = name;
        courses = new ArrayList<>();
    }

    public String getName() {
        return name;
    }

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

    public LocalDate getDateOfBirth() {
        return dateOfBirth;
    }

    public void setDateOfBirth(LocalDate dateOfBirth) {
        this.dateOfBirth = dateOfBirth;
    }
}
import java.time.LocalDate;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class UniversityDriver {
    public static void main(String[] args) {
        boolean loop = true;
        List<Faculty> faculties = new ArrayList<>();
        List<Student> students =  new ArrayList<>();
        do {
            System.out.println("Commands are 'Hire','Admit','find Student','find faculty','list students','list faculty':\n" +
                    "Commands are case insensitive - Hire is same as hire.\nEnter your Command:");
            Scanner sc = new Scanner(System.in);
            String choice = sc.nextLine();
            if (choice.equalsIgnoreCase("hire")) {
                Faculty f;
                System.out.println("Enter faculty name:");
                String str = sc.next();
                System.out.println("Enter Course he takes:");
                f = new Faculty(str);
                f.addCourse(new Course(sc.next()));
                System.out.println("enter date of birth in yyyy-mm-dd format");

                String next = sc.next();
                while (next.equalsIgnoreCase("\n")) {
                    next = sc.next();
                }
                f.setDateOfBirth(LocalDate.parse(next));
                System.out.println("Done:");
                faculties.add(f);
            }
            if (choice.equalsIgnoreCase("admit")) {
                System.out.println("Enter Student name:");
                String str = sc.next();
                System.out.println("Enter major:");
                Student st =  new Student(str);
                st.setMajor(sc.next());
                System.out.println("enter date of birth in yyyy-mm-dd format");
                st.setDateOfBirth(LocalDate.parse(sc.next()));
                System.out.println("Done");
                students.add(st);
            }
            if (choice.equalsIgnoreCase("find student")) {
                System.out.println("Enter name to find");
                String findName = sc.next();
                for (Student s:students){
                    if(s.getName().equalsIgnoreCase(findName)){
                        System.out.println(s);
                    }
                }

            }
            if (choice.equalsIgnoreCase("find faculty")) {
                System.out.println("Enter name to find");
                String findName = sc.next();
                for (Faculty s:faculties){
                    if(s.getName().equalsIgnoreCase(findName)){
                        System.out.println(s);
                    }
                }
            }
            if (choice.equalsIgnoreCase("list students")) {
                students.stream().forEach(item-> System.out.println(item));
            }
            if (choice.equalsIgnoreCase("list faculty")) {
                faculties.stream().forEach(i-> System.out.println(i));
            }
            if (choice.equalsIgnoreCase("quit")) {
                loop = false;
            }
        } while (loop);
    }
}
import java.time.LocalDate;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

public class Student {
    private String name;
    LocalDate dateOfBirth;
    private String major;

    public Student(String name) {
        this.name = name;
    }

    public String getMajor() {
        return major;
    }

    public void setMajor(String major) {
        this.major = major;
    }

    public String getName() {
        return name;
    }

    public void setDateOfBirth(LocalDate dateOfBirth) {
        this.dateOfBirth = dateOfBirth;
    }

    public LocalDate getDateOfBirth() {
        return dateOfBirth;
    }

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", dateOfBirth=" + dateOfBirth +
                ", major='" + major + '\'' +
                '}';
    }
}

class Course {
    private String name;

    @Override
    public int hashCode() {
        return Objects.hash(name);
    }

    public Course(String name) {
        this.name = name;
    }

    public String getName() {
        return name;
    }

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

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Course course = (Course) o;
        return name.equals(course.name);
    }
}

Sample out:

Add a comment
Know the answer?
Add Answer to:
create a java prgram that have UniversityDriver Class The UniversityDriver contains the main method. The following...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • You are asked to build and test the following system using Java and the object-oriented concepts ...

    You are asked to build and test the following system using Java and the object-oriented concepts you learned in this course: Project (20 marks) CIT College of Information technology has students, faculty, courses and departments. You are asked to create a program to manage all these information's. Create a class CIT to represents the following: Array of Students, each student is represented by class Student. Array of Faculty, each faculty is represented by class Faculty. Array of Course, each course...

  • 1. Do the following a. Write a class Student that has the following attributes: - name:...

    1. Do the following a. Write a class Student that has the following attributes: - name: String, the student's name ("Last, First" format) - enrollment date (a Date object) The Student class provides a constructor that saves the student's name and enrollment date. Student(String name, Date whenEnrolled) The Student class provides accessors for the name and enrollment date. Make sure the class is immutable. Be careful with that Date field -- remember what to do when sharing mutable instance variables...

  • Complete the following Java class. In this class, inside the main() method, user first enters the...

    Complete the following Java class. In this class, inside the main() method, user first enters the name of the students in a while loop. Then, in an enhanced for loop, and by using the method getScores(), user enters the grades of each student. Finally, the list of the students and their final scores will be printed out using a for loop. Using the comments provided, complete the code in methods finalScore(), minimum(), and sum(). import java.util.Scanner; import java.util.ArrayList; public class...

  • Use C++ to create a class called Student, which represents the students of a university. A...

    Use C++ to create a class called Student, which represents the students of a university. A student is defined with the following attributes: id number (int), first name (string), last name (string), date of birth (string), address (string). and telephone (area code (int) and 7-digit telephone number(string). The member functions of the class Student must perform the following operations: Return the id numb Return the first name of the student Modify the first name of the student. . Return the...

  • For the code below write a public static main() method in class Student that: - creates...

    For the code below write a public static main() method in class Student that: - creates an ArrayList<Student> object called students - adds 4 new Student objects to the students list, with some made up names and dates - sort the students list by name and display the sorted collection to System.out. use function getCompByName() - sort the students list by enrollment date and display the sorted collection to System.out. use function getCompByDate() import java.util.Comparator;    import java.util.Date;    public...

  • Write a Java program which will store, manipulate, and print student registration information. As part of...

    Write a Java program which will store, manipulate, and print student registration information. As part of the solution, identify the following classes: Student Admissions. The class Student must have the following fields – Name, Address, Id number, Courses, and Date, where: Name is a user defined class comprising of at minimum first name and last name. Address is a user defined class comprising of fields - street, city, state, and zip code. Date is a predefined class in the java.util...

  • Create a java class for an object called Student which contains the following private attributes: a...

    Create a java class for an object called Student which contains the following private attributes: a given name (String), a surname (family name) (String), a student ID number (an 8 digit number, String or int) which does not begin with 0. There should be a constructor that accepts two name parameters (given and family names) and an overloaded constructor accepting two name parameters and a student number. The constructor taking two parameters should assign a random number of 8 digits....

  • Create a class hierarchy to be used in a university setting. The classes are as follows:...

    Create a class hierarchy to be used in a university setting. The classes are as follows: The base class is Person. The class should have 3 data members: personID (integer), firstName(string), and lastName(string). The class should also have a static data member called nextID which is used to assign an ID number to each object created (personID). All data members must be private. Create the following member functions: o Accessor functions to allow access to first name and last name...

  • SQL Homework Create a single script to do all of the following. Be sure to create...

    SQL Homework Create a single script to do all of the following. Be sure to create in such a way that it can be re-run multiple times. Create a database named homework. In this database, create three tables: Student, Course, StudentCourse - Create the Student table with the following fields in this order: studentID as an integer; do not allow empty values firstName as a variable number of characters, max 30, with a null default value lastName as a variable...

  • Design and code a JAVA program called ‘Grades’. ? Your system should store student’s name, and...

    Design and code a JAVA program called ‘Grades’. ? Your system should store student’s name, and his/her course names with grades. ? Your system should allow the user to input, update, delete, list and search students’ grades. ? Each student has a name (assuming no students share the same name) and some course/grade pairs. If an existing name detected, user can choose to quit or to add new courses to that student. ? Each student has 1 to 5 courses,...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT