JAVA Week 8 Hands-on Practice

3. Define a notebook class with two attributes: color (char) and cpu model (int). 【Required Questions】

• 3.2 The method of outputting notebook information

• 3.3 Then write a test class to test the various methods of the notebook class.

package fs;
 public  class Bijiben {
      char color;
      int cpu;
    public  void showBijiben () { 
        System.out.println ( "notebook color:" + c olor); 
        System.out.println ( "notebook cpu model:" + c pu); 
    } 
    }
package fs;
public class Test {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        Bijiben c1= new Bijiben();
        c1.color='白';
        c1.cpu=32;
        c1.showBijiben();

    }

}

5. Define two categories, described as follows: [Mandatory questions]

• 5.1 Define a human Person:

• 5.1.1 defines a method sayHello () that can send a greeting “hello, my name is XXX” to the other party

• 5.1.2 has three attributes: name, height, weight

• 5.2 Define a PersonCreate class:

• 5.2.1 Create two objects, zhangsan, 33 years old, 1.73; lishi, 44, 1.74

• 5.2.2 Call the sayHello () method of the object separately.

package fs;

public class Person {
     String name;
     double shengao;
     double nianling;
     
     public void sayHello() {
         System.out.println("hello,ny name is "+name);
    }

}
package fs;

public class PersonCreate {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        Person p1 = new Person();
        Person p2 = new Person();     
        p1.name="zhangsan";
        p1.shengao=1.73;
        p1.nianling=33;
         
        p2.name="lishi";
        p2.shengao=1.74;
        p2.nianling=44;
         
        p1.sayHello();
        p2.sayHello();
 
    }
 
    }

Guess you like

Origin www.cnblogs.com/jisuanji-04/p/12759729.html