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.

EBK JAVA PROGRAMMING
9th Edition
ISBN:9781337671385
Author:FARRELL
Publisher:FARRELL
Chapter11: Advanced Inheritance Concepts
Section: Chapter Questions
Problem 2PE
icon
Related questions
Question

Given the following instructions and starter:

Would this be the right way to implement the variables and constructors?

I'm a bit confused on how to deep copy the passenger array.

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.
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.
public abstract class Ride {
private String name;
private double profits;
private int lastInspection;
private String[] passengers;
public Ride(String name, int lastInspection, String[] passengers) {
this.name = name;
this.profits = profits;
this.runsSinceInspection = runsSinceInspection;
}
this.passengers = new String[]passengers;
public Ride(String name, String[] passengers) {
this(name, 0, passengers);
}
Transcribed Image Text:public abstract class Ride { private String name; private double profits; private int lastInspection; private String[] passengers; public Ride(String name, int lastInspection, String[] passengers) { this.name = name; this.profits = profits; this.runsSinceInspection = runsSinceInspection; } this.passengers = new String[]passengers; public Ride(String name, String[] passengers) { this(name, 0, passengers); }
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps with 3 images

Blurred answer
Follow-up Questions
Read through expert solutions to related follow-up questions below.
Follow-up Question

Is there any other way to deep copy without having to create the helper method?

Solution
Bartleby Expert
SEE SOLUTION
Knowledge Booster
Unreferenced Objects
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
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT