第八周上机

 

  

第一题无参

package test;

import java.util.Random;
import java.util.Scanner;

public class hhh {
	public static void main(String[] args) {
        // TODO Auto-generated method stub
		notebook r=new notebook();
		r.colourname='红';
		r.cpumodel=2;
		r.colour();
		r.cpu();
		  
	       
       
	}
}

  

package test;

public class notebook {
	char colourname;
	int cpumodel;
	public void colour(){
	System.out.println("颜色是"+colourname);
		
	}
	public void cpu(){
		System.out.println("型号是"+cpumodel);
	}

}

  

 

 

有参

 

package test;

import java.util.Random;
import java.util.Scanner;

public class hhh {
	public static void main(String[] args) {
        // TODO Auto-generated method stub
		notebook r=new notebook();
		r.colour('红');
		r.cpu(2);
	
       
	}
}

  

package test;

public class notebook {
	
public void colour(char colourname){
	System.out.println("颜色是"+colourname);
		
	}
	public void cpu(int cpumodel){
		System.out.println("型号是"+cpumodel);
	}

}

  测试类

package test;

import java.util.Random;
import java.util.Scanner;

public class hhh {
	public static void main(String[] args) {
        // TODO Auto-generated method stub
		notebook r=new notebook();
		r.colour('红');
		r.cpu(2);
	
		
	
       
	}
}

  

 第二题

package test;

public class person {
	String name;
	double height;
	double weight;
	public void sayhellow(){
		System.out.println("hellow,my name is"+name);
		
	}
	public void hhhhh(){
		System.out.println("名字是"+name);
		System.out.println("升高是"+height);
		System.out.println("体重是"+weight);
	}

}

  测试类

package test;

import java.util.Random;
import java.util.Scanner;

public class hhh {
	public static void main(String[] args) {
        // TODO Auto-generated method stub
		person r1=new person();
		person r2=new person();
		r1.height=1.73;
		r1.name="zhangsan";
		r1.weight=56.3;
		r2.name="lishi";
		r2.height=1.74;
		r2.weight=78.4;
		r1.sayhellow();
		r1.hhhhh();
		r2.sayhellow();
		r2.hhhhh();
	
		
		
		
	
       
	}
}

  

 

posted @ 2020-04-23 11:15  来咬我啊20675  阅读(90)  评论(0)    收藏  举报