m0_75120226 2023-04-18 19:22 采纳率: 100%
浏览 25
已结题

Java创建一个电脑类

需要一个完整代码,谢谢((˵¯͒〰¯͒˵)(=TェT=)挨骂˃ʍ˂)

  • 写回答

2条回答 默认 最新

  • CSDN专家-sinJack 2023-04-18 19:37
    关注
    public class Computer {
        private String brand;
        private String model;
        private int year;
        private double price;
    
        public Computer(String brand, String model, int year, double price) {
            this.brand = brand;
            this.model = model;
            this.year = year;
            this.price = price;
        }
        
        public void turnOn() {
            System.out.println("The computer is turning on.");
        }
    
        public void turnOff() {
            System.out.println("The computer is turning off.");
        }
    
        public void printSpecs() {
            System.out.println("Brand: " + brand);
            System.out.println("Model: " + model);
            System.out.println("Year: " + year);
            System.out.println("Price: $" + price);
        }
    
        public static void main(String[] args) {
            Computer computer=new Computer("苹果电脑","16G内存",2023,12999);
            computer.printSpecs();
        }
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论 编辑记录
查看更多回答(1条)

报告相同问题?

问题事件

  • 系统已结题 4月26日
  • 已采纳回答 4月18日
  • 创建了问题 4月18日