class demo_mian {
public static void main(String[] args) {
Phone p1 = new Phone();
p1.setBrand("魅族");
p1.setPrice(2688);
System.out.println(p1.getBrand() + "..." + p1.getPrice());
p1.call();
p1.sendMessage();
p1.playGame();
Person p2 = new Person();
p2.setName("盖伦");
p2.setAge(17);
System.out.println(p2.getName() + "..." + p2.getAge());
p2.study();
p2.sleep();
Animal p3 = new Animal();
p3.setName("熊猫");
p3.setAge(12);
System.out.println(p3.getName() + "..." + p3.getAge());
p3.eat();
Dog p4 = new Dog();
p4.setName("二哈");
p4.setAge(8);
System.out.println(p4.getName() + "..." + p4.getAge());
p4.eat();
p4.lookHome();
Cat p5 = new Cat();
p5.setName("汤姆");
p5.setAge(4);
System.out.println(p5.getName() + "..." + p5.getAge());
p5.eat();
p5.catchMouse();
Student p6 = new Student();
p6.setChinese(128);
p6.setMath(136);
p6.setEnglish(132);
System.out.println(p6.getChinese() + "..." + p6.getMath() + "..." + p6.getEnglish());
System.out.println(p6.getSum());
}
}
class Phone {
private String brand;
private int price;
public void setBrand(String brand) {
this.brand = brand;
}
public String getBrand() {
return this.brand;
}
public void setPrice(int price) {
this.price = price;
}
public int getPrice() {
return this.price;
}
public void call() {
System.out.println("打电话");
}
public void sendMessage() {
System.out.println("发短信");
}
public void playGame() {
System.out.println("玩游戏");
}
}
class Person {
private String name;
private int age;
public void setName(String name) {
this.name = name;
}
public String getName() {
return name;
}
public void setAge(int age) {
this.age = age;
}
public int getAge () {
return age;
}
public void study() {
System.out.println("学生能学习");
}
public void sleep() {
System.out.println("学生需要睡觉");
}
}
class Animal {
private String name;
private int age;
public void setName(String name) {
this.name = name;
}
public String getName() {
return name;
}
public void setAge(int age) {
this.age = age;
}
public int getAge() {
return age;
}
public void eat() {
System.out.println("熊猫要吃竹子");
}
}
class Dog {
private String name;
private int age;
public void setName(String name) {
this.name = name;
}
public String getName() {
return name;
}
public void setAge(int age) {
this.age = age;
}
public int getAge() {
return age;
}
public void eat() {
System.out.println("狗要吃骨头");
}
public void lookHome() {
System.out.println("狗会看家");
}
}
class Cat {
private String name;
private int age;
public void setName(String name) {
this.name = name;
}
public String getName() {
return name;
}
public void setAge(int age) {
this.age = age;
}
public int getAge() {
return age;
}
public void eat() {
System.out.println("汤姆要吃杰瑞");
}
public void catchMouse() {
System.out.println("汤姆要抓杰瑞");
}
}
class Student {
private int chinese;
private int math;
private int english;
public void setChinese(int chinese) {
this.chinese = chinese;
}
public int getChinese() {
return chinese;
}
public void setMath(int math) {
this.math = math;
}
public int getmath() {
return math;
}
public void setEnglish(int english) {
this.english = english;
}
public int getEnglish() {
return english;
}
public int getSum() {
return chinese + math + english;
}
} |
|