4.23 Computer operation

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 yu; 

public class hg { 
	String color; 
	int cpu; 
	public void show () { 
		System.out.println ("color is" + color + "model is" + cpu); 
	} 
	

}

  

package yu;

public class text {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		   hg R=new hg();
	        R.color="red";
	        R.cpu=999;
	        System.out.println("颜色为:"+R.color);
	        System.out.println("型号为:"+R.cpu);
	}

}

  

 

 

 

 

 

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 yu; 

public class hg { 
	double shenggao; 
	String name; 
	int year; 
	public void sayHello () { 
		System.out.println ("hello, my name is" + name); 
		System.out.println ("My age is "+ year); 
		System.out.println (" My height is "+ shenggao); 
	} 
	

}

  

package yu;

public class text {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		hg R1=new hg();
		R1.name="zhangshan";
		R1.shenggao=1.73;
		R1.year=33;
		System.out.println("hello,my name is "+R1.name);
		System.out.println("我的身高是"+R1.shenggao);
		System.out.println("我的年龄是"+R1.year);
		
		hg R2=new hg();
		R2.name="lishi";
		R2.shenggao=1.74;
		R2.year=44;
		System.out.println("hello,my name is "+R2.name);
		System.out.println("我的身高是"+R2.shenggao);
		System.out.println("我的年龄是"+R2.year);
		
	}

}

  

Guess you like

Origin www.cnblogs.com/wzj123/p/12759740.html