Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

3.3 The Meeting Class The facility is rented out for meetings and this class rep

ID: 3744045 • Letter: 3

Question

3.3 The Meeting Class

The facility is rented out for meetings and this class represents a single meeting.There is a fundamental difference in the way the organization makes money from meetings. The organization does not sell any tickets for such an event.Instead, the tenant (that holds the meeting) is charged a certain fee

1. The class has a single constructor with two parameters: the description (String) and the fee (double).

2. As mentioned earlier, the organization charges a flat fee for a meeting. Selling tickets, adjusting price factor, etc. do not apply to meetings. We will employ a somewhat dirty approach to “disable” methods related to getters and setters and other methods related to these fields. Change the body of the following methods to read as below.

throw new UnsupportedOperationException();

(a) setPriceFactor

(b) getPriceFactor

(c) addTicket

(d) getTickets

For example,

we will have public int getPriceFactor()

{ throw new UnsupportedOperationException("Price factor not "

+ "supported by Meeting"); }

3. The getProceeds method should return the fee for the meeting. (There are no tickets.)

4. When the toString method is invoked, it must return the string with the word Meeting placed in front of the string returned by the toString method of the Event class. A similar comment applies for the other two subclasses of Event as well.

Events

import java.util.Arrays;

/**
* Represents a single event. It stores a description of the play, a unique id,
* and the tickets sold for the play.
*
* @author Brahma Dathan
*
*/
public class Event {
private String description;
public static final int CAPACITY = 5;
protected int ticketsSold;
private int eventId;
private double priceFactor;
private static int counter = 1;
private Ticket[] tickets;

/**
* Stores the description and price factor and assigns a unique id to the
* event. The constructor also allocates the array tickets.
*
* @param description
* a description of this Play
* @param priceFactor
* the price factor for this Play
*
*/
public Event(String description, double priceFactor) {
this.description = description;
this.priceFactor = priceFactor;
this.tickets = new Ticket[CAPACITY];
this.eventId = computeSerialNumber();
}

/**
* Receives the description and stores that and a price factor of 1.0.
* Besides, it assigns a unique id to the event. The constructor also
* allocates the array tickets.
*
* @param description
* a description of this Play
*
*/
public Event(String description) {
this(description, 1.0);
}

/**
* Returns the unique id of the play
*
* @return id of the play
*
*/
public int getEventId() {
return eventId;
}

/**
* Returns the tickets list
*
* @return the tickets list
*/
public Ticket[] getTickets() {
return Arrays.copyOf(tickets, ticketsSold);
}

/**
* Sets the price factor for the event.
*
* @param priceFactor
* the new price factor
*/
public void setPriceFactor(double priceFactor) {
this.priceFactor = priceFactor;
}

/**
* Computes and returns the total proceeds for thos event.
*
* @return total proceeds
*/

public double getProceeds() {
double total = 0;
for (int index = 0; index < ticketsSold; index++) {
total = total + tickets[index].getPrice();
}
return total;
}

/**
* Compares this Play with object. Follows the semantics of the equals
* method in Object.
*
*/
@Override
public boolean equals(Object object) {
if (this == object) {
return true;
}
if (object == null) {
return false;
}
if (getClass() != object.getClass()) {
return false;
}
Event other = (Event) object;
if (eventId != other.eventId)
return false;
return true;
}

/**
* Returns the description of the Play object
*
* @return description
*/
public String getDescription() {
return description;
}

/**
* Returns the price factor
*
* @return price factor
*/
public double getPriceFactor() {
return priceFactor;
}

/**
* Setter for description
*
* @param description
* the new description
*/
public void setDescription(String description) {
this.description = description;
}

/**
* Returns a unique serial number. This is a helper method.
*
* @return serial number
*/
private int computeSerialNumber() {
return counter++;
}

/**
* Adds a ticket to the list of tickets sold for this Play object.
*
* @param ticket
* the Ticket object to be added
* @return true iff the Ticket object could be added.
*/

public boolean addTicket(Ticket ticket) {
if (ticketsSold < CAPACITY) {
tickets[ticketsSold] = ticket;
ticketsSold++;
return true;
}
return false;
}

/**
* Returns a String representation of this Event object
*/
@Override
public String toString() {
String string = eventId + " " + description + " " + priceFactor + " ";
return string;
}

}

Another Events

import java.util.Arrays;

/**
* Collection of all events
*
* @author Brahma Dathan
*
*/
public class Events {
private Event[] events = new Event[10];
private int numberOfEvents;

/**
* Adds an event to the list of events.
*
* @param event
* the new event
*/
public void add(Event event) {
events[numberOfEvents++] = event;
}

/**
* Getter for the events
*
* @return getter
*/
public Event[] getEvents() {
return Arrays.copyOf(events, numberOfEvents);
}

/**
* Computes and returns the total number of tickets sold for the events.
*
* @return number of tickets sold
*/
public double getTotalProceeds() {
double proceeds = 0;
return proceeds;
}

/**
* Generates a String representation of the object
*/
@Override
public String toString() {
return "Events events=" + events;
}
}

Event Tester

public class EventsTester {

public int assertd(boolean condition, int score, int increment) {

int value = 0;

try {

assert (condition);

value = increment;

} catch (Error error) {

}

return score + value;

}

public int testEverything(int score) {

try {

Event play1 = new Play("p1");

Event concert1 = new Concert("c1");

Event meeting1 = new Meeting("m1", 100);

for (int index = 0; index < 5; index++) {

new Ticket(play1);

}

try {

for (int index = 0; index < 5; index++) {

new Ticket(concert1);

}

} catch (NoSpaceException nse) {

score++;

}

Events events = new Events();

events.add(meeting1);

events.add(concert1);

events.add(play1);

score = score + 2;

score = assertd(events.getEvents().length == 3, score, 1);

score = assertd(events.getEvents()[0].equals(meeting1), score, 1);

score = assertd(events.getEvents()[1].equals(concert1), score, 1);

score = assertd(events.getEvents()[2].equals(play1), score, 1);

score = assertd(events.getTotalProceeds() == 110.64, score, 2);

} catch (Exception e) {

}

return score;

}

public static void main(String[] args) {

int score = 0;

EventsTester test = new EventsTester();

score = test.testEverything(score);

System.out.println(score + " out of 8");

}

}

Need Help

Meeting

public class Meeting extends Event {
private double fee;

/**
* Creates a meeting with a given description and fee
*
* @param description
* meeting description
* @param fee
* the fee charged
*/
// TODO CREATE CONSTRUCTOR

/**
* To disable the price factor
*/
@Override
public void setPriceFactor(double priceFactor) {
throw new UnsupportedOperationException("Pricefactor not supported");
}

@Override
public double getProceeds() {
// TODO
}

/**
* Not supported. Throws UnsupportedOperationException.
*
* @return nothing
*/
public double getPriceFactor() {
// TODO
}

/**
* Not supported. Throws UnsupportedOperationException.
*
* @param ticket
* the Ticket object to be added
* @return true iff the Ticket object could be added.
*/
@Override
public boolean addTicket(Ticket ticket) throws UnsupportedOperationException {
// TODO
}

/**
* Get tickets is not supported. Throws UnsupportedOperationException.
*/
@Override
public Ticket[] getTickets() {
// TODO
}

/**
* Returns the fee
*
* @return the fee
*/
public double getFee() {
return fee;
}

/**
* Returns a String representation of this Event object
*/
@Override
public String toString() {
return "Meeting " + super.toString();
}

}

Explanation / Answer

I assume, you were asking implementation of throwing exception as rest of the methods seem to be already implemented. Please feel free to comment (elaborate) if not.

public class Meeting extends Event {

private double fee;

/**

* Creates a meeting with a given description and fee

*

* @param description

* meeting description

* @param fee

* the fee charged

*/

// TODO CREATE CONSTRUCTOR

/**

* To disable the price factor

*/

@Override

public void setPriceFactor(double priceFactor) {

throw new UnsupportedOperationException("Pricefactor not supported");

}

@Override

public double getProceeds() {

return this.fee;

}

/**

* Not supported. Throws UnsupportedOperationException.

*

* @return nothing

*/

public double getPriceFactor() {

throw new UnsupportedOperationException("Price Factor not supported by Meeting");

}

/**

* Not supported. Throws UnsupportedOperationException.

*

* @param ticket

* the Ticket object to be added

* @return true iff the Ticket object could be added.

*/

@Override

public boolean addTicket(Ticket ticket) throws UnsupportedOperationException {

throw new UnsupportedOperationException("Add Ticket not supported by Meeting");

}

/**

* Get tickets is not supported. Throws UnsupportedOperationException.

*/

@Override

public Ticket[] getTickets() {

throw new UnsupportedOperationException("Get Tickets not supported by Meeting");

}

/**

* Returns the fee

*

* @return the fee

*/

public double getFee() {

return fee;

}

/**

* Returns a String representation of this Event object

*/

@Override

public String toString() {

return "Meeting " + super.toString();

}

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote