class Person{
private String name;
private int age;
private Book book; //得到本人的书
public Person(String name,int age){
this.setName(name);
this.setAge(age);
}
public void setName(String name){
this.name = name;
}
public void setAge(int age){
this.age = age;
}
public String getName(){
return this.name;
}
public int getAge(){
return this.age;
}
public void SetBook(Book book){ //设置本人得到书
this.book = book;
}
public Book getBook(){
return book;
}
public String getInfo(){
return "姓名:" + this.getName() + "、年龄:" + this.getAge();
}
}
class Book{
private String title;
private double price;
private Person per;
public Book (String title,double price){
this.setTitle(title);
this.setPrice(price);
}
public void setTitle(String title){
this.title = title;
}
public void setPrice(double price){
this.price = price;
}
public String getTitle(){
return this.title;
}
public double getPrice(){
return this.price;
}
public void setPer(Person per){
this.per = per;
}
public Person getPer(){
return this.per;
}
public String getInfo(){
return "书名:" + this.getTitle() + "、价格:" + this.getPrice();
}
}
public class Studyjava1{
public static void main (String args[]){
Person per1 = new Person("张三",19);
Person per2 = new Person("李四",22);
Book bk1 = new Book("java se",87.0);
Book bk2 = new Book("java ee",83.0);
System.out.println(bk1.getInfo());
per1.setBook(bk1);
per2.setBook(bk2);
bk1.setper(per1);
bk2.setper(per2);
}
}
private String name;
private int age;
private Book book; //得到本人的书
public Person(String name,int age){
this.setName(name);
this.setAge(age);
}
public void setName(String name){
this.name = name;
}
public void setAge(int age){
this.age = age;
}
public String getName(){
return this.name;
}
public int getAge(){
return this.age;
}
public void SetBook(Book book){ //设置本人得到书
this.book = book;
}
public Book getBook(){
return book;
}
public String getInfo(){
return "姓名:" + this.getName() + "、年龄:" + this.getAge();
}
}
class Book{
private String title;
private double price;
private Person per;
public Book (String title,double price){
this.setTitle(title);
this.setPrice(price);
}
public void setTitle(String title){
this.title = title;
}
public void setPrice(double price){
this.price = price;
}
public String getTitle(){
return this.title;
}
public double getPrice(){
return this.price;
}
public void setPer(Person per){
this.per = per;
}
public Person getPer(){
return this.per;
}
public String getInfo(){
return "书名:" + this.getTitle() + "、价格:" + this.getPrice();
}
}
public class Studyjava1{
public static void main (String args[]){
Person per1 = new Person("张三",19);
Person per2 = new Person("李四",22);
Book bk1 = new Book("java se",87.0);
Book bk2 = new Book("java ee",83.0);
System.out.println(bk1.getInfo());
per1.setBook(bk1);
per2.setBook(bk2);
bk1.setper(per1);
bk2.setper(per2);
}
}