package com.jredu.ch06; public class Students { //构造函数 float java; float c; float db; public Students(float java, float c, float db) { this.java = java; this.c = c; this.db = db; } }
package com.jredu.ch06; public class StudentsBiz { //定义方法 public float getAvg(Students students){ float avg = (students.c+students.db+students.java)/3; return avg; } }
package com.jredu.ch06; public class StudentsBizTese { public static void main(String[] args) { Students students = new Students(90,85,95); //创建Students类对象students并赋值 StudentsBiz studentsBiz = new StudentsBiz(); //创建StudentsBiz类对象studentsBiz //用对象studentsBiz调用getAvg方法赋值调用students类的值 float avg = studentsBiz.getAvg(students); System.out.println("平均分为:"+avg); } }