Question: IN JAVA 1. Slide Class Write a fully-documented class named Slide which contains the title (String), the array of bullet points (String[]), and the duration

IN JAVA

1. Slide Class

Write a fully-documented class named Slide which contains the title (String), the array of bullet points (String[]), and the duration of the slide in minutes (double). Each slide should be limited to a maximum of 5 bullet points, which should be reflected in a static constant named MAX_BULLETS. You should provide getter and setter methods for all member variables, with the getter/setter method for bullets taking an additional index parameter (see the provided UML diagram for further detail). In addition, you should provide a constructor as detailed below, though you may create a custom constructor which takes any arguments you see fit. Lastly, you should provide a toString() method that returns a printable representation of the Slide and its data members (title, duration, and bullets).

public static final int MAX_BULLETS = 5

private String title

private String[] bullets

private double duration

public Slide()

Brief:

Default constructor.

Postconditions:

This object has been initialized to an empty Slide (title and all bullets are null, duration = 0.0)

Note:

You may create a custom constructor which takes arguments if you wish.

public String getTitle()

Brief:

Public getter method for the title member variable.

Returns:

The title of the Slide.

public void setTitle(String newTitle)

Brief:

Public setter method for the title member variable.

Parameters: newTitle

The new title of this slide. This parameter should not be null

Preconditions:

newTitle is not null.

Throws: IllegalArgumentException

Thrown if newTitle is null.

public double getDuration()

Brief:

Public getter method for the duration member variable.

Returns:

The duration of the Slide.

public void setDuration(double newDuration)

Brief:

Public setter method for the duration member variable.

Parameters: newDuration

The new duration of this slide. This parameter should be greater than 0.

Preconditions:

newDuration is greater than 0.

Throws: IllegalArgumentException

Thrown if newDuration is less than or equal to 0.

public int getNumBullets()

Brief:

Gets the total number of bullet point in the Slide.

Returns:

The number of bullet points in the Slide.

Note:

This method counts the number of non-null elements in the bullets array.

public String getBullet(int i)

Brief:

Gets the bullet point at index i.

Parameters: i

The index to retrieve from the array. This value must be between 1 and MAX_BULLETS, inclusive.

Preconditions:

1 i MAX_BULLETS.

Returns:

The String representing the bullet point at the given index (may be null, meaning there is no bullet point at this index).

Throws: IllegalArgumentException

Thrown if i is not in the valid range.

public void setBullet(String bullet, int i)

Brief:

Sets bullet as the i'th bullet point for bullets. If bullet is null, this method erases the bullet point at index i and pushes all bullet points greater than i back one index (i.e. leaves no holes in the bullets array).

Parameters: bullet

The String to place as the ith bullet point in bullets. This parameter may be null, indicating that the bullet at index i is to be erased from the slide.

i

The index to place bullet in the array. This value must be between 1 and MAX_BULLETS, inclusive.

Preconditions:

1 i MAX_BULLETS.

Postconditions:

The bullet point at index i has been updated to the String bullet.

There are no holes in the bullets array. All bullet points occupy the lowest possible indices of the array.

Throws: IllegalArgumentException

Thrown if i is not in the valid range.

Note:

You may index bullets in this array however you like. If you wish to allocate a String array of size MAX_BULLETS and index starting from 0, this is fine (just remember to subtract 1 from i before setting the bullet point). Conversely, you can also allocate a String array of size MAX_BULLETS + 1 and index from 1, using the 0'th index as a dummy placeholder (you can use i as-is).

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!