教育路上

全国站>Java>课堂作业>java子程序,作为主程序的一个类,等同于在后台为实现主程序
学员需求

java子程序,作为主程序的一个类,等同于在后台为实现主程序

摘要:java子程序,作为主程序的一个类,等同于在后台为实现主程序。以下是我们为大家整理的,相信大家阅读完后肯定有了自己的选择吧。

2023-09-08 09:30周子尧

发布时间:
2023-09-08 09:30
信息来源:
周子尧
浏览次数:
393
java子程序,作为主程序的一个类,等同于在后台为实现主程序

package 项目三;

public class Student1 {//子程序,作为主程序的一个类,等同于在后台为实现主程序
	private String name;//名字
	private float score1;
	private float score2;
	private float score3;//定义三科分数及类型
	float ave;
	float sum;
	
	void setname(String name) {
		thisname=name;
	}
	void setscore1(float score1) {
		thisscore1=score1;
	}
	void setscore2(float score2) {
		thisscore2=score2;
	}
	void setscore3(float score3) {
		thisscore3=score3;
	}
	String getname() {
		return name;
	}
	float getscore1() {
		return score1;
	}
	float getscore2() {
		return score2;
	}
	float getscore3() {
		return score3;
	}
	float getave(float ave) {
		thisave=ave;
		return ave;
	}
	float getsum(float sum) {
		thissum=sum;
		return sum;
	}
	
	Student1(){
		
	}
    Student1(String name,float score1,float score2,float score3){
		thisname=name;
		thisscore1=score1;
		thisscore2=score2;
		thisscore3=score3;
    	
	} void show() {
    	Systemoutprintln("姓名:"+name+" 语文成绩:"+score1+" 数学成绩"+score2+" 英语成绩:"+score3+" 平均分:"+ave+" 总分:"+sum);
    }
}//所有的this*,表示访问类中的成员变量,用来区分成员变量和局部变量
 //return表示返回指定类型的值

package 项目三;
import 项目三Student1;
public class Test1 {//主程序,用于实现相关的输出

	@SuppressWarnings("unused")
	public static void main(String[] args) {

		Student1 s1=new Student1("张三",905f,865f,695f);//张三数据
		s1show();
		Student1 s2=new Student1();
		s2setname("李四");//李四数据
		s2setscore1(805f);
		s2setscore2(925f);
		s2setscore3(955f);
		s2show();
		Student1 s3=new Student1("王五",935f,885f,935f);//王五数据
		s3show();
		
		float ave=(s1getscore1()+s1getscore2()+s1getscore3())/3;//计算平均分
		float sum=(s1getscore1()+s1getscore2()+s1getscore3());//计算总分	
	}//调用类中的数据实现功能
	

}

上一篇:
java定义一个Father类和Child类
下一篇:
java用构造方法算图形周长面积
标签:
网友评论
发布评论

访客的评论 2024/04/28 16:34

文中描述的是准确的吗,如何报名!

相关推荐
我也来发表评价关闭
我对该内容的评价:
0
评价500
验证码: 看不清 换一张
提交 (匿名发布,无须担心别人知道您的身份)
学校免费发布信息关闭
我们审核后会尽快展示,如有图片请发邮件到:edu63@foxmail.com

姓      名:

内      容:

手机号码:

验  证  码:  换一张

确认提交
填写需求信息关闭
我们会根据您的需求匹配并审核留言

姓      名:

意向城市:

留      言:

手机号码:

验  证  码:  换一张

确认提交
完善补充本文信息关闭
非常感谢您帮助完善补充本文信息


 换一张

确认提交