Given the following Ride.java and it's instructions: I'm having trouble understanding how to create the deep copy for the array. Also, would the provided be the proper way to implement said instructions?

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Given the following Ride.java and it's instructions:

I'm having trouble understanding how to create the deep copy for the array.

Also, would the provided be the proper way to implement said instructions?


Ride.java
This class represents any amusement park ride. Ride should never be instantiated. Instead, it should only
serve as a superclass for more specific rides.
Variables:
For fields in Ride, use the most restrictive visibility modifier that allows the fields to be accessible from
any subclass.
String name
This variable should be immutable after construction of an instance.
double profits
the total amount of money this ride has made, always initially 0
int lastInspection
-
the number time ride has completed since the last inspection
String[] passengers
the names of passengers aboard this ride.
Constructors:
a) A constructor that takes in name, lastInspection, and passengers.
passengers argument array must be deep copied to the corresponding instance field.
should not simply copy the reference of the input array and assign it to the instance field.
b) A constructor that takes in name, passengers, and sets lastInspection to 0.
Methods:
a) ableToRun
i)
ii)
b) inspectRide
i)
ii)
iii)
iv)
i)
Takes in an int number of runs and returns a boolean that represents whether the ride can complete
that number of runs without needing an inspection.
This method should not have an implementation in the Ride class.
c) costPerPassenger
i)
ii)
Takes in a String[] that represents different components of the ride.
Resets lastInspection to 0 if the ride passes inspection and returns true.
Returns false if the ride does not pass inspection.
This method should not have an implementation in the Ride class.
111)
ii)
d) addPassengers
Takes in an int number of stops and returns a double representing the cost for the passenger to ride
the specified number of stops.
This method should not have an implementation in the Ride class.
Takes in an int number of stops and a String[] of passenger names.
Returns true if all new passengers can fit on the ride and the ride can travel the given number of
stops without an inspection, and false otherwise.
This method should not have an implementation in the Ride class.
Transcribed Image Text:Ride.java This class represents any amusement park ride. Ride should never be instantiated. Instead, it should only serve as a superclass for more specific rides. Variables: For fields in Ride, use the most restrictive visibility modifier that allows the fields to be accessible from any subclass. String name This variable should be immutable after construction of an instance. double profits the total amount of money this ride has made, always initially 0 int lastInspection - the number time ride has completed since the last inspection String[] passengers the names of passengers aboard this ride. Constructors: a) A constructor that takes in name, lastInspection, and passengers. passengers argument array must be deep copied to the corresponding instance field. should not simply copy the reference of the input array and assign it to the instance field. b) A constructor that takes in name, passengers, and sets lastInspection to 0. Methods: a) ableToRun i) ii) b) inspectRide i) ii) iii) iv) i) Takes in an int number of runs and returns a boolean that represents whether the ride can complete that number of runs without needing an inspection. This method should not have an implementation in the Ride class. c) costPerPassenger i) ii) Takes in a String[] that represents different components of the ride. Resets lastInspection to 0 if the ride passes inspection and returns true. Returns false if the ride does not pass inspection. This method should not have an implementation in the Ride class. 111) ii) d) addPassengers Takes in an int number of stops and returns a double representing the cost for the passenger to ride the specified number of stops. This method should not have an implementation in the Ride class. Takes in an int number of stops and a String[] of passenger names. Returns true if all new passengers can fit on the ride and the ride can travel the given number of stops without an inspection, and false otherwise. This method should not have an implementation in the Ride class.
public abstract class Ride {
protected final String name;
protected double profits;
protected int lastInspection;
protected String[] passengers;
public Ride (String id, int runsSinceInspection, String[] passengers) {
this.name = name;
this.profits
0;
this.lastInspection = 0;
//this.passengers =;
}
public Ride(String name, String[] passengers) {
this(name, 0, passengers);
}
public abstract boolean ableToRun(int numberofRuns);
public abstract boolean checkRide(String[] components);
public abstract double costPerPassenger(int numberOfStops);
public abstract boolean addPassengers(int numberOfStops, String[] newPassengers);
Transcribed Image Text:public abstract class Ride { protected final String name; protected double profits; protected int lastInspection; protected String[] passengers; public Ride (String id, int runsSinceInspection, String[] passengers) { this.name = name; this.profits 0; this.lastInspection = 0; //this.passengers =; } public Ride(String name, String[] passengers) { this(name, 0, passengers); } public abstract boolean ableToRun(int numberofRuns); public abstract boolean checkRide(String[] components); public abstract double costPerPassenger(int numberOfStops); public abstract boolean addPassengers(int numberOfStops, String[] newPassengers);
Expert Solution
steps

Step by step

Solved in 4 steps

Blurred answer
Knowledge Booster
Array
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
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education