events;public Reservations() {this.events = new LinkedList ();// adds the given event to the events list, as long as there is no// date/time conflict with existing events in the list.// returns...


The owner of a venue for events needs software to keep track of reservations. The venue can handle<br>two events in a day, one scheduled for the afternoon and another scheduled for the evening. Each<br>event consists of the type (wedding, bar mitzvah, etc.), the date of the event, and whether or not the<br>event will be held in the evening. A programmer writes the code given on the handout.<br>import java.util.LinkedList;<br>class Event {<br>// wedding, etc.<br>String type;<br>Date date;<br>boolean isEvening;<br>// true if the event is to be held in the evening<br>public Event(string type, Date date, boolean isEvening) {<br>this.type - type;<br>this.date = date;<br>this.isEvening = isEvening;<br>}<br>class Date {<br>string month;<br>int day;<br>int year;<br>public Date(string month, int day, int year) {<br>this.month = month;<br>this.day = day;<br>this.year = year;<br>class Reservations {<br>LinkedList<Event> events;<br>public Reservations() {<br>this.events = new LinkedList<Event>();<br>// adds the given event to the events list, as long as there is no<br>// date/time conflict with existing events in the list.<br>// returns true if the event was added, false otherwise<br>boolean bookEvent (Event newEvent) {<br>if (events.size() == 0) {<br>events.add(newEvent);<br>return true;<br>}<br>else {<br>// no other events, so no conflicts<br>for (Event e: this.events) {<br>if (hasconflict(newEvent, e))<br>return false;<br>/i conflict found, event not added<br>}<br>events.add(newEvent);<br>return true;<br>// no conflicts, so add event<br>// returns true if a conflict<br>boolean hasconflict (Event e1, Event e2){<br>return datesame(e1.date, e2.date) && e1.isEvening = e2.isEvening;<br>}<br>// returns true if both dates are the same<br>boolean datesame (Date di, Date d2) {<br>return d1.month.equals (d2. month) && d1.day == d2.day && d1.year == d2.year;<br>}<br>}<br>

Extracted text: The owner of a venue for events needs software to keep track of reservations. The venue can handle two events in a day, one scheduled for the afternoon and another scheduled for the evening. Each event consists of the type (wedding, bar mitzvah, etc.), the date of the event, and whether or not the event will be held in the evening. A programmer writes the code given on the handout. import java.util.LinkedList; class Event { // wedding, etc. String type; Date date; boolean isEvening; // true if the event is to be held in the evening public Event(string type, Date date, boolean isEvening) { this.type - type; this.date = date; this.isEvening = isEvening; } class Date { string month; int day; int year; public Date(string month, int day, int year) { this.month = month; this.day = day; this.year = year; class Reservations { LinkedList events; public Reservations() { this.events = new LinkedList(); // adds the given event to the events list, as long as there is no // date/time conflict with existing events in the list. // returns true if the event was added, false otherwise boolean bookEvent (Event newEvent) { if (events.size() == 0) { events.add(newEvent); return true; } else { // no other events, so no conflicts for (Event e: this.events) { if (hasconflict(newEvent, e)) return false; /i conflict found, event not added } events.add(newEvent); return true; // no conflicts, so add event // returns true if a conflict boolean hasconflict (Event e1, Event e2){ return datesame(e1.date, e2.date) && e1.isEvening = e2.isEvening; } // returns true if both dates are the same boolean datesame (Date di, Date d2) { return d1.month.equals (d2. month) && d1.day == d2.day && d1.year == d2.year; } }
Rewrite the above code so that<br>• It has all of the correct access modifiers for good encapsulation.<br>• Your code obeys the principle of encapsulation that obliges you to put each method in the proper<br>class.<br>• Your code uses NO getters and NO additional classes or methods. You are welcome to modify<br>any existing methods (including signatures and bodies) and/or move them between the existing<br>classes.<br>• Your code DOES NOT modify any of the constructors.<br>Important notes:<br>• You DO NOT have to write a main method.<br>• You DO NOT have to write tests.<br>• You DO NOT have to write Javadocs.<br>• You DO NOT have to write interfaces to encapsulate data structures.<br>• There should be no incorrect syntax or other compile-time errors.<br>

Extracted text: Rewrite the above code so that • It has all of the correct access modifiers for good encapsulation. • Your code obeys the principle of encapsulation that obliges you to put each method in the proper class. • Your code uses NO getters and NO additional classes or methods. You are welcome to modify any existing methods (including signatures and bodies) and/or move them between the existing classes. • Your code DOES NOT modify any of the constructors. Important notes: • You DO NOT have to write a main method. • You DO NOT have to write tests. • You DO NOT have to write Javadocs. • You DO NOT have to write interfaces to encapsulate data structures. • There should be no incorrect syntax or other compile-time errors.
Jun 08, 2022
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here