Please help me with this assignment below. Add Javadoc comments please as it will help me understand the code. r . g :. Bookinglnfo (1).java
Please help me with this assignment below. Add Javadoc comments please as it will help me understand the code.
r . g :. Bookinglnfo (1).java /** * A booking info class with start date, end date, and id. */ import java.text.SimpleDateFormat; import java.util.Date: public class BookingInfo { private String id; private Date start: private Date end; /** * Constructs a booking info. * @param starts the starting date of booking * @param ends the ending date of booking * @param id the id of the booking */ public BookingInfo(Date start, Date end, String id) { this.start = start; this.end = end: this.id = id; } /** * Gets the starting date of the booking * @return the starting date */ public Date getStartDate() { return start; } l** * Gets the ending date of the booking * @return the ending date */ public Date getEndDate() { return end; } /** * Gets the id of this booking * @return the id */ public String getId() { return id; } /** * Returns a string representation of (id, start, end). * @return the string representation of this booking in the format of (id, start, end) */ public String toString() { SimpleDateFormat formatter = new SimpleDateFormat("yxvyMMdd"): return \"(\" + id + ", " + formatter.format(start) + \Task Description Please write a program in Java to sort and search hotel booking information. The public interface of BookingManager is described below, along with a ready-to-use class Bookinglnfo. Please follow the requirements in the description for each method to complete this class. Please also write a tester class to thoroughly test the four methods given in BookingManager. The BookingManager class should contain the following public methods: 1. public ArrayList readBookingslstring pathName) throws IOException: a. Read all the booking information from the binary file in the local file system as specified by the parameter pathName and return an ArrayList of Bookinglnfo. b. We assume that each record in the binary file has a fixed length of 60 bytes, with start date stored in the first 20 bytes, end date in next 20 bytes, and id in the last 20 bytes. (3. We assume that all the dates in the file are in the format of YYYY-MM-DD. There could be an arbitrary number of records in the file. 2, public ArrayList sortBookings(ArrayList inputList): a. Write code that implements the merge sort algorithm to sort all the booking information in inputList by start date in a way that recent info shows first. The method returns the list of sorted bookings. 3. Public ArrayList removeConflictslArrayList inputList): a. Use the sorted list of booking info (inputList) to find if there are pairs of bookings with conflict. Having a conflict means that a booking has a start date before the end date of another booking. Whenever there is a conflict, remove the later one. The method returns a new list of booking info with no conflicts. 4. public void saveBookinglnfo(String pathName, ArrayList sortedList) throws IOException: a. Use RandomAccessFile to save all the ordered booking info from the sortedList to the given pathName on the disk. 5. public ArrayList bookingSearch(String pathName, Date minDate, Date maxDate) throws IOException: 3. Given the date range [minDate, maxDate] (both inclusive) and the pathname of the file that stores the sorted booking info, use binary search to find and return an ArrayList of all the booking info within this date range without loading all the booking info in the le into memory (i.e., do NOT attempt to read all booking info into an array/ArrayList and then perform the search there). If no booking info falls in the date range, the method returns an empty list. As a hint, one way to complete this method is to adapt the binary search algorithm (for arrays) taught in class to the setting of random access files. To retrieve the booking info in a range, you may use binary search to locate within the range the booking info with the given minDate (or if such a booking info does not exist, the first booking info that has a start date that is higher than minDate in the file) and then visit the subsequent records until the date is out of the given range or the end ofthe file is reached. b. Tips: 1.Use RandomAccessFile(}.seek(long pos) to do random access; 2. Use RandomAccessFile().length() to get the size of file (number of bytes). Hints: Here is a sample binary file with 4 records in it (see attached test.bin). Each record has the following format: |***20bytes*** |***20bytes* **|***20bytes***| The first and second 20 bytes are starting date and ending date. The third 20 bytes represent the ID of this booking record. They can be read as strings. For starting and ending dates, the string objects thus obtained can be converted into date objects. Don't try to open the test.bin file in text editors as it is a binary file. The four records in test.bin are: "2001-01-01 2001-01-03 1a2b3d "; "2001-01-05 2001-01-07 2b3d4e "; "2001-01-02 2001-01-06 3deafe "; "2001-02-01 2001-02-04 4fafe1 "; Here is an example of how to convert a string to a date: String sDate1="2001-01-01 "; Date datel = new SimpleDateFormat ("yyyy-MM-dd") . parse (sDate1) ; As for the BookingInfo, consider String sDate1="2001-01-01"; BookingInfo book = new BookingInfo (new SimpleDateFormat ("yyyy-MM- dd") . parse (sDatel) , new SimpleDateFormat ("yyyy-MM-dd") .parse (sDate1) , "asdf1" )
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance