The requirements for computer design are as follows: properties: Brand, color, cpu model, memory capacity, hard disk size, price, and working status; Method: Enable, disable, and sleep; create a computer object, call the open or close method,
The Code is as follows:
1 // Author: realjanushu 2 // Date: 17/9/28 3/* function: 4 design computer requirements: 5 6 attributes: Brand, color, cpu model, memory capacity, hard Disk size, price, working status; 7 8 Methods: open, close, sleep; 9 10 create a computer object, method 11 */12 public class ComputerDemo {13 public static void main (String [] args) {14 Computer c1 = new Computer (); 15 c1.open (); 16 c1.sleep (); 17} 18} 19 class Computer {20 String brand; // brand 21 String color; // color 22 String model; // model 23 int memory; // memory 24 int hardDiskStorage; // hard disk storage 25 String status; // working status 26 Computer () {}// display declaration default constructor 27 // initialization variable 28 public Computer (String brand, String color, String model, 29 int memory, int hardDiskStorage, String status) {30 // distinguish between member attributes and parameter 31 this. brand = brand; 32 this. color = color; 33 this. model = model; 34 this. memory = memory; 35 this. hardDiskStorage = hardDiskStorage; 36 this. status = status; 37} 38 // print out 39 public void open () {40 System. out. println ("turn on the computer"); 41} 42 public void shutdown () {43 System. out. println ("disabled"); 44} 45 public void sleep () {46 System. out. println ("Sleep"); 47} 48}