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 Movie’s 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 Movie’s script at the position passed in, if there are not at least pos scenes in the movie return and don’t do anything
EX: If i try to addScene(“asdf”,8) but there are only 3 scenes in the movie return nothing and don’t 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 Movie’s script, and returns the removed object. If there are no Scenes in the script then don’t do anything and return null
public Scene removeScene(int pos) - A method that removes the Scene at the passed in position from the Movie’s script, and returns the removed object.
If there is not a Scene at pos then don’t 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 Scene’s 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”
Below is your code
public class Scene {
private String event;
private Scene nextScene;
public Scene(String event) {
this.event = event;
this.nextScene=null;
}
public Scene(String event, Scene nextScene) {
this.event = event;
this.nextScene = nextScene;
}
public Scene getNextScene() {
return nextScene;
}
public void setNextScene(Scene nextScene) {
this.nextScene = nextScene;
}
public String getEvent() {
return event;
}
}
import java.util.LinkedList;
public class Movie {
public LinkedList<Scene> script=new
LinkedList<Scene>();
public Movie() {
}
public void addScene(String event) {
Scene sc=new Scene(event);
script.add(sc);
}
public void addScene(String event, int pos) {
if(script.size()>pos) {
Scene sc=new
Scene(event);
script.add(pos,
sc);
}
}
public Scene removeScene() {
if(script.size()>=1) {
return
script.remove(script.size()-1);
}
return null;
}
public Scene removeScene(int pos) {
if(script.size()>pos) {
return
script.remove(pos);
}
return null;
}
public String toString() {
String retstr="";
int i=0;
for(Scene s:script) {
retstr=retstr+"\""+s.getEvent()+"\"";
i++;
if(script.size()!=i) {
retstr=retstr+",
";
}
}
return retstr;
}
}
public class MovieSceneDriver {
public static void main(String[] args) {
Movie m=new Movie();
m.addScene("Introduction");
m.addScene("Magic Man");
m.addScene("Betrayal");
m.addScene("Climax");
m.addScene("Evil Defeated");
m.addScene("Conclusion");
System.out.println(m.toString());
m.removeScene();
System.out.println(m.toString());
m.addScene("Sequel");
System.out.println(m.toString());
m.removeScene(4);
System.out.println(m.toString());
m.addScene("Prequel", 0);
System.out.println(m.toString());
}
}
Needs Help with Java Programming language! Lights Camera Action Purpose: To learn the basics of linked...
Please please help me with this code please Purpose: To learn the basics of linked lists You are to implement 2 classes, Scene and Movie. Note: Please dont use inbuild linkedList methods and functions The Scene class has the following fields and methods: p rivate 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...
Needs Help In Java Programming language Exceptional Cars Purpose To review interfaces and exception usage. Directions Your task is to write a class called Car. Your class should have the following fields and methods: private int position private boolean headlightsOn public Car() - a constructor which initializes position to 0 and headlightsOn to false public Car(int position) - a constructor which initializes position to the passed in value and headlightsOn to false, and it should throw a NegativeNumberException with a...
I need help writing my main method**** Computer Science 111 Introduction to Algorithms and Programming: Java Programming Project #4 – Classes and Objects (20 Points) You will create 3 new classes for this project, two will be chosen from the list below and one will be an entirely new class you invent.Here is the list: Shirt Shoe Wine Book Song Bicycle VideoGame Plant Car FootBall Boat Computer WebSite Movie Beer Pants TVShow MotorCycle Design First Create three (3) UML diagrams...
Needs Help with Java programming language For this assignment, you need to write a simulation program to determine the average waiting time at a grocery store checkout while varying the number of customers and the number of checkout lanes. Classes needed: SortedLinked List: Implement a generic sorted singly-linked list which contains all of the elements included in the unsorted linked list developed in class, but modifies it in the following way: • delete the addfirst, addlast, and add(index) methods and...