定义一个student类,其中有成员变量,学号,姓名,性别,是否为班干部,以及语文数学英语的分数,求成绩的方法。
定义一个主类,主方法中通过学生类创造对象,通过键盘输入学生的属性值,然后输出学生的属性值,调用方法输出该学生的总成绩和平均成绩。
JAVA类与对象 定义一个student类
- 写回答
- 好问题 0 提建议
- 追加酬金
- 关注问题
- 邀请回答
-
4条回答 默认 最新
关注 import java.util.Scanner; public class HelpOther { public static void main(String[] args) { Scanner scanner=new Scanner(System.in); System.out.println("请输入学生学号:"); String id=scanner.nextLine(); System.out.println("请输入学生姓名:"); String name=scanner.nextLine(); System.out.println("请输入学生性别(1:男生 0:女生):"); String isMan=scanner.nextLine(); boolean man=false; if(isMan.equals("1")){ man=true; } System.out.println("请输入学生是否领导(1:是 0:不是)"); String isLeader=scanner.nextLine(); boolean leader=false; if(isLeader.equals("1")){ leader=true; } System.out.println("请输入学生数学分数"); float mathScore=scanner.nextFloat(); System.out.println("请输入学生语文分数"); float chineseScore=scanner.nextFloat(); Student student=new Student(id,name,man,leader,mathScore,chineseScore); System.out.println(student.avScore); } } class Student { String id; //学号 String name;//姓名 boolean isMan;//是否男生 boolean isLeader;//是否领导 float mathScore;//数学分数 float chineseScore;//语文分数 float avScore;//平均成绩 public Student(String id ,String name,boolean isMan, boolean isLeader,float mathScore,float chineseScore){ this.id=id; this.name=name; this.isMan=isMan; this.isLeader=isLeader; this.mathScore=mathScore; this.chineseScore=chineseScore; //计算平均分数 this.avScore=(mathScore+chineseScore)/2; } }
如有帮助望采纳哈哈。
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决评论 打赏 举报无用 1
悬赏问题
- ¥15 如何在scanpy上做差异基因和通路富集?
- ¥20 关于#硬件工程#的问题,请各位专家解答!
- ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
- ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
- ¥30 截图中的mathematics程序转换成matlab
- ¥15 动力学代码报错,维度不匹配
- ¥15 Power query添加列问题
- ¥50 Kubernetes&Fission&Eleasticsearch
- ¥15 報錯:Person is not mapped,如何解決?
- ¥15 c++头文件不能识别CDialog