
Concept explainers
How should I add a main to the Java code?
import java.util.*;
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;
this.numCastMembers = castMembers.length;
this.castMembers = new String[numCastMembers];
for (int i = 0; i < castMembers.length; i++)
{
this.castMembers[i] = castMembers[i];
}
}
// set the number of minutes
public void setNumMinutes(int numMinutes)
{
this.numMinutes = numMinutes;
}
// set the movie name
public void setMovieName(String movieName)
{
this.movieName = movieName;
}
// set if the movie is kid friendly or not
public void setIsKidFriendly(boolean isKidFriendly)
{
this.isKidFriendly = isKidFriendly;
}
// return the movie name
public String getMovieName()
{
return this.movieName;
}
// return the number of minutes
public int getNumMinutes()
{
return this.numMinutes;
}
// return true if movie is kid friendly else false
public boolean isKidFriendly()
{
return this.isKidFriendly;
}
// return the array of cast members
public String[] getCastMembers()
{
// create a deep copy of the array
String[] copyCastMembers = new String[this.castMembers.length];
// copy the strings from the array to the copy
for (int i = 0; i < this.castMembers.length; i++)
{
copyCastMembers[i] = this.castMembers[i];
}
return copyCastMembers;
}
// return the number of cast members
public int getNumCastMembers()
{
return this.numCastMembers;
}
// method that allows the name of a castMember at an index in the castMembers
// array to be changed
public boolean replaceCastMember(int index, String castMemberName)
{
if (index < 0 || index >= numCastMembers)
return false;
castMembers[index] = castMemberName;
return true;
}
// method that determines the equality of two String arrays and returns a
// boolean, by comparing the value at each index location.
// Return true if all elements of both arrays match, return false if there is
// any mismatch.
public boolean doArraysMatch(String[] arr1, String[] arr2)
{
// both arrays are null
if (arr1 == null && arr2 == null)
return true;
else if (arr1 == null || arr2 == null) // one of the array is null
return false;
else if (arr1.length != arr2.length) // length of arrays do not match
return false;
// length of both arrays are same
// loop over the arrays
for (int i = 0; i < arr1.length; i++)
{
// if ith element are not equal, return false
if (!arr1[i].equalsIgnoreCase(arr2[i]))
return false;
}
return true; // length of arrays are same and each element at respective location are same
}
// method that gets the contents of the array of castMembers as a comma
// separated String.
public String getCastMemberNamesAsString()
{
if (numCastMembers == 0)
{
return "none";
}
String names = castMembers[0];
for (int i = 1; i < numCastMembers; i++)
{
names += ", " + castMembers[i];
}
return names;
}
// return String representation of the movie
public String toString() {
String movie = "Movie: [ Minutes " + numMinutes + " | Movie Name: %15s | ";
if (isKidFriendly)
movie += "is kid friendly | ";
else
movie += "not kid friendly | ";
movie += "Number of Cast Members: " + numCastMembers + " | Cast Members: " + getCastMemberNamesAsString()
+
" ]"; // extra space after ] removed
return String.format(movie, movieName);
}
// returns true if this movie is equal to o
public boolean equals(Object o)
{
// check if o is an instance of Movie
if (o instanceof Movie)
{
Movie other = (Movie) o;
// returns true if all the fields are equal
return ((movieName.equalsIgnoreCase(other.movieName)) && (isKidFriendly == other.isKidFriendly)
&&
(numMinutes == other.numMinutes) && (numCastMembers == other.numCastMembers)
&&
(doArraysMatch(castMembers, other.castMembers)));
}
return false; // movies are not equal or o is not an object of Movie
}
}

Step by stepSolved in 2 steps

- Write a class named IceCreamCup that implements the Customizable interface. The class should have the following private instance variables. Do NOT give any method implementations for this question, but only declare the instance variables. Do NOT initialize the instance variables -- except nCups below. A String variable name describing the ice cream name • A List of Flavor s added to the cup. Name it flist Additionally, define the following static variable: • An int nCups describing the total number of ice cream cups instantiated. Initialize this variablearrow_forward1. 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_forwardHow 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 constructorpublic Movie() {this.movieName = "Flick";this.numMinutes = 0;this.isKidFriendly = false;this.numCastMembers = 0;this.castMembers = new String[10]; }// overloaded parameterized constructorpublic Movie(String movieName, int numMinutes, boolean isKidFriendly, String[] castMembers) {this.movieName = movieName;this.numMinutes = numMinutes;this.isKidFriendly = isKidFriendly;//numCastMember is set to array lengththis.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…arrow_forward
- How 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_forwardpublic class Book { protected String title; protected String author; protected String publisher; protected String publicationDate; public void setTitle(String userTitle) { title = userTitle; } public String getTitle() { return title; } public void setAuthor(String userAuthor) { author = userAuthor; } public String getAuthor(){ return author; } public void setPublisher(String userPublisher) { publisher = userPublisher; } public String getPublisher() { return publisher; } public void setPublicationDate(String userPublicationDate) { publicationDate = userPublicationDate; } public String getPublicationDate() { return publicationDate; } public void printInfo() { System.out.println("Book Information: "); System.out.println(" Book Title: " + title); System.out.println(" Author: " + author); System.out.println(" Publisher: " + publisher); System.out.println(" Publication…arrow_forwardQuestion 13 What is outpout? public class Vehicle { public void drive(){ System.out.println("Driving vehicle"); } } public class Plane extends Vehicle { @Override public void drive(){ System.out.println("Flying plane"); } public static void main(String args[]) { Vehicle myVehicle= = new Plane(); myVehicle.drive(); } Driving vehicle syntax error Flying plane Driving vehicle Flying plane }arrow_forward
- C# Solve this error using System; namespace RahmanA3P1BasePlusCEmployee { public class BasePlusCommissionEmployee { public string FirstName { get; } public string LastName { get; } public string SocialSecurityNumber { get; } private decimal grossSales; // gross weekly sales private decimal commissionRate; // commission percentage private decimal baseSalary; // base salary per week // six-parameter constructor public BasePlusCommissionEmployee(string firstName, string lastName, string socialSecurityNumber, decimal grossSales, decimal commissionRate, decimal baseSalary) { // implicit call to object constructor occurs here FirstName = firstName; LastName = lastName; SocialSecurityNumber = socialSecurityNumber; GrossSales = grossSales; // validates gross sales CommissionRate = commissionRate; // validates commission rate BaseSalary = baseSalary; // validates base…arrow_forwardclass implementation file -- Rectangle.cpp class Rectangle { #include #include "Rectangle.h" using namespace std; private: double width; double length; public: void setWidth (double); void setLength (double) ; double getWidth() const; double getLength() const; double getArea () const; } ; // set the width of the rectangle void Rectangle::setWidth (double w) { width = w; } // set the length of the rectangle void Rectangle::setLength (double l) { length l; //get the width of the rectangle double Rectangle::getWidth() const { return width; // more member functions herearrow_forward// This class discounts prices by 10% public class DebugFour4 { public static void main(String args[]) { final double DISCOUNT_RATE = 0.90; int price = 100; double price2 = 100.00; tenPercentOff(price DISCOUNT_RATE); tenPercentOff(price2 DISCOUNT_RATE); } public static void tenPercentOff(int p, final double DISCOUNT_RATE) { double newPrice = p * DISCOUNT_RATE; System.out.println("Ten percent off " + p); System.out.println(" New price is " + newPrice); } public static void tenPercentOff(double p, final double DISCOUNT_RATE) { double newPrice = p * DISCOUNT_RATE; System.out.println"Ten percent off " + p); System.out.println(" New price is " + newprice); } }arrow_forward
- import java.util.Scanner;public class MP2{public static void main (String[] args){//initialization and declarationScanner input = new Scanner (System.in);String message;int Option1;int Option2;int Quantity;int TotalBill;int Cash;int Change;final int SPECIALS = 1;final int BREAKFAST = 2;final int LUNCH = 3;final int SANDWICHES = 4;final int DRINKS = 5;final int DESSERTS = 6;//For the Special, Breakfast, Lunch Optionsfinal int Meals1 = 11;final int Meals2 = 12;final int Meals3 = 13;final int Meals4 = 14;//First menu and First OptionSystem.out.println("\t Welcome to My Kitchen ");System.out.println("\t\t SPECIALS");System.out.println("\t\t [2] BREAKFAST MEALS");System.out.println("\t\t [3] LUNCH MEALS");System.out.println("\t\t [4] SANDWICHES");System.out.println("\t\t [5] DRINKS");System.out.println("\t\t [6] DESSERTS");System.out.println("\t\t [0] EXIT");System.out.print("Choose an option ");Option1 = input.nextInt();//first switch case statementsswitch(Option1){case (SPECIALS):message…arrow_forwardMath 130 Java programming Dear Bartleby, I am a student beginning in computer science. May I have some assistance on this lab assignment please? Thank you.arrow_forwardPlease help me with these errors in java. Errors below public class Student { //student related variables //for reading the student information String studName; int studNum; String coursesTaken; float midtermMarks; float finalTermMarks; String teachComments; float finalAvgWthCreEar; //setters and getters methods to the above fields /** * @return the studName */ public String getStudName() { return studName; } /** * @return the studNum */ public int getStudNum() { return studNum; } /** * @return the coursesTaken */ public String getCoursesTaken() { return coursesTaken; } /** * @return the midtermMarks */ public float getMidtermMarks() { return midtermMarks; } /** * @return the finalTermMarks */ public float getFinalTermMarks() { return finalTermMarks; } /** * @return the teachComments */ public String getTeachComments() { return teachComments; } /** * @return the finalAvgWthCreEar */ public float…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





