使用java语言设计一组类(至少3个类),分别表示计算机,台式机,笔记本,服务器(注意使用继承)

时间: 2024-05-06 09:18:24 浏览: 7
下面是使用Java语言设计的一组类,分别表示计算机,台式机,笔记本和服务器,其中台式机和笔记本都继承自计算机类,服务器则继承自台式机类。 ``` public class Computer { private String brand; private String model; private int price; public Computer(String brand, String model, int price) { this.brand = brand; this.model = model; this.price = price; } public String getBrand() { return brand; } public String getModel() { return model; } public int getPrice() { return price; } public void setBrand(String brand) { this.brand = brand; } public void setModel(String model) { this.model = model; } public void setPrice(int price) { this.price = price; } } public class Desktop extends Computer { private String cpu; private int memorySize; private int hardDiskSize; public Desktop(String brand, String model, int price, String cpu, int memorySize, int hardDiskSize) { super(brand, model, price); this.cpu = cpu; this.memorySize = memorySize; this.hardDiskSize = hardDiskSize; } public String getCpu() { return cpu; } public int getMemorySize() { return memorySize; } public int getHardDiskSize() { return hardDiskSize; } public void setCpu(String cpu) { this.cpu = cpu; } public void setMemorySize(int memorySize) { this.memorySize = memorySize; } public void setHardDiskSize(int hardDiskSize) { this.hardDiskSize = hardDiskSize; } } public class Laptop extends Computer { private String cpu; private int memorySize; private int hardDiskSize; private int batteryCapacity; public Laptop(String brand, String model, int price, String cpu, int memorySize, int hardDiskSize, int batteryCapacity) { super(brand, model, price); this.cpu = cpu; this.memorySize = memorySize; this.hardDiskSize = hardDiskSize; this.batteryCapacity = batteryCapacity; } public String getCpu() { return cpu; } public int getMemorySize() { return memorySize; } public int getHardDiskSize() { return hardDiskSize; } public int getBatteryCapacity() { return batteryCapacity; } public void setCpu(String cpu) { this.cpu = cpu; } public void setMemorySize(int memorySize) { this.memorySize = memorySize; } public void setHardDiskSize(int hardDiskSize) { this.hardDiskSize = hardDiskSize; } public void setBatteryCapacity(int batteryCapacity) { this.batteryCapacity = batteryCapacity; } } public class Server extends Desktop { private int numOfCPUs; private int numOfHardDisks; public Server(String brand, String model, int price, String cpu, int memorySize, int hardDiskSize, int numOfCPUs, int numOfHardDisks) { super(brand, model, price, cpu, memorySize, hardDiskSize); this.numOfCPUs = numOfCPUs; this.numOfHardDisks = numOfHardDisks; } public int getNumOfCPUs() { return numOfCPUs; } public int getNumOfHardDisks() { return numOfHardDisks; } public void setNumOfCPUs(int numOfCPUs) { this.numOfCPUs = numOfCPUs; } public void setNumOfHardDisks(int numOfHardDisks) { this.numOfHardDisks = numOfHardDisks; } } ```

相关推荐

最新推荐

recommend-type

台式机安装苹果系统教程

台式机安装苹果系统教程 不用光驱也能装苹果系统!其实很简单,不要看网上那么复杂。 准备工具(1) 下载镜像文件(ISO)的苹果系统.(2)下载硬盘助手和变色龙(Chameleon Install)还有一张PE系统盘XP W7也得
recommend-type

台式机如何使用wlan

台式机也可以用wlan 省钱 省时 方便。只要你的地区已wlan覆盖
recommend-type

2013计算机毕业设计云计算应用之桌面虚拟化论文

自己做的毕业设计,主要是XP虚拟化,linux很简单一笔带过。电脑配置内存至少4G,处理器尽量好一点,反正配置越高越好。开始我是用一台电脑做的,卡的...答辩前两个星期导师给我配了两台台式机,又在台式机上做了一遍。
recommend-type

电脑台式和笔记本的wifi密码破解工具和方法及教程

希望对大家有所帮助,详细记录了电脑台式和笔记本的wifi密码破解工具和方法及教程
recommend-type

zigbee-cluster-library-specification

最新的zigbee-cluster-library-specification说明文档。
recommend-type

管理建模和仿真的文件

管理Boualem Benatallah引用此版本:布阿利姆·贝纳塔拉。管理建模和仿真。约瑟夫-傅立叶大学-格勒诺布尔第一大学,1996年。法语。NNT:电话:00345357HAL ID:电话:00345357https://theses.hal.science/tel-003453572008年12月9日提交HAL是一个多学科的开放存取档案馆,用于存放和传播科学研究论文,无论它们是否被公开。论文可以来自法国或国外的教学和研究机构,也可以来自公共或私人研究中心。L’archive ouverte pluridisciplinaire
recommend-type

【实战演练】MATLAB用遗传算法改进粒子群GA-PSO算法

![MATLAB智能算法合集](https://static.fuxi.netease.com/fuxi-official/web/20221101/83f465753fd49c41536a5640367d4340.jpg) # 2.1 遗传算法的原理和实现 遗传算法(GA)是一种受生物进化过程启发的优化算法。它通过模拟自然选择和遗传机制来搜索最优解。 **2.1.1 遗传算法的编码和解码** 编码是将问题空间中的解表示为二进制字符串或其他数据结构的过程。解码是将编码的解转换为问题空间中的实际解的过程。常见的编码方法包括二进制编码、实数编码和树形编码。 **2.1.2 遗传算法的交叉和
recommend-type

openstack的20种接口有哪些

以下是OpenStack的20种API接口: 1. Identity (Keystone) API 2. Compute (Nova) API 3. Networking (Neutron) API 4. Block Storage (Cinder) API 5. Object Storage (Swift) API 6. Image (Glance) API 7. Telemetry (Ceilometer) API 8. Orchestration (Heat) API 9. Database (Trove) API 10. Bare Metal (Ironic) API 11. DNS
recommend-type

JSBSim Reference Manual

JSBSim参考手册,其中包含JSBSim简介,JSBSim配置文件xml的编写语法,编程手册以及一些应用实例等。其中有部分内容还没有写完,估计有生之年很难看到完整版了,但是内容还是很有参考价值的。
recommend-type

"互动学习:行动中的多样性与论文攻读经历"

多样性她- 事实上SCI NCES你的时间表ECOLEDO C Tora SC和NCESPOUR l’Ingén学习互动,互动学习以行动为中心的强化学习学会互动,互动学习,以行动为中心的强化学习计算机科学博士论文于2021年9月28日在Villeneuve d'Asq公开支持马修·瑟林评审团主席法布里斯·勒菲弗尔阿维尼翁大学教授论文指导奥利维尔·皮耶昆谷歌研究教授:智囊团论文联合主任菲利普·普雷教授,大学。里尔/CRISTAL/因里亚报告员奥利维耶·西格德索邦大学报告员卢多维奇·德诺耶教授,Facebook /索邦大学审查员越南圣迈IMT Atlantic高级讲师邀请弗洛里安·斯特鲁布博士,Deepmind对于那些及时看到自己错误的人...3谢谢你首先,我要感谢我的两位博士生导师Olivier和Philippe。奥利维尔,"站在巨人的肩膀上"这句话对你来说完全有意义了。从科学上讲,你知道在这篇论文的(许多)错误中,你是我可以依