3. Define a notebook class with
two attributes: color (char) and cpu model (int). [Mandatory questions]
• 3.1 Two construction methods without parameters and with parameters; the construction method with parameters can
assign values to each attribute while creating the object;
• 3.2 the method of outputting notebook information
• 3.3 and then write a test class, Test the various
methods of the notebook class .
package test; public class aa { char color; int cpu; aa() { } aa(char color, int cpu) { this.color = color; this.cpu = cpu; } void a() { System.out.println("颜色:"+color); System.out.println( "型号:"+cpu); } public static void main(String[] args) { aa a= new aa('a',4689); a.a(); } }
5. Define two classes, described as follows: [Mandatory questions]
• 5.1 Define a human Person:
• 5.1.1 Define a method sayHello (), which can send a question
“hello, my name is XXX” to each other
• 5.1 .2 has three attributes: name, height, weight / age
• 5.2 defines a PersonCreate class:
• 5.2.1 creates two objects, namely zhangsan, 33 years old, 1.73
; lishi, 44, 1.74
• 5.2.2 call objects separately The sayHello () method.
package test; public class person { String name; double height; int age; person (String name, double height, int age) { this.name = name; this.height = height; this.age = age; } void sayHello() { System.out.println("hello,my name is " + name+" "+height+"m"+" "+age+"岁"); } } package test; public class personcreate { public static void main(String[] args) { person a = new person("lishi", 1.80, 23); person b = new person("wanger", 1.69, 19); a.sayHello(); b.sayHello(); } }