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

please help! 3.1 The Play Class The changes would be as follows. 1. You need to

ID: 3743764 • Letter: P

Question

please help!

3.1 The Play Class The changes would be as follows. 1. You need to add two constructors, like in Event. 2. As tickets are sold, the price factor is adjusted automatically. If it is found that 60% of the tickets have been sold, the price factor is increased by a factor of 1.2. This new price factor applies until it is observed that 80% of the tickets have been sold. Then the price factor is increased once more by a factor of 1.2. For example, assume that the capacity is 100 and that the price factor is 1.0 initially. Let us assume that this was not changed for the first 60 tickets. (Remember the setPriceFactor method, which could be used to change price factor.) When a ticket is requested now (that is, after 60 tickets have been sold), the price factor is increased to 1.2 × 1.0, that is 1.2. This price factor applies for tickets 61 through 80. After 80 tickets have been sold, if a new ticket is to be sold, one more hike is made to the price factor when selling the 81st ticket. The price factor is now 1.2 × 1.2, which is 1.44. Of course, a client could override the above by manually changing the price factor. 3 Note that price factor is automatically adjusted exactly once after 60 percent of tickets have been sold until but not including 81 percent. Similarly, price factor is automatically adjusted exactly once after 80 percent of tickets have been sold. 3. When the toString method is invoked, it must return the string with the word Play 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.


public class Play extends Event {

/**
* Creates a Play object with the description and price factor.
*
* @param description
* the description of the play
* @param priceFactor
* the price factor for the play
*/

// TODO Create a constructor

/**
* Creates a play with the given description and a price factor of 1.0.
*
* @param description
* the description of the play
*/

// TODO Create a constructor

/**
* Returns a String representation.
*
*/
@Override
public String toString() {
return "Play " + /* TODO */;
}
}

import java.util.StringTokenizer;

public class PlayTester {
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 testConstructorAndGetters(int score) {
Play play1 = null;
Play play2 = null;
try {
play1 = new Play("p1", 2.0);
play2 = new Play("p2");
score += 2;
} catch (Exception e) {
System.out.println("constructor...issues");
}

try {
score = assertd(play1.getDescription().equals("p1"), score, 1);
} catch (Exception e) {
System.out.println("constructor...issues");
}

try {
score = assertd(play1.getEventId() == 1, score, 1);
score = assertd(play2.getEventId() == 2, score, 1);
} catch (Exception e) {
System.out.println("constructor...issues");
}

try {
score = assertd(play1.getPriceFactor() == 2.0, score, 1);
play2.setPriceFactor(3.0);
play2.setDescription("play2");
score = assertd(play2.getPriceFactor() == 3.0, score, 1);
score = assertd(play2.getDescription().equals("play2"), score, 1);
} catch (Exception e) {
System.out.println("constructor...issues");
}

return score;
}

public int testToString(int score) {
double value = 0.0;
try {
Play play1 = null;
Play play2 = null;
try {
play1 = new Play("p1", 2.0);
play2 = new Play("p2");
score += 1;
} catch (Exception e) {
}
String string = play1.toString();
System.out.println(string);
StringTokenizer tokenizer = new StringTokenizer(string);
String token = tokenizer.nextToken();
if (token.equals("Event")) {
value = value + 0.25;
}
System.out.println(token + " " + value);

token = tokenizer.nextToken();
if (token.equals("3")) {
value = value + 0.25;
}
System.out.println(token + " " + value);
token = tokenizer.nextToken();
if (token.equals("p1")) {
value = value + 0.25;
}
System.out.println(token + " " + value);

} catch (Exception e) {
System.out.println("string issues");
}
// System.out.println("Value " + value);
score = score + Math.round((float) value);
return score;
}

public int testEquals(int score) {
try {
Play play1 = new Play("p1");
Play play2 = new Play("p2");
score = assertd(!play1.equals(play2), score, 1);
score = assertd(play1.equals(play1), score, 1);
} catch (Exception e) {
}
return score;
}

public int testAddTickets(int score) {
try {
Play play1 = new Play("p1");
Ticket[] tickets = new Ticket[5];
for (int index = 0; index < tickets.length; index++) {
tickets[index] = new Ticket(play1);
}
score = score + 3;
Ticket[] retrievedTickets = play1.getTickets();
for (int index = 0; index < retrievedTickets.length; index++) {
assert (retrievedTickets[index].equals(tickets[index]));
}
Ticket tExtra = null;
try {
tExtra = new Ticket(play1);

} catch (Exception e) {
System.out.println("couldn't add");
retrievedTickets = play1.getTickets();
for (int index = 0; index < retrievedTickets.length; index++) {
assert (!retrievedTickets[index].equals(tExtra));
}
score += 2;
}
} catch (Exception e) {
System.out.println("issues " + e);
}

return score;
}

public static void main(String[] args) {
int score = 0;
PlayTester test = new PlayTester();
score = test.testConstructorAndGetters(score);
score = test.testToString(score);
score = test.testEquals(score);
score = test.testAddTickets(score);
System.out.println(score + " out of 17");
}
}

Explanation / Answer

In order to provide a more precise solution, you would need to provide me the implementation of class Event. Once you do so, I can provide you a more correct definition of class Play.

But for time being, here is a sample implementation of class Play.

Play.java

************************

public class Play extends Event{

   /**

   * Creates a Play object with the description and price factor.

   *

   * @param description

   * the description of the play

   * @param priceFactor

   * the price factor for the play

   */

   // TODO Create a constructor

   public Play(String description, double priceFactor) {

       super(description, priceFactor);

   }

   /**

   * Creates a play with the given description and a price factor of 1.0.

   *

   * @param description

   * the description of the play

   */

   // TODO Create a constructor

   public Play(String description) {

       super(description, 1.0);

   }

   /**

   * Returns a String representation.

   *

   */

   @Override

   public String toString() {

       return "Play " + super.toString();

   }

}