4.23 homework

3. Define a notebook class with two attributes: color ( char) and cpu
model ( int). [Will do questions]
• 3.1 and two no-argument constructor has the Senate; arg constructor may have
to assign for each property while creating an object;
methods • 3.2 output notebook information
• 3.3 and then write a test class, Test the various
methods of the notebook class .

 1 package wyyyy;
 2 public class macbookpro {
 3         char color;
 4         int model;
 5 
 6         macbookpro() {
 7 
 8         }
 9 
10         macbookpro(char color, int model) {
11             this.color = color;
12             this.model = model;
13         }
14 
15         void a() {
16             System.out.println("颜色:" + color + "  型号:" + model);
17         }
18 
19         public static void main(String[] args) {
20             macbookpro a = new macbookpro('a', 2020);
21             a.a();
22         }
23     }

5. define two classes, described as follows:  [will do questions]
• 5.1 definition of a human the Person:
• 5.1.1 define a method sayHello (), you can send out to ask each other
greeting "the Hello, My name IS XXX"
• 5.1 .2 has three attributes: name, height, and 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 calls the sayHello of the objects respectively ()method.

 1 package wyyyy;
 2 public class person {
 3         String name;// 名字
 4         double height;// 身高
 5         int age;// 年龄
 6 
 7         person(String name, double height, int age) {
 8             this.name = name;
 9             this.height = height;
10             this.age = age;
11         }
12 
13         void sayHello() {
14             System.out.println("hello " + name+" "+height+"m"+" "+age+"岁");
15         }
16     }
 1 package wyyyy;
 2 
 3 public class Constructor {
 4 
 5     public static void main(String[] args) {
 6         // TODO Auto-generated method stub
 7         person a = new person("wangyuyan", 1.9, 20);
 8         person b = new person("meinv", 1.99, 18);
 9         a.sayHello();
10         b.sayHello();
11 
12     }
13 
14

 

Guess you like

Origin www.cnblogs.com/WangYYY/p/12759832.html