Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Needs Help with Java Programming language! Lights Camera Action Purpose: To learn the basics of linked lists You are to implement 2 classes, Scene and

Needs Help with Java Programming language!

Lights Camera

Action Purpose: To learn the basics of linked lists

You are to implement 2 classes, Scene and Movie.

The Scene class has the following fields and methods:

private String event

private Scene nextScene

Public Scene(String event) - A constructor that creates a Scene object with the event set and nextScene set to null

Public Scene(String event, Scene next) - A constructor that creates a Scene object with the event and the nextScene fields set

public Scene getNextScene() - returns the nextScene after the current one

public void setNextScene(Scene newScene) - changes the nextScene to the Scene passed in

public String getEvent() - returns the event from the current scene

Your Movie class has the following fields and methods:

public Scene script- that stores a linked list of Scenes

Public Movie() - A Movie constructor which initializes the the script variable to null

public void addScene(String event) - A method that adds a new Scene to the end of the Movies script. If there are no Scenes in the script then the Scene added becomes the first Scene in the movie

public void addScene(String event, int pos) - A method that adds a new Scene to the Movies script at the position passed in, if there are not at least pos scenes in the movie return and dont do anything

EX: If i try to addScene(asdf,8) but there are only 3 scenes in the movie return nothing and dont add the string

Note: The linked list is indexed starting from 0 so we have 0,1,2,3,4...

public Scene removeScene() - A method that removes a Scene from the end of the Movies script, and returns the removed object. If there are no Scenes in the script then dont do anything and return null

public Scene removeScene(int pos) - A method that removes the Scene at the passed in position from the Movies script, and returns the removed object.

If there is not a Scene at pos then dont do anything and return null EX: if I try removeScene(8) but there are only 3 scenes in the movie return null

Note: The linked list is indexed starting from 0 so we have 0,1,2,3,4...

public String toString() - returns a string where each Scenes event is separated by a comma and space. Ex: event1, event2, event3

You also need to create a Driver class with a main method.

In main:

Create a Movie object

Add Scenes until the Movie is:

Introduction,Magic Man,Betrayal,Climax,Evil Defeated,Conclusion

Print out the script of the Movie object using toString()

Remove the Conclusion of the Movie

Print out the script of the Movie object using toString()

Add a scene to the end of the movie called Sequel

Print out the script of the Movie object using toString()

Remove Evil Defeated from the Movie since the sequel retconned it

Print out the script of the Movie object using toString()

Add a Scene called Prequel to the beginning of the Movie

Print out the script of the Movie object using toString()

Example Output:

Introduction,Magic Man,Betrayal,Climax,Evil Defeated,Conclusion

Introduction,Magic Man,Betrayal,Climax,Evil Defeated

Introduction,Magic Man,Betrayal,Climax,Evil Defeated,Sequel

Introduction,Magic Man,Betrayal,Climax,Sequel

Prequel,Introduction,Magic Man,Betrayal,Climax,Sequel

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions