zoukankan      html  css  js  c++  java
  • 简单的方法使用案例4

    1、写一个学生的类,类中的属性学生的名字,学生的java成绩,学生的sql成绩,学生的C#成绩。类中有方法:
    (一)学生学习的方法,无返回,要求输出“学生在学习”。
    (二)返回学生姓名的方法。
    (三)返回学生java成绩的方法。
    (四)返回学生所有功课总成绩的方法。
    (五)返回学生把有功 课平均分的方法。

    public class Student {
    	//创建属性
    	String name;	
    	int java;	
    	int sql;	
    	int c;
    	//(一)学生学习的方法,无返回,要求输出“学生在学习”。
    	public void method1(){
    		System.out.println("学生在学习");
    		
    	}
    	//(二)返回学生姓名的方法。
        public String method2(){
    		return name;
    	}
        //(三)返回学生java成绩的方法。
        public int method3(){
        	return java;
    	
        }
        //(四)返回学生所有功课总成绩的方法。
        public int method4(){
        	int sum=java+sql+c;
        	return sum;
    	
        }
        //(五)返回学生把有功 课平均分的方法。
        public double method5(){
        	double ave;
        	ave=(java+sql+c)/3;
    		return ave;
    	}
    
    }
    

      

    public class demo1 {
    	public static void main(String[] args) {
    		//创建
    		Student student=new Student();
    		//赋值
    		student.name="小明";
    		student.c=80;
    		student.java=99;
    		student.sql=88;
    		//调用方法1
    		student.method1();
    		//接收方法并输出		
    		String a=student.method2();
    		System.out.println("姓名:"+a);
    		//方法3,4,5,同上
    		int b=student.method3();
    		System.out.println("java成绩:"+b);
    		int c=student.method4();
    		System.out.println("总成绩:"+c);
    		double d=student.method5();
    		System.out.println("平均分:"+d);
    	}
    
    }
    

      

  • 相关阅读:
    【Codeforces 1051D】Bicolorings
    【Codeforces 827B】High Load
    【Codeforces 1006D】Two Strings Swaps
    【Codeforces 1108E1】Array and Segments (Easy version)
    【Codeforces 1141E】Superhero Battle
    【Codeforces 1042D】Petya and Array
    springmvc jar包下载 提供地址
    tomcat 8 startup.bat启动乱码问题
    js 对象数组删除和查找的方法
    sql 获取每个分组的前N条记录的写法
  • 原文地址:https://www.cnblogs.com/www-x/p/8087827.html
Copyright © 2011-2022 走看看