How do I make the code output Java? import java.util.Arrays;
How do I make the code output Java?
import java.util.Arrays;
public class Movie {
String movieName;
int numMinutes;
boolean isKidFriendly;
int numCastMembers;
String castMembers[] = new String[10];
// Non-parameterized constructor
public Movie() {
this.movieName = "Flick";
this.numMinutes = 0;
this.isKidFriendly = false;
this.numCastMembers = 0;
}
// Parameterized constructor
public Movie(String movieName, int numMinutes, boolean isKidFriendly, int numCastMembers, String[] castMembers) {
this.movieName = movieName;
this.numMinutes = numMinutes;
this.isKidFriendly = isKidFriendly;
this.numCastMembers = numCastMembers;
this.castMembers = castMembers;
}
// getter and setters
public String getMovieName() {
return movieName;
}
public void setMovieName(String movieName) {
this.movieName = movieName;
}
public int getNumMinutes() {
return numMinutes;
}
public void setNumMinutes(int numMinutes) {
this.numMinutes = numMinutes;
}
public boolean isKidFriendly() {
return isKidFriendly;
}
public void setKidFriendly(boolean isKidFriendly) {
this.isKidFriendly = isKidFriendly;
}
public int getNumCastMembers() {
return numCastMembers;
}
public void setNumCastMembers(int numCastMembers) {
this.numCastMembers = numCastMembers;
}
public String[] getCastMembers() {
return castMembers;
}
public void setCastMembers(String[] castMembers) {
this.castMembers = castMembers;
}
public String toString() {
return "Movie name: "+movieName+"\n Num Minutes: "+numMinutes+"\nIs Kid Friendly: "+isKidFriendly+"\nNum cast memebers: "+numCastMembers+"\nCast Members: "+Arrays.toString(castMembers);
}
//Main funtion
public static void main(String args[]) {
//Printing default values
System.out.println("-----------------------Default values------------------------");
Movie m = new Movie();
System.out.println(m);
//printing setter new value
String castMembers[] = {"Ram", "Charan", "Swami","Ganesh","Namita","Babita","Anunay","Shikhar","Dravin","peter"};
Movie movie = new Movie("Avengers End game", 150, true, 25, castMembers);
System.out.println("------------------------New setter values------------------");
System.out.println(movie);
}
}
Step by step
Solved in 2 steps with 1 images