Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

2. In the class Office HourSchedule, Implement the following methods (documentation for each method is provided in the code). a) printisInOn(String day) b) is AvailableFor(String

image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
2. In the class Office HourSchedule, Implement the following methods (documentation for each method is provided in the code). a) printisInOn(String day) b) is AvailableFor(String instructor, int minutes) 3. Add a method (call it findinstructorsOnAfter) to OfficeHourSchedule that takes two parameters campus and hour -- and returns a String containing the names of all instructors who offer an office hour on given campus that starts not before hour. You should exclude duplicate names (if an instructor offers multiple office hours). The string should start with "Instructors who are available on campus after hour.00 are: Hint: Use filter and map to create a stream with all the (possibly duplicate) names. Add these names to an appropriate collection (you need to decide about the right one - you want to eliminate the duplicates) and then use reduce on the corresponding stream to produce the output. Decide on the correct identity and formulate a two-parameter lambda that combines the running "sum" with the next element of the stream. public boolean isAvailableFor(String instructor, int minutes) 7/ put your code here return true; * Add the office hours recorded in the given filename to the schedule. * @param filename A CSV file of officeHour records. */ private void addofficeHoursFromFile(String filename) { OfficeHour Reader reader = new OfficeHour Reader(): officeHours.addAll(reader.getofficeHours(filename)); } /** * Prints for all office hours the corresponding info */ public void printAllofficeHours { for (OfficeHour officeh: officeHours) { officeh.printInfo(); System.out.printini import java.io.IOException; import java.nio.file.Files; import java.nio.file.Paths; import java.util.ArrayList; import java.util.Optional; import java.util.function. Function; import java.util.stream.Collectors; ** * A class to read CSV-style records of office hours. * */ public class OfficeHour Reader 7/ How many fields are expected. private static final int NUMBER_OF_FIELDS = 8: V Index values for the fields in each record. private static final int INSTRUCTOR = 0. DAY 1. HOUR = 2, MINUTE 3. DURATION = 4, CAMPUS 5. OFFICE 6. COURSE = 7; V** * Create an officeHour Reader. public officeHour Reader() ** * Read office hours in CSV format from the given file. * Return an ArrayList of officeHour objects created from * the information in the file. * @param filename the file to be read - should be in CSV format. * @return A list of officeHour. public ArrayList getofficeHours(String filename) 77 Create an officehour from a CSV input line. Function createofficeHour record - Stringll parts record.split(); if(parta. length - NUMBER_OF_FIELDS) try String instructor parts(INSTRUCTOR).trim(): String day - parts [DAY).trim(): int hour - Integer.parseInt(parts [HOUR).trim()); int minute - Integer.parseInt(parts[MINUTE].trim(): int duration - Integer.parseInt(parts DURATION).trim(): String campus - parts [CAMPUS).trim(); String office - parts[OFFICE).trim(): String course - parts[COURSE).trim(): return new OfficeHour (instructor, day, hour, minute, duration, campus, office, course): 3 catch(Number FormatException e) { System.out.println("office Hour record has a malformed integer : " + record): return null; 3 else { System.out.println("Office Hour has the wrong number of fields: return null; + record): ArrayList officeHour officeHours: try { officehours - Files.lines (Paths.get(filename)) filter (record > record. length() > 0 && record.charAt(0) != '#') map(createofficeHour) .filter(officeHour -> officeHour != null) .collect(Collectors.toCollection(ArrayList:: new)); catch (IOException e) { System.out.println("Unable to open " + filename): officeHours = new ArrayList0: return officeHours: import java.util.Arraylist: * * Write a description of class office our here. * * @author course instructor * @version 2021.02.11 */ public class OfficeHour private String instructor; private String dayOfWeek; private int startTimeHours: private int startTimeMinutes; private int duration InMinutes; private String campus; private String office; private String course: V! Ignore these two declarations private String minutesString: private String hoursString: * Constructor for objects of class officeHour public officeHour (String instructor, String day, int startTimel, int startTimeM, int duration, String campus, String office, String course) ( this. instructor - instructor; dayofWeek = day: startTimeHours = startTimeH; startTimeMinutes = startTimeM; duration InMinutes = duration; this.campus = campus: this.office = office; this.course = course; 1/ignore this part minutesString = startTimeM == 0 ? "00" : + startTimeM; hoursString = startTimeH getofficeHours(String filename) 77 Create an officehour from a CSV input line. Function createofficeHour record - Stringll parts record.split(); if(parta. length - NUMBER_OF_FIELDS) try String instructor parts(INSTRUCTOR).trim(): String day - parts [DAY).trim(): int hour - Integer.parseInt(parts [HOUR).trim()); int minute - Integer.parseInt(parts[MINUTE].trim(): int duration - Integer.parseInt(parts DURATION).trim(): String campus - parts [CAMPUS).trim(); String office - parts[OFFICE).trim(): String course - parts[COURSE).trim(): return new OfficeHour (instructor, day, hour, minute, duration, campus, office, course): 3 catch(Number FormatException e) { System.out.println("office Hour record has a malformed integer : " + record): return null; 3 else { System.out.println("Office Hour has the wrong number of fields: return null; + record): ArrayList officeHour officeHours: try { officehours - Files.lines (Paths.get(filename)) filter (record > record. length() > 0 && record.charAt(0) != '#') map(createofficeHour) .filter(officeHour -> officeHour != null) .collect(Collectors.toCollection(ArrayList:: new)); catch (IOException e) { System.out.println("Unable to open " + filename): officeHours = new ArrayList0: return officeHours: import java.util.Arraylist: * * Write a description of class office our here. * * @author course instructor * @version 2021.02.11 */ public class OfficeHour private String instructor; private String dayOfWeek; private int startTimeHours: private int startTimeMinutes; private int duration InMinutes; private String campus; private String office; private String course: V! Ignore these two declarations private String minutesString: private String hoursString: * Constructor for objects of class officeHour public officeHour (String instructor, String day, int startTimel, int startTimeM, int duration, String campus, String office, String course) ( this. instructor - instructor; dayofWeek = day: startTimeHours = startTimeH; startTimeMinutes = startTimeM; duration InMinutes = duration; this.campus = campus: this.office = office; this.course = course; 1/ignore this part minutesString = startTimeM == 0 ? "00" : + startTimeM; hoursString = startTimeH

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Multidimensional Array Data Management In Databases

Authors: Florin Rusu

1st Edition

1638281483, 978-1638281481

More Books

Students also viewed these Databases questions

Question

EI can be learned. True False

Answered: 1 week ago

Question

To find integral of sin(logx) .

Answered: 1 week ago