201711671132《java实用教程》第四章学习总结
一、教材学习内容总结
(1)教材学习中的问题和解决过程
(2)代码调试内容总结(课后习题),无问题
1、
CPU.java
public class CPU {
int speed;
int getSpeed() {
return speed;
}
public void setSpeed(int speed) {
this.speed = speed;
}
}
HardDisk.java
public class HardDisk {
int amount;
int getAmount() {
return amount;
}
public void setAmount(int amount) {
this.amount = amount;
}
}
PC.java
public class PC {
CPU cpu;
HardDisk HD;
void setCPU(CPU cpu) {
this.cpu = cpu;
}
void setHardDisk(HardDisk HD) {
this.HD = HD;
}
void show(){
System.out.println("CPU速度:"+cpu.getSpeed());
System.out.println("硬盘容量:"+HD.getAmount());
}
}
Test.java
public class Test {
public static void main(String args[]) {
CPU cpu = new CPU();
HardDisk HD=new HardDisk();
cpu.setSpeed(2200);
HD.setAmount(200);
PC pc =new PC();
pc.setCPU(cpu);
pc.setHardDisk(HD);
pc.show();
}
}
(3)无疑问