package computer;
public class Computer {
private boolean state;
private int number;
public Computer(){}
public Computer(int number){
this.number = number;
}
public int getNumber(){
return this.number;
}
public boolean getState(){
return this.state;
}
public void beOpen(){
System.out.println(this.number +"电脑被打开");
}
public void beUsing(){
System.out.println(this.number + "电脑被使用");
}
public void beClose(){
System.out.println(this.number + "电脑被关闭");
}
}
package computer;
public class MachineRoom {
public void welcomeStudent(Student student){
String name = student.getName();
System.out.println("欢迎" + name + "学生进入机房");
Computer computer = new Computer(1);
student.useComputer(computer);
}
}
package computer;
public class Student {
private String name;
public Student(){}
public Student(String name){
this.name = name;
}
public String getName(){
return this.name;
}
public void useComputer(Computer computer){
System.out.println(this.name+"开始使用电脑");
computer.beOpen();
computer.beUsing();
computer.beClose();
}
}
package computer;
public class Test {
public static void main(String[] args) {
MachineRoom machineRoom = new MachineRoom();
Student student = new Student("小红"); //此时student是对象属性
machineRoom.welcomeStudent(student);
}
}
"C:\Program Files (x86)\Java\jdk1.7.0_71\bin\java.exe" ...
欢迎小红学生进入机房
小红开始使用电脑
1电脑被打开
1电脑被使用
1电脑被关闭