Define a new buy method that receives Vehicle type value in Person.java argument.

class Person { private String firstName; private String middleName; private String lastName; private int age; private double height; private double weight;

Person(String firstName, String lastName, int age, double height, double weight) { this.firstName = firstName; this.lastName = lastName; this.age = age; this.height = height; this.weight = weight; }

Person(String firstName, String middleName, String lastName, int age, double height, double weight) { this(firstName, lastName, age, height, weight); this.middleName = middleName; }

public String fullName() { if (this.middleName == null) { return this.firstName + " " + this.lastName; } else { return this.firstName + " " + this.middleName + " " + this.lastName; } }

public void printData() { System.out.println ("name is" + this.fullName () + "is"); System.out.println ("Age" + this.age + "Age"); System.out.println ("height" + this.height + "m"); System.out.println ("Weight is" + this.weight + "kg"); System.out.println ("BMI is" + Math.round (this.bmi ()) + ""); }

public double bmi() { return this.weight / this.height / this.height; }

// Please rewrite the following two with one method public void buy(Vehicle vehicle){ vehicle.setOwner(this); } }

Recommended Posts

Define a new buy method that receives Vehicle type value in Person.java argument.
Declare a method that has a Java return value with the return value data type
Verification value error that occurred in a clustering environment