
How do I make the Java code output?
//import java.util.Arrays;
public class Movie {
private String movieName;
private int numMinutes;
private boolean isKidFriendly;
private int numCastMembers;
private String[] castMembers;
// default constructor
public Movie() {
this.movieName = "Flick";
this.numMinutes = 0;
this.isKidFriendly = false;
this.numCastMembers = 0;
this.castMembers = new String[10];
}
// overloaded parameterized constructor
public Movie(String movieName, int numMinutes, boolean isKidFriendly, String[] castMembers) {
this.movieName = movieName;
this.numMinutes = numMinutes;
this.isKidFriendly = isKidFriendly;
//numCastMember is set to array length
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();
}
//Setter methods
public void setMovieName(String movieName) {
this.movieName = movieName;
}
public void setNumMinutes(int numMinutes) {
this.numMinutes = numMinutes;
}
public void setIsKidFriendly(boolean isKidFriendly) {
this.isKidFriendly = isKidFriendly;
}
// set the number of minutes
//replace cast memeber at index with new cast memeber
//return false if index in invalid
//else return true;
//replace cast memeber at index with new cast memeber
//return false if index in invalid
//else return true;
public boolean replaceCastMember(int index, String castMemberName) {
if (index < 0 || index >= numCastMembers)
return false;
castMembers[index] = castMemberName;
return true;
} /*alterante method if index is starting from 1
public boolean replaceCastMember(int index, String castMemberName) {
if (index < 1 || index > numCastMembers)
return false;
castMembers[index-1] = castMemberName;
return true;
} */
//compare two arrays
//return true if thery are same else return false
public boolean doArraysMatch(String[] arr1, String[] arr2) {
if (arr1 == null && arr2 == null)
return true;
else if(arr1==null || arr2==null)
return false;
if (arr1.length == arr2.length) {
for (int i = 0; i < arr1.length; i++) {
//to ignore case compare lowercase version of both stirng
if (arr1[i].toLowerCase().equals(arr2[i].toLowerCase()) == false)
return false;
}
return true;
}
return false;
}
//return comma separated name of castmembers
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= "is kid friendly";
else
friendly="not kid freindly";
String minute=String.format("%03d",getNumMinutes());
return "Movie:"+ " [ Minutes "+minute+" "+ "| Movie Name: "+getMovieName()+" "+ "| "+friendly+" "+ "| Number of Cast Members: "+getNumCastMembers()+" "+ "| "
+ "Cast Members: "+getCastMemberNamesAsString()+" "+ "]";
//return "Movie["+ "movieName ="+movieName + ",numMinutes ="+numMinutes + ",isKidfreindly ="+isKidFriendly + "numCastMembers ="+getCastMemberNamesAsString() +
//",castMembers ="+castMembers+ "]";
}
//"Movie: [ Minutes 142 | Movie Name: The Shawshank Redemption | not kid friendly | Number of Cast Members: 3 | Cast Members: Tim Robbins, Morgan Freeman, Bob Gunton ] }
//compare two movie object
//return true if every member variable matches else return false
public boolean equals(Object o){
// Movie m=(Movie)o;
//return movieName.equals(m.getMovieName())
// && numMinutes==m.getNumMinutes()
// && doArraysMatch(castMembers, m.getCastMembers());
if(o instanceof Movie){
Movie other = (Movie) o;
if(movieName.equals(other.movieName)){
if(numMinutes == other.numMinutes){
if(isKidFriendly == other.isKidFriendly){
if(doArraysMatch(castMembers,other.castMembers)){
return true;
}
}
}
}
}
return false;
}
//main function to test the code
//uncomment to use it.
public static void main(String[] args){
Movie m1=new Movie();
System.out.println(m1);
String[] cast=new String[]{"Tim Robbins","Morgan Freeman", "Bob Gunton"};
Movie m2=new Movie("The Shawshank Redemption",142,false,cast);
System.out.println(m2);
System.out.println("m1==m2 =: "+m2.equals(m1));
}
}


Trending nowThis is a popular solution!
Step by stepSolved in 2 steps with 1 images

- PROBLEM STATEMENT: An anagram is a word that has been rearranged from another word, check tosee if the second word is a rearrangement of the first word. public class AnagramComputation{public static boolean solution(String word1, String word2){// ↓↓↓↓ your code goes here ↓↓↓↓return true;}} Can you help me with this java question the language is java please use the code I gavearrow_forward... in javaarrow_forwardLab 9 C balance the same, y, n, why? class CheckingAct { . . . . private int balance; public void processCheck( int amount ) { int charge; if ( balance < 100000 ) charge = 15; else charge = 0; balance = balance - amount - charge ; // change the local copy of the value in "amount" amount = 0 ; } } public class CheckingTester { public static void main ( String[] args ) { CheckingAct act; int check = 5000; act = new CheckingAct( "123-345-99", "Your Name", 100000 ); System.out.println( "check:" + check ); // prints "5000" // call processCheck with a copy of the value 5000 act.processCheck( check ); System.out.println( "check:" + check ); // prints "5000" --- "check" was not changed } }arrow_forward
- 1 a. is the amount the same, yes or no, why? public class CheckingAct { private String actNum; private String nameOnAct; private int balance; . . . . public void processDeposit( int amount ) { balance = balance + amount ; } // modified toString() method public String toString() { return "Account: " + actNum + "\tName: " + nameOnAct + "\tBalance: " + amount ; } } b. public class CheckingAct { private String actNum; private String nameOnAct; private int balance; . . . . public void processDeposit( int amount ) { // scope of amount starts here balance = balance + amount ; // scope of amount ends here } public void processCheck( int amount ) { // scope of amount starts here int charge; incrementUse(); if ( balance < 100000 ) charge = 15; else charge = 0; balance = balance - amount - charge ; // scope of amount ends here } } c. is the…arrow_forwardStatement that increases numPeople by 5. Ex: If numPeople is initially 10, the output is: There are 15 people.arrow_forwardQ1. amount the same, y, n, why? public class CheckingAct { private String actNum; private String nameOnAct; private int balance; . . . . public void processDeposit( int amount ) { balance = balance + amount ; } // modified toString() method public String toString() { return "Account: " + actNum + "\tName: " + nameOnAct + "\tBalance: " + amount ; } } Q2. amount the same, y, n, why? public class CheckingAct { private String actNum; private String nameOnAct; private int balance; . . . . public void processDeposit( int amount ) { // scope of amount starts here balance = balance + amount ; // scope of amount ends here } public void processCheck( int amount ) { // scope of amount starts here int charge; incrementUse(); if ( balance < 100000 ) charge = 15; else charge = 0; balance = balance - amount - charge ; // scope of amount ends here }…arrow_forward
- public class KnowledgeCheckTrek { public static final String TNG = "The Next Generation"; public static final String DS9 = "Deep Space Nine"; public static final String VOYAGER = "Voyager"; public static String trek(String character) { if (character != null && (character.equalsIgnoreCase("Picard") || character.equalsIgnoreCase("Data"))) { // IF ONE return TNG; } else if (character != null && character.contains("7")) { // IF TWO return VOYAGER; } else if ((character.contains("Quark") || character.contains("Odo"))) { // IF THREE return DS9; } return null; } public static void main(String[] args) { System.out.println(trek("Captain Picard")); System.out.println(trek("7 of Nine")); System.out.println(trek("Odo")); System.out.println(trek("Quark")); System.out.println(trek("Data").equalsIgnoreCase(TNG));…arrow_forwardC++ programmingarrow_forwardHow do I fix the Java code errors? Code: //import java.util.Arrays;//Movie.java package movie; 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() {…arrow_forward
- 1. Insert the missing part of the code below to output the string. public class MyClass { public static void main(String[] args) { ("Hello, I am a Computer Engineer");arrow_forwardPublic classTestMain { public static void main(String [ ] args) { Car myCar1, myCar2; Electric Car myElec1, myElec2; myCar1 = new Car( ); myCar2 = new Car("Ford", 1200, "Green"); myElec1 = new ElectricCar( ); myElec2 = new ElectricCar(15); } }arrow_forwardHow do I fix the errors? Code: import java.util.Scanner;public class ReceiptMaker { public static final String SENTINEL = "checkout";public final int MAX_NUM_ITEMS;public final double TAX_RATE;private String[] itemNames;private double[] itemPrices;private int numItemsPurchased; public ReceiptMaker() {MAX_NUM_ITEMS = 10;TAX_RATE = 0.0875;itemNames = new String[MAX_NUM_ITEMS];itemPrices = new double[MAX_NUM_ITEMS];numItemsPurchased = 0;}public ReceiptMaker(int maxNumItems, double taxRate) {MAX_NUM_ITEMS = maxNumItems;TAX_RATE = taxRate;itemNames = new String[MAX_NUM_ITEMS];itemPrices = new double[MAX_NUM_ITEMS];numItemsPurchased = 0;} public void greetUser() {System.out.println("Welcome to the " + MAX_NUM_ITEMS + " items or less checkout line");}public void promptUserForProductEntry() {System.out.println("Enter item #" + (numItemsPurchased + 1) + "'s name and price separated by a space, or enter \"checkout\" to end transaction early");}public void addNextPurchaseItemFromUser(String…arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education





