On the machine 8

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 .

package ww;

public class aa {
    char cl;
    int cpu;
    public char getCl(){
        return cl;
    }
    public void setCl(char cl){
        this.cl=cl;
    }
    public int getCpu(){
        return cpu;
    }
    public void setCpu(int cpu){
        this.cpu=cpu;
    }
    public void shoubjb(){
        System.out.println ( "Color:" + cl + "cpu model:" + cpu); 
    } 
}
package ww;

public class wdw {
    public static void main(String[] args) {
        aa r=new aa();
        r.setCpu(4);
        r.setCl('红');
        r.shoubjb();
        }
}

 

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 weight
• 5.2 defines a PersonCreate class:
• 5.2.1 creates two objects, namely zhangsan, 33 years old, 1.73
; lisi, 44, 1.74
• 5.2.2 calls the sayHello of the objects respectively ()method.

package ww;

public class PERSON {
    String name;
    double sg;
    int nl;
    public void sayHello(){
        System.out.println("hello,my name is"+name);
    }
    public void show(){
        System.out.println("身高"+sg);
        System.out.println("年龄"+nl);
    }
}
package ww;

public class RESONCREATE {
    public static void main(String[] args){
        PERSON r=new PERSON();
        PERSON r1=new PERSON();
        r.name="***";
        r.sg=1.73;
        r.nl=33;
        r1.name="xxx";
        r1.sg=1.74;
        r1.nl=44;
        r.sayHello();
        r.show();
        r1.sayHello();
        r1.show();
    }
}

 

 

Guess you like

Origin www.cnblogs.com/risktt/p/12759730.html