JAVA on the eighth week

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 zuoye; import java.util.Scanner; public class arc{ public static
void main(String[] args){ Computer c1 = new Computer(); c1.showComputer(); Computer c2 = new Computer ('Red', 32 ); c2.showComputer(); } } class Computer{ private char color; private int cpu; public Computer(){ } public Computer(char color,int cpu){ this.color=color; this.cpu=cpu; } public char getColor(){ return color; } public void setColor(char color){ this.color=color; } public int getCpu(){ return cpu; } public void setCpu(int cpu){ this.cpu=cpu; } public void showComputer(){ System.out.println ( "Notebook color:" + getColor ()); System.out.println ( "Notebook CPU model:" + getCpu ()); } }

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 zuoye; public class person { String name;
int age; double height; person(String name,double d,double height){ this.name=name; this.age=age; this.height=height; } void sayHello(){ System.out.println("hello,my name is xx" ); System.out.println("name"+"height"+"age"); }
public class personCreate {

        public void main(String[] args) {
            person c1 = new person("zhangsan", 1.73, 33);
            person c2 = new person("lishi", 1.74, 44);

            c1.sayHello();
            c2.sayHello();
        }
    }
}

 

Guess you like

Origin www.cnblogs.com/z917/p/12759785.html