JAVASCRIPT USING ECLIPSE Part A.Create a class called Trip with Private Attribut
ID: 3700692 • Letter: J
Question
JAVASCRIPT USING ECLIPSE
Part A.Create a class called Trip with
Private Attributes: tripID (int)
location (String)
pricePerPerson (double)
Public Methods:
constructor: Receives values for the attributes as parameters and initializes them.//argument constructor
display: Displays the trip information, including tripID, location, and pricePerPerson.
computeCost: This method takes an integer parameter to represent the number of people coming on the trip, and returns the computed cost using the number of people and pricePerPerson attribute.
Explanation / Answer
//Trip.java public class Trip { private int tripID; private String location; private double pricePerPerson; public Trip(int tripID, String location, double pricePerPerson) { this.tripID = tripID; this.location = location; this.pricePerPerson = pricePerPerson; } public String display() { return "Trip{" + "tripID=" + tripID + ", location='" + location + ''' + ", pricePerPerson=" + pricePerPerson + '}'; } public double computeCost(int n){ return n * pricePerPerson; } }
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.