Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

2. DemoMovie2.java and DemoMovie2.java - Modifications of an earlier assignment a. DemoMovie2.java --- Copy Movie.java from Project 2 into DemoMovie2.java i. Add a static variable

2. DemoMovie2.java and DemoMovie2.java - Modifications of an earlier assignment

a. DemoMovie2.java --- Copy Movie.java from Project 2 into DemoMovie2.java

i. Add a static variable to your class

ii. Add a constructor that receives parameters to your class (if you dont already have one)

iii. Add a toString method to your class that displays the data in your object in a nice format

b. DemoMovie2.java --- Copy DemoMovie.java from Project 2 into DemoMovie2.java

i. Add code to instantiate an additional object using the constructor that receives parameters

ii. Add code to display data from the newly added object by calling the toString method you added in the class.

iii. Demonstrate use of the static variable

Movie.java

public class Movie { //declarations private String title; private String director; private String rating ; private int runtime;

public Movie() { title="TBD"; director="TBD"; rating="NR"; runtime=0; } //Syntax for Movie public Movie(String title, String director, String rating, int runtime) {

this.setTitle(title); this.setDirector(director); this.setRating(rating); this.setRuntime(runtime);

} //Set statements

public void setTitle(String title){ this.title = title; }

public void setDirector(String director){ this.director = director; }

public void setRating(String rating){ if(rating.equals("AO") || rating.equals("R")|| rating.equals("PG13") || rating.equals("PG") || rating.equals("G") || rating.equals("NR")){ this.rating = rating;} else {this.rating = "NR";} }

public void setRuntime(int runtime){ this.runtime = runtime; }

//get methods public String getTitle() {return title;} public String getDirector() {return director;} public String getRating() {return rating;} public int getRuntime() {return runtime;}

}

DemoMovie.java

import java.util.Scanner;

public class DemoMovie { public static void main(String args[]) { //declarations String movieTitle ; String directorName; String movieRating; String again = "Yes"; int movieTime; //first movie (default values) Movie firstMovie=new Movie();

//print firstMovie System.out.println(firstMovie.getTitle()); System.out.println(firstMovie.getDirector()); System.out.println(firstMovie.getRating()); System.out.println(firstMovie.getRuntime());

//Second movie utilizing valid input Movie secondMovie=new Movie("Red Dawn", "John Milius", "R", 114);

//Printing secondMovie System.out.println(secondMovie.getTitle()); System.out.println(secondMovie.getDirector()); System.out.println(secondMovie.getRating()); System.out.println(secondMovie.getRuntime());

//initialize scanner Scanner keyboard = new Scanner(System.in);

//Get information for thirdMovie

System.out.print("Enter Movie Title : "); movieTitle =keyboard.nextLine();

System.out.print("Enter the Director : "); directorName = keyboard.nextLine();

System.out.print("Enter the Movie's Rating : "); movieRating = keyboard.nextLine();

System.out.print("Enter the Runtime : "); movieTime = keyboard.nextInt();

//Create thirdMovie Movie thirdMovie=new Movie(movieTitle, directorName, movieRating, movieTime);

//Print thirdMovie System.out.println(thirdMovie.getTitle()); System.out.println(thirdMovie.getDirector()); System.out.println(thirdMovie.getRating()); System.out.println(thirdMovie.getRuntime());

} }

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_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

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

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

Explain the importance of Human Resource Management

Answered: 1 week ago

Question

Discuss the scope of Human Resource Management

Answered: 1 week ago

Question

Discuss the different types of leadership

Answered: 1 week ago

Question

Write a note on Organisation manuals

Answered: 1 week ago

Question

Define Scientific Management

Answered: 1 week ago