How to complete this methods:
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.time.LocalDate;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Scanner;
import java.util.Set;
/**
* Utility class that deals with all the other classes.
*
* @author EECS2030 Summer 2019
*
*/
public final class Registrar {
public static final String COURSES_FILE =
"Courses.csv";
public static final String STUDENTS_FILE =
"Students.csv";
public static final String PATH =
System.getProperty("java.class.path");
/**
* Hash table to store the list of students using their
{@code id} as the key.
*/
public static HashMap<String, Student> students
= new HashMap<String, Student>();
/**
* Hash table to store the list of course using their
{@code code} as the key.
*/
public static HashMap<String, Course> courses =
new HashMap<String, Course>();
/**
* The list of currently being courses offered.
*/
public static List<CourseOffering> offerings =
new ArrayList<CourseOffering>();
/**
* A list to hold the enrollments of students in the
offered courses.
*/
public static List<StudentEnrollement>
enrollments = new ArrayList<StudentEnrollement>();
/**
* Enrolls a {@code student} in the course {@code
offering}. This method
* verifies that 1) the course is open for enrollment,
2) the student has
* completed the prerequisite courses, and 3) the
course is not full. If any of
* those conditions is not satisfied, the method throws
an exception of the
* type @{@code Exception} with descriptive message
showing the reason.
* Otherwise the method adds an object of {@link
StudentEnrollement} class to
* the {@link enrollments} list. The enrollment object
contains references the
* student to be enrolled and the course offering. The
enrollment date shall be
* set to the current date.
*
* @param student the student to be enrolled
* @param offering the course offering available
* @throws Exception when the student cannot be
enrolled
*/
public static void enroll(Student student,
CourseOffering offering) throws Exception {
}
/**
* Returns the list of students enrolled in certain
course offering.
*
* @param offering certain course offering
* @return list of students enrolled in the
course
*/
public static List<Student>
getEnrolledStudents(CourseOffering offering) {
}
/**
* Returns the number of students enrolled in certain
course offering. This
* method counts how many {@link StudentEnrollement}
objects having their course
* offering equals to the argument.
*
* @param offering the course offering to find the
number of students enrolled
* in
* @return number of students enrolled in certain
course offering.
*/
public static int getNumEnrolled(CourseOffering
offering) {
}
/**
* Returns a reference to the course with title equals
to the argument. This
* method searches in the courses stored in the HashMap
{@code courses} to find
* the course whose title equals to the argument {@code
title}. If the course is
* not found, {@code null} is returned.
*
* @param title the title of the course
* @return a reference to the course, or {@code null}
if the course is not
* found.
*/
public static Course getCourseByTitle(String title)
{
}
/**
* Returns a reference to the Student whose name equals
to the argument. This
* method searches in the students stored in the
HashMap {@code students} to
* find the student whose name equals to the argument
{@code name}. If the
* student is not found, {@code null} is
returned.
*
* @param name the student name
* @return the student whose name is specified in the
argument, or {@code null}
* if the student is not found
*/
public static Student getStudentByName(String name)
{
}
/**
* Add a new student entry to {@code students}
HashMap.
*
* @param id id of the new student
* @param student object of the new student
* @throws Exception if the new {@code id} exists in
the {@code students}
* HashMap
*/
public static void addStudent(String id, Student
student) throws Exception {
}
/**
* Remove an existing student entry from {@code
students} HashMap.
*
* @param id the 'id' of the student to be
removed
* @throws Exception if the {@code id} does not exist
in the {@code students}
* HashMap
*/
public static void removeStudent(String id) throws
Exception {
}
/**
* Returns the entry in the {@link offerings} list that
has the information
* provided in the arguments. If the entry is not
found, {@code null} is
* returned.
*
* @param courseCode the code of the course
offered
* @param section section of the course
* @param term term
* @param year year
* @return Returns the entry in the {@link offerings}
list that has the
* information provided in the arguments
*/
public static CourseOffering getCourseOffering(String
courseCode, char section, char term, int year) {
}
1. I have defined the classes Student, Course, CourseOffering and StudentEnrollement with regards to support the methods defined in the query.
class Student{
String studentId;
String name;
List<Course> coursesCompleted;
}
class Course{
String courseId;
String title;
char section;
public boolean equals(Course course) {
if(this.courseId==course.courseId)
return
true;
else
return
false;
}
}
class CourseOffering{
Course course;
char term;
int year;
int seatsOccupied;
List<Course> prerequisiteCourses;
private final int MAX_NUM_SEATS;
CourseOffering(Course course, char term, int year, int
numOfSeats, List<Course> prerequisiteCourses){
this.course=course;
this.term=term;
this.year=year;
this.prerequisiteCourses=prerequisiteCourses;
this.seatsOccupied=0;
this.MAX_NUM_SEATS=numOfSeats;
}
public boolean isFull() {
if(this.seatsOccupied<this.MAX_NUM_SEATS)
return
false;
else
return
true;
}
public boolean hasCompletedPrerequisiteCourses(Student
student) {
// need to write the code
return true;
}
}
class StudentEnrollement{
private Student student;
private CourseOffering courseOffered;
Date enrollmentDate;
public StudentEnrollement(Student
student,CourseOffering course, Date date) {
this.student=student;
this.courseOffered=course;
this.enrollmentDate=date;
}
public Course getCourse() {
return
this.courseOffered.course;
}
public Student getStudent() {
return this.student;
}
public void enrollStudent() {
this.courseOffered.seatsOccupied+=1;
}
}
2. Below is the implementation of the class Registrar with all the methods completed and added a comment to describe the approach.
public final class Registrar {
public static final String COURSES_FILE = "Courses.csv";
public static final String STUDENTS_FILE = "Students.csv";
public static final String PATH =
System.getProperty("java.class.path");
public static HashMap<String, Student> students = new
HashMap<String, Student>();
public static HashMap<String, Course> courses = new
HashMap<String, Course>();
public static List<CourseOffering> offerings = new
ArrayList<CourseOffering>();
public static List<StudentEnrollement> enrollments = new
ArrayList<StudentEnrollement>();
public static void enroll(Student student, CourseOffering
offering) throws Exception {
// Since the correct message has to returned in case
of exception,
// so first check for all the three conditions.
// If any condition did not get match then throw
exception
// else enroll the student.
if(!offerings.contains(offering)) {
throw new Exception("Course is not
open for enrollment");
}
else if
(!offering.hasCompletedPrerequisiteCourses(student)) {
throw new Exception("Prerequisite
courses has not been completed");
}
else if (offering.isFull()) {
throw new Exception("This course
has been full");
}
else {
StudentEnrollement newEnrollment =
new StudentEnrollement(student, offering, new Date());
enrollments.add(newEnrollment);
}
}
public static List<Student>
getEnrolledStudents(CourseOffering offering) {
// loop through enrollments List and add each student
where course offered is equal to the @param offering
// Course.equals() method is used to check if two courses are equal
or not.
List<Student> studentList=new
ArrayList<Student>();
for(StudentEnrollement enrollment: enrollments)
{
if(enrollment.getCourse().equals(offering.course)) {
studentList.add(enrollment.getStudent());
}
}
return studentList;
}
public static int getNumEnrolled(CourseOffering
offering) {
// initialize count with zero.
// loop through enrollments List and increment count
by one when offered course is equal to the @param offering
int enrolledStudentsCount=0;
for(StudentEnrollement enrollment: enrollments)
{
if(enrollment.getCourse().equals(offering.course)) {
enrolledStudentsCount+=1;
}
}
return enrolledStudentsCount;
}
public static Course getCourseByTitle(String
title) {
// loop through all the courses from Hashmap courses
and if any course title matches
// @param title then return that course
Collection<Course> allCourses =
courses.values();
for(Course course: allCourses) {
if(course.title.equals(title))
return
course;
}
return null;
}
public static Student getStudentByName(String
name) {
// loop through all the students from Hashmap students
and if any student name matches
// @param name then return that student
Collection<Student> allStudents =
students.values();
for(Student student: allStudents) {
if(student.name.equals(name))
return
student;
}
return null;
}
public static void addStudent(String id, Student student)
throws Exception {
// if the student id is not present in the Hashmap
students then
// add the @param student
// else throw an exception.
if(students.containsKey(id))
throw new Exception("Student id
already exist");
students.put(id, student);
}
public static void removeStudent(String id) throws
Exception {
// if the student id is present in the Hashmap
students then remove it
// else throw an exception.
if(!students.containsKey(id))
throw new Exception("Student id
does not exist");
students.remove(id);
}
public static CourseOffering getCourseOffering(String
courseCode, char section, char term, int year) {
// loop through all the courses offered from the
list offerings and if any offering is found
// where all the parameters get matched then return
that course offered
// else return null
for(CourseOffering courseOffered:offerings) {
Course
course=courseOffered.course;
if(course.courseId.equals(courseCode) &&
course.section==section &&
courseOffered.term==term &&
courseOffered.year==year)
return
courseOffered;
}
return null;
}
}
Please let me know if any part is not clear or you may have found any difficulty or something wrong in the answer.
How to complete this methods: import java.io.FileInputStream; import java.io.FileNotFoundException; import java.time.Loc...
How to complete these methods: /** * Returns a reference to the course with title equals to the argument. This * method searches in the courses stored in the HashMap {@code courses} to find * the course whose title equals to the argument {@code title}. If the course is * not found, {@code null} is returned. * * @param title the title of the course * @return a reference to the course, or {@code null} if the course is not ...
package scheduler; import java.util.List; public class Scheduler { /** * Instantiates a new, empty scheduler. */ public Scheduler() { } /** * Adds a course to the scheduler. * * @param course the course to be added */ public void addCourse(Course course) { } /** * Returns the list of courses that this scheduler knows about. * * This returned object does not share state with the internal state of the Scheduler. * * @return the list of courses */...
DO NOT COPY AND PASTED!!!!!!!!!!!!! IF YOU DO NOT HOW TO DO IT, JUST DO NOT ANSWER MY QUESTIONS package scheduler; import java.util.List; public class Scheduler { /** * Instantiates a new, empty scheduler. */ public Scheduler() { } /** * Adds a course to the scheduler. * * @param course the course to be added */ public void addCourse(Course course) { } /** * Returns the list of courses that this scheduler knows about. * * This returned object...
PLEASE COMPLETE THE CODES. package javaprogram; import java.io.PrintStream; import java.util.ArrayList; import java.util.Scanner; /** * Movie class definition. * * @author David Brown * @version 2019-01-22 */ public class Movie implements Comparable { // Constants public static final int FIRST_YEAR = 1888; public static final String[] GENRES = { "science fiction", "fantasy", "drama", "romance", "comedy", "zombie", "action", "historical", "horror", "war" }; public static final int MAX_RATING = 10; public static final int MIN_RATING = 0; /** * Converts a string of...
Complete the implementations of various classes in a Flight
Management, We consider a database that stores information about
passengers and flights. Each passenger
record (e.g., String name, double TicketAmount, int flightID) can
be uniquely identified by a String ID (e.g., ”e1”), whereas each
flight record (e.g., String airline and String flight
for flight name and airline name, respectively ) can be uniquely
identified by an integer id. You must implement all methods in the
FlightManagementSystem by manipulating the
two attributes...
complete this in java import java.io.File; import java.io.FileNotFoundException; import java.util.ArrayList; import java.util.Random; import java.util.Scanner; public class WordDetective { /** * Finds the specified set of words in the specified file and returns them * as an ArrayList. This finds the specified set in the file which is on the * line number of the set. The first line and set in the file is 1. * * This returns an ArrayList with the keyword first, then : and then followed...
Course.java
import java.io.Serializable;
/**
* Represents a course that might be taken by a student.
*
*/
public class Course implements Serializable
{
private String prefix;
private int number;
private String title;
private String grade;
/**
* Constructs the course with the specified information.
*
* @param prefix the prefix of the course designation
* @param number the number of the course designation
* @param title the title of the course
* @param grade the grade received for the course...
Complete this in java import java.io.File; import java.io.FileNotFoundException; import java.util.ArrayList; import java.util.Random; import java.util.Scanner; public class WordDetective { /** * This returns a string containing the char ch, count times. * For example calling with 'a', 5 would return: * "aaaaa" * * @param ch The character to repeat. * @param count The number of the character. * @return A string with count number of ch. */ public static String charToString(char ch, int count) { return null; //TODO }
// can someone explain the code line by line shortly.thanks import java.security.KeyPair; import java.security.KeyPairGenerator; import java.security.PrivateKey; import java.security.PublicKey; import java.util.Base64; import java.util.HashMap; import java.util.Map; import javax.crypto.Cipher; // Java 8 example for RSA encryption/decryption. // Uses strong encryption with 2048 key size. public class GlobalMembers { public static void main(String[] args) throws Exception { String plainText = "Hello World!"; // Generate public and private keys using RSA Map<String, Object> keys = getRSAKeys(); PrivateKey privateKey = (PrivateKey) keys.get("private"); PublicKey publicKey = (PublicKey)...
CS HELP Use sets to solve this problem package log; import java.io.IOException; import java.io.Reader; import java.util.ArrayList; import java.util.List; import java.util.Scanner; public class LogParser { /** * Returns a list of SuspectEntries corresponding to the CSV data supplied by the given Reader. * * The data contains one or more lines of the format: * * Marc,413-545-3061,1234567890 * * representing a name, phone number, and passport number. * * @param r an open Reader object * @return a list of SuspectEntries...