Question: The Passenger class from the previous assignment public class Passenger { private String name; private int birthYear; private double weight; private char gender; private int
The Passenger class from the previous assignment
public class Passenger { private String name; private int birthYear; private double weight; private char gender; private int numCarryOn;
public Passenger() { this.name = ""; this.birthYear = 1900; this.weight = 0.0; this.gender = 'u'; this.numCarryOn = 0; }
public Passenger(String name, int birthYear, double weight, char gender, int numCarryOn) { this.name = name; this.birthYear = birthYear; this.weight = weight; this.gender = gender; this.numCarryOn = numCarryOn; }
public String getName() { return name; }
public void setName(String name) { this.name = name; }
public int getBirthYear() { return birthYear; }
public void setBirthYear(int birthYear) { this.birthYear = birthYear; }
public double getWeight() { return weight; }
public void setWeight(double weight) { if (weight
public char getGender() { return gender; }
public void setGender(char gender) { if (gender != 'm' && gender != 'f') { this.gender = 'u'; } else { this.gender = gender; } }
public int getNumCarryOn() { return numCarryOn; }
public void setNumCarryOn(int numCarryOn) { if (numCarryOn 2) { this.numCarryOn = 2; } else { this.numCarryOn = numCarryOn; } }
public int calculateAge(int currentYear) { if (currentYear
public void gainWeight() { this.weight += 1.0; }
public void gainWeight(double weight) { this.weight += weight; if (this.weight
public boolean isFemale() { return this.gender == 'f'; }
public boolean isMale() { return this.gender == 'm'; }
public void loseWeight() { this.weight -= 1; if (this.weight
public void loseWeight(double weight) { this.weight -= weight; if (this.weight
public void printDetails() { String details = String.format( "Name: %20s | Year of Birth: %4d | Weight: %10.2f | Gender: %c | NumCarryOn: %2d ", this.name, this.birthYear, this.weight, this.gender, this.numCarryOn); System.out.print(details); } }
Take the Passenger class from the previous assignment and add the following to it: Passenger - height: double + Passenger(String, int, double double char, int)/ame, birth Year, weight, height, gender, numCarryOn + getHeight(): double + setHeight(double): void l/if input value is negative set height to-1 + calculate BMI(): double l/using pounds and inches BMI = ( weight * 703) / (height?) + printDetails(): void // prints Passenger attributes in the following format: // "Name: %20s | Year of Birth: %4d Weight: %10.2f | Height: %10.2f Gender: %c NumCarryOn: %2d " + toString(): String @Override I/ see Note 1 for format + equals(Object): boolean @Override l/see Note2 for equality checks NOTE 1: Format the data for the toString() method as "Name: %20s Year of Birth: %4d Weight: %10.2f | Height: %10.2f | Gender: %c | NumCarryOn: %2d " NOTE2: For the equals(Object) method, two Passenger objects are considered equal if both have the same values for birth Year, gender, name and if their weight, height values are within .5 of the other's weight, height values
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
