LoginSignup
0
0

More than 3 years have passed since last update.

Person.java 引数にVehicle型の値を受け取るbuyメソッドを新たに定義する。

Posted at

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("名前は" + this.fullName() + "です");
System.out.println("年齢は" + this.age + "歳です");
System.out.println("身長は" + this.height + "mです");
System.out.println("体重は" + this.weight + "kgです");
System.out.println("BMIは" + Math.round(this.bmi()) + "です");
}

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

// 以下2つを一つのメソッドで書き換えてください
public void buy(Vehicle vehicle){
vehicle.setOwner(this);
}
}

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0