创建一个电脑类Computer类。
类中有变量品牌brand 、内存memory、型号 model
定义类的无参构造方法
定义为品牌赋值的构造方法
定义为内存和型号赋值的构造方法
设置内存的方法,要求内存必须是8、16、32之一
获取内存的方法
返回类的品牌信息的方法
创建一个对象obj,品牌为“联想”,型号为“天逸“,内存为”16“G
并把该电脑配置输出到屏幕
创建一个电脑类Computer类。 类中有变量品牌brand 、内存memory、型号 model 定义类的无参构造方法 定义为品牌赋值的构造方法 定义为内存和型号赋值的构造方法
- 写回答
- 好问题 0 提建议
- 追加酬金
- 关注问题
- 邀请回答
-
1条回答 默认 最新
- 龙猫爱抓鱼 2022-12-09 10:13关注
希望对您有所帮助,望采纳
public class Computer { private String brand; private String memory; private String model; public Computer() { } public Computer(String brand) { this.brand = brand; } public Computer(String memory, String model) { this.memory = memory; this.model = model; } public String getBrand() { return brand; } public void setBrand(String brand) { this.brand = brand; } public String getMemory() { return memory; } public void setMemory(String memory) { if ("8".equals(memory) || "16".equals(memory) || "32".equals(memory)) { this.memory = memory; } else { System.out.println("内存必须为8或16或32"); } } public String getModel() { return model; } public void setModel(String model) { this.model = model; } public String toString() { return "电脑信息:品牌为【" + this.brand + "】," + "型号为【" + this.model + "】,内存为【" + this.memory + "】G"; } } public class Main { public static void main(String[] args) { Computer computer = new Computer("联想"); computer.setMemory("16"); computer.setModel("天逸"); System.out.println(computer.toString()); } }
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报
悬赏问题
- ¥15 不是,这到底错哪儿了😭
- ¥15 2020长安杯与连接网探
- ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
- ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
- ¥16 mybatis的代理对象无法通过@Autowired装填
- ¥15 可见光定位matlab仿真
- ¥15 arduino 四自由度机械臂
- ¥15 wordpress 产品图片 GIF 没法显示
- ¥15 求三国群英传pl国战时间的修改方法
- ¥15 matlab代码代写,需写出详细代码,代价私