98.3k views
3 votes
Assume that the classes listed in the Java Quick Reference have been imported where appropriate. Unless otherwise noted in the question, assume that parameters in method calls are not null and that methods are called only when their preconditions are satisfied. In writing solutions for each question, you may use any of the accessible methods that are listed in classes defined in that question. Writing significant amounts of code that can be replaced by a call to one of these methods will not receive full credit.

Consider the following class.
public class LightSequence
{
// attributes not shown
/** The parameter seq is the initial sequence used for
* the light display
*/
public LightSequence(String seq)
{ /* implementation not shown */ }
/** Inserts the string segment in the current sequence,
* starting at the index ind. Returns the new sequence.
*/
public String insertSegment(String segment, int ind)
{ /* implementation not shown */ }
/** Updates the sequence to the value in seq
*/
public void changeSequence(String seq)
{ /* implementation not shown */ }
/** Uses the current sequence to turn the light on and off
* for the show
*/
public void display()
{ /* implementation not shown */ }
}

(a) Write a statement to create a LightSequence object gradShow that has the initial light sequence "0101 0101 0101".
Write the statement below.

1 Answer

7 votes

Final answer:

To create a LightSequence object named gradShow with the given sequence, use the constructor with the statement LightSequence gradShow = new LightSequence("0101 0101 0101");

Step-by-step explanation:

To create a LightSequence object named gradShow with the initial light sequence "0101 0101 0101", you would write the following statement in Java:

LightSequence gradShow = new LightSequence("0101 0101 0101");

This statement creates a new instance of the LightSequence class and uses the provided string as the initial sequence for the light display.

User BobMcboberson
by
8.2k points