这个怎么写简单易懂,答疑

创建计算机类,笔记本电脑类(计算机)中包含:
品牌(品牌)颜色(颜色)价格(价格)。
电脑类中有:开机的方法(打印电脑开机了),我
有关机的方法(打印电脑关机了),
有工作的方法。在工作的方法中要调用开机关机的方法。(在工作的方法中,调用开机和关机的方法中间,打印一句话:电脑在工作)。
还有一个方法打印电脑的信息方法(品牌 颜色价格)
在测试类中创建一个电脑对象,给它的属性赋值。然后调用电脑对象工作的方法和打印电脑对象打印信息的方法。

Computer类

package com.rg.question;

public class Computer {
    //开机
    public void turnOn() {
        System.out.println("电脑开机了......");
    }
    
    //关机
    public void turnOff() {
        System.out.println("电脑关机了......");
    }
    
    public void work() {
        this.turnOn();
        System.out.println("电脑在工作......");
        this.turnOff();
    }

}


Notebook类

package com.rg.question;
/**
 * 笔记本类
 * @author 物竞天择适者生存
 *
 */
public class Notebook extends Computer{
    private String brand;
    private String color;
    private double price;
    public Notebook() {
        super();
        // TODO Auto-generated constructor stub
    }
    public Notebook(String brand, String color, double price) {
        super();
        this.brand = brand;
        this.color = color;
        this.price = price;
    }
    public String getBrand() {
        return brand;
    }
    public void setBrand(String brand) {
        this.brand = brand;
    }
    public String getColor() {
        return color;
    }
    public void setColor(String color) {
        this.color = color;
    }
    public Double getPrice() {
        return price;
    }
    public void setPrice(double price) {
        this.price = price;
    }
    @Override
    public String toString() {
        return "Notebook [brand=" + brand + ", color=" + color + ", price=" + price + "]";
    }
    
}

测试类

package com.rg.question;



public class Test01 {
    public static void main(String[] args) {
        Computer computer = new Notebook("惠普战666", "土豪银", 9999);
        System.out.println(computer);
        computer.work();
    }

}

运行结果:

img

不是很明确你的需求,根据你的描述我猜测你是在学习继承相关的内容,我按我的理解给个例子,你参考一下:

class Computer{
    private String brand;
    private String color;
    private int price;
    public Computer(){}
    public Computer(String brand, String color, int price){
        this.brand = brand;
        this.color = color;
        this.price = price;
    }

    public void showInfo(){
        System.out.println("品牌:"+this.brand+", 颜色:"+this.color+", 价格:"+this.price);
    }

    public void start(){
        System.out.println("电脑开机了");
    }
    public void stop(){
        System.out.println("电脑关机了");
    }
}

class Laptop extends Computer{
    public Laptop(String brand, String color, int price){
        super(brand,color,price);
    }
    public void work(){
        this.start();
        System.out.println("电脑在工作");
        this.stop();
    }
}

public class DemoTest{
    public static void main(String[] args) {
        Laptop laptop = new Laptop("联想", "黑色", 6700);
        laptop.work();
        laptop.showInfo();
    }
}

img


如有帮助,请采纳!

应该还要在加两个个属性值,电脑是否关机,电脑是否在工作。