Database System Concepts
Database System Concepts
7th Edition
ISBN: 9780078022159
Author: Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher: McGraw-Hill Education
Bartleby Related Questions Icon

Related questions

bartleby

Concept explainers

Question

How do I fix the errored outputs Java?

Code:

//import java.util.Arrays;
//Movie.java
public class Movie {
private String movieName;

private int numMinutes;

private boolean isKidFriendly;

private int numCastMembers;

private String[] castMembers;

public Movie() {

movieName = "Flick";

numMinutes = 0;

isKidFriendly = false;

numCastMembers = 0;

castMembers = new String[10];

}

public Movie(String movieName, int numMinutes, boolean isKidFriendly, String[] castMembers) {

this.movieName = movieName;

this.numMinutes = numMinutes;

this.isKidFriendly = isKidFriendly;

this.numCastMembers = castMembers.length;

this.castMembers = castMembers;

}

public String getMovieName() {

return this.movieName;

}

public int getNumMinutes() {

return this.numMinutes;

}

public boolean getIsKidFriendly() {

return this.isKidFriendly;

}

public boolean isKidFriendly() {

return this.isKidFriendly;

}

public int getNumCastMembers() {

return this.numCastMembers;

}

public String[] getCastMembers() {

return this.castMembers.clone();

}

public void setMovieName(String movieName) {

this.movieName = movieName;

}

public void setNumMinutes(int numMinutes) {

this.numMinutes = numMinutes;

}

public void setIsKidFriendly(boolean isKidFriendly) {

this.isKidFriendly = isKidFriendly;

}

public boolean replaceCastMember(int index, String castMemberName) {

if (index < 0 || index > numCastMembers) {
return false;
}

castMembers[index] = castMemberName;

return true;

}

public boolean doArraysMatch(String[] arr1, String[] arr2) {

if (arr1 == null && arr2 == null) {
return true;
}

if (arr1.length == arr2.length) {

for (int i = 0; i < arr1.length; i++) {

if (arr1[i] != null && arr2[i] != null) {
if (! arr1[i].toLowerCase().equals(arr2[i].toLowerCase())) {
return false;
}
}

}

return true;

}

return false;

}

public String getCastMemberNamesAsString() {

if (numCastMembers == 0) {
return "none";
}

String names = castMembers[0];

for (int i = 1; i < numCastMembers; i++) {

names += ", " + castMembers[i];

}

return names;

}

public String toString() {

String friendly;

if (isKidFriendly()) {
friendly = "kid friendly";
} else {
friendly = "not kid freindly";
}

return "Movie:" + " [ Minutes " + getNumMinutes() + " " + "| Movie Name: " + getMovieName() + " " + "| "
+ friendly + " " + "| Number of Cast Members: " + getNumCastMembers() + " " + "| Cast Members: "
+ getCastMemberNamesAsString() + " " + "]";

}

public boolean equals(Object o) {

Movie m = (Movie) o;

return movieName.equals(m.getMovieName()) && numMinutes == m.getNumMinutes()
&& doArraysMatch(castMembers, m.getCastMembers());

}

public static void main(String[] args) {
Movie movie = new Movie("The Shawshank Redemption", 142, false,
new String[] { "Tim Robbins", "Morgan Freeman", "Bob Gunton" });
Movie movie1 = new Movie(" Aladin", 90, true,
new String[] { "Scott Weigner", "Robin Williams", "Linda Larkin", "Jonathan Freeman" });

String[] castMembers = new String[] { "Tim Robbins", "Morgan Freeman", "Bob Gunton" };

System.out.println(movie.toString());
System.out.println(movie1.toString());

System.out.println("\ncast members are same : "+movie.doArraysMatch(movie.castMembers, castMembers));

System.out.println("\nCast Members of movie 1 "+movie1.getCastMemberNamesAsString());

}

}

Errors:

1. Error ---------- Exception occurred while calling Movie.doArraysMatch(String[] arr1, String[] arr2)

2. Error ---------- Movie.toString() returns:

Movie: [ Minutes 142 | Movie Name: The Shawshank Redemption | not kid freindly | Number of Cast Members: 3 | Cast Members: Tim Robins, Morgan Freeman, Bob Guton ]

instead of:

Movie: [ Minutes 142 | Movie Name: The Shawshank Redemption | not kid friendly | Number of Cast Members: 3 | Cast Members: Tim Robins, Morgan Freeman, Bob Guton ]

3. Error ---------- Exception occurred while calling Movie.equals()

4. FAILED ---- numCastMembers expected: 0

FAILED Overloaded Constructor test

5. java.lang.ArrayIndexOutOfBoundsException: Index 10 out of bounds for length 10

OK --- method replaceCastMember exists, will test functionality now

Expert Solution
Check Mark
Knowledge Booster
Background pattern image
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
    SEE MORE QUESTIONS
    Recommended textbooks for you
    Text book image
    Database System Concepts
    Computer Science
    ISBN:9780078022159
    Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
    Publisher:McGraw-Hill Education
    Text book image
    Starting Out with Python (4th Edition)
    Computer Science
    ISBN:9780134444321
    Author:Tony Gaddis
    Publisher:PEARSON
    Text book image
    Digital Fundamentals (11th Edition)
    Computer Science
    ISBN:9780132737968
    Author:Thomas L. Floyd
    Publisher:PEARSON
    Text book image
    C How to Program (8th Edition)
    Computer Science
    ISBN:9780133976892
    Author:Paul J. Deitel, Harvey Deitel
    Publisher:PEARSON
    Text book image
    Database Systems: Design, Implementation, & Manag...
    Computer Science
    ISBN:9781337627900
    Author:Carlos Coronel, Steven Morris
    Publisher:Cengage Learning
    Text book image
    Programmable Logic Controllers
    Computer Science
    ISBN:9780073373843
    Author:Frank D. Petruzella
    Publisher:McGraw-Hill Education