Please help with this im not sure how to do this Write code
Please help with this im not sure how to do this
Write code to accomplish the following tasks.
create an array to hold four movie objects
fill the array with objects: two movies and two documentaries
iterate through the array with a loop and print only the topic of any object that is a documentary
Do not use the index of the array to determine whether the object is a documentary
Your code would go in the following class:
public class MovieDocumentaryDriver {
public static void main(String[] args) {
// YOUR CODE HERE
}
}
Solution
MovieInter.java
package org.students;
public interface MovieInter {
void displayInfo();
}
_____________________
DocumentaryInter.java
package org.students;
public interface DocumentaryInter {
void printInfo();
}
_______________
Movie.java
package org.students;
public class Movie implements MovieInter {
//Declaring instance variables
private String name;
private String genre;
private int year_of_release;
//parameterized constructor
public Movie(String name, String genre, int year_of_release) {
super();
this.name = name;
this.genre = genre;
this.year_of_release = year_of_release;
}
//Displaying the movie info
@Override
public void displayInfo() {
System.out.println(\"Movie Name :\"+name);
System.out.println(\"Genere :\"+genre);
System.out.println(\"Year of release :\"+year_of_release);
}
}
________________
Documentary.java
package org.students;
public class Documentary implements DocumentaryInter {
//Declaring variables
private String name;
private int year_of_release;
//Parameterized constructor
public Documentary(String name, int year_of_release) {
super();
this.name = name;
this.year_of_release = year_of_release;
}
//Displaying the info
@Override
public void printInfo() {
System.out.println(\"\ #Documentary\");
System.out.println(\"Name :\"+name);
System.out.println(\"Year of release :\"+year_of_release);
}
}
_____________________
MovieDocumentaryDriver.java
package org.students;
public class MovieDocumentaryDriver {
public static void main(String[] args) {
//Creating an Array of objects which holds Movie and Documentary Objects
Object movies[]={new Movie(\"Passengers\",\"Science Fiction\",2016),
new Movie(\"X-Men\",\"Thriller\",2014),
new Documentary(\"Tickled\", 2016),
new Documentary(\"Gleason\",2016)};
//Iterating over the Object Array
for(Object obj:movies)
{
//If the Object is of type Documentary then display its info
if(obj instanceof Documentary)
{
Documentary d=(Documentary)obj;
//Displaying the information about Documentary Object
d.printInfo();
}
}
}
}
______________________
Output:
#Documentary
Name :Tickled
Year of release :2016
#Documentary
Name :Gleason
Year of release :2016
___________ThankYou


