1.TestDemo 类
package com.dayuanit.java;
public class TestDemo {
public static void main(String[] args) {
School school = new School("南京外国语中学","长江中路155号");
Paper paper = new Paper(5, 10);
Bike bike = new Bike("ofo", "黄色", 1880);
Person person = new Person("小明", 15, "天润城19街区");
person.gotoSchool(bike, person);
person.goTest(paper,school);
}
}
将Bike bike 改为Autool autool
2.School类
package com.dayuanit.java;
public class School {
private String name;
private String address;
public School() {
}
public School(String name, String address) {
this.name = name;
this.address = address;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getAddress() {
return address;
}
public void setAddress() {
this.address = address;
}
}
3.Person 类
package com.dayuanit.java;
public class Person {
private String name;
private int age;
private String address;
public Person() {
}
public Person(String name, int age, String address) {
this.name = name;
this.age = age;
this.address = address;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
public void gotoSchool(Autool autool, Person person) {
autool.move(person);
}
public void goTest(Paper paper, School school) {
paper.exam(school);
}
}
4.Paper类
package com.dayuanit.java;
public class Paper {
private int chioce;
private int judge;
public Paper() {
}
public Paper(int chioce, int judge) {
this.chioce = chioce;
this.judge = judge;
}
public int getChioce() {
return chioce;
}
public void setChioce(int chioce) {
this.chioce = chioce;
}
public int getJudge() {
return judge;
}
public void setJudge(int judge) {
this.judge = judge;
}
public void exam(School school) {
System.out.println("去位于" + school.getAddress()
+ "的" + school.getName()
+"考试,考试内容是"
+ chioce + "选择题"
+ judge + "判断题");
}
}
5.Car,Bike类
package com.dayuanit.java;
public class Car extends Autool {
public Car() {
}
public Car(String name, String color, int price) {
super(name, color, price);
}
public void move(Person person){
System.out.println("家住在"
+ person.getAddress()
+ "的" + person.getAge()
+ person.getName()
+ "开着一辆价值"
+ getPrice()
+ "的" + getColor()
+ getName());
}
}
package com.dayuanit.java;
public class Bike extends Autool {
public Bike() {
}
public Bike(String name, String color, int price) {
super(name, color, price);
}
public void move(Person person){
System.out.println("家住在"
+ person.getAddress()
+ "的" + person.getAge()
+ person.getName()
+ "骑着一辆价值"
+ getPrice()
+ "的" + getColor()
+ getName());
}
}
6.父类Autool
package com.dayuanit.java;
public class Autool {
private String name;
private String color;
private int price;
public Autool() {
}
public Autool(String name, String color, int price) {
this.name = name;
this.color = color;
this.price = price;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getColor() {
return color;
}
public void setColor(String color) {
this.color = color;
}
public int getPrice() {
return price;
}
public void setPrice(int price) {
this.price = price;
}
public void move(Person person){
System.out.println("家住在"
+ person.getAddress()
+ "的" + person.getAge()
+ person.getName()
+ "用着一辆价值"
+ price
+ "的" + color
+ name);
}
}