CUP
package week;
public interface CPU {
public String brand(String brand);
public String frequence(String brand);
}
硬盘
package week;
public interface HardDisk {
public String capacityY(String capacity);
}
内存
package week;
public interface Memory {
public String capacityN(String capacity);
}
计算机性能
package week;
public class Computer implements CPU,HardDisk,Memory{
String brand;
public String brand(String brand) {
this.brand = brand;
return brand;
}
String frequence;
public String frequence(String frequence) {
this.frequence = frequence;
return frequence;
}
String capacity1;
public String capacityY(String capacity) {
this.capacity1 = capacity;
return capacity;
}
String capacity2;
public String capacityN(String capacity) {
this.capacity2 = capacity;
return capacity;
}
public void printer(){
System.out.println("计算机的信息如下:");
System.out.println("CPU的品牌是:"+brand+"主频为:"+frequence);
System.out.println("硬盘容量是:"+capacity1);
System.out.println("内存容量是:"+capacity2);
}
}
测试类
package week;
public class Test {
public static void main(String[] args) {
Computer computer = new Computer();
computer.brand("Inter");
computer.frequence("3.8GHz");
computer.capacityY("3000GB");
computer.capacityN("8GB");
computer.printer();
}
}
测试结果