在线等,急!用JAVA编写程序,题目如下:
发布网友
发布时间:2022-06-01 19:28
我来回答
共1个回答
热心网友
时间:2023-10-13 11:49
package com.example;
/**
1.利用学号和姓名处理基本信息:
(1)输出:姓名,校名,专业,年级(学号中第10位为专业位,1表示语文,2表示数学,3表示英语)。
格式为:姓名:小明,A大学 数学 专业 2016级学生
(2)输出Email地址
格式为:姓名:小明 Email地址是:111111111311@mail.com
2.以1为父类定义子类实现成绩管理
利用语文、数学、英语成绩计算并输出
计算并输出语文、数学、英语三门课的成绩总分,最高分,最低分
输出格式为:学号: 姓名: 总分: 最高分: 最低分:
3.在main方法中使用实际的数据调用以上的功能
(生成一个对象是自己的姓名和学号)
*/
public class StudentScore extends Student {
//英语分数
private float enScore;
//语文分数
private float laScore;
//数学分数
private float maScore;
/**
* @param args
*/
public static void main(String[] args) {
StudentScore stu = new StudentScore();
stu.setStudentName("小明");
stu.setSchoolName("A大学");
stu.setGradeName(2016);
stu.setStudentID("2016061601");
stu.setEmail("111111111311@mail.com");
stu.setEnScore(90);
stu.setLaScore(80);
stu.setMaScore(70);
System.out.println(stu.printInfo());
System.out.println(stu.printEmail());
System.out.println(stu.printScore());
}
public float getEnScore() {
return enScore;
}
public void setEnScore(float enScore) {
this.enScore = enScore;
}
public float getLaScore() {
return laScore;
}
public void setLaScore(float laScore) {
this.laScore = laScore;
}
public float getMaScore() {
return maScore;
}
public void setMaScore(float maScore) {
this.maScore = maScore;
}
//最高分
public float maxScore(){
float maxScore = enScore;
if (laScore > maxScore) {
maxScore = laScore;
}
if (maScore > maxScore) {
maxScore = maScore;
}
return maxScore;
}
//最低分
public float minScore(){
float minScore = enScore;
if (laScore < minScore) {
minScore = laScore;
}
if (maScore < minScore) {
minScore = maScore;
}
return minScore;
}
//总分
public float totalScore(){
float totalScore = 0;
totalScore = enScore + laScore + maScore;
return totalScore;
}
public String printScore(){
StringBuffer strBuff =new StringBuffer();
strBuff.append("学号 :");
strBuff.append(studentID);
strBuff.append("姓名 :");
strBuff.append(studentName);
strBuff.append(" 总分:");
strBuff.append(totalScore());
strBuff.append(" 最高分:");
strBuff.append(maxScore());
strBuff.append(" 最低分:");
strBuff.append(minScore());
return strBuff.toString();
}
}
class Student {
//姓名
public String studentName;
//学号
public String studentID;
//年级
public int gradeName;
//学校名称
public String schoolName;
//电子邮箱
public String email;
public String getStudentName() {
return studentName;
}
public void setStudentName(String studentName) {
this.studentName = studentName;
}
public String getStudentID() {
return studentID;
}
public void setStudentID(String studentID) {
if(studentID.length()<10){
throw new RuntimeException("学号长度不够10位");
}
this.studentID = studentID;
}
public int getGradeName() {
return gradeName;
}
public void setGradeName(int gradeName) {
this.gradeName = gradeName;
}
public String getSchoolName() {
return schoolName;
}
public void setSchoolName(String schoolName) {
this.schoolName = schoolName;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
if(!email.contains("@")){
throw new RuntimeException("学号长度不够10位");
}
this.email = email;
}
public String printInfo(){
StringBuffer strBuff =new StringBuffer();
strBuff.append("姓名 :");
strBuff.append(studentName);
strBuff.append(",");
strBuff.append(schoolName);
strBuff.append(" ");
char type = studentID.charAt(9);
if(type == '1'){
strBuff.append("语文");
}else if(type == '2'){
strBuff.append("数学");
}else if(type == '3'){
strBuff.append("英语 ");
}
strBuff.append("专业 ");
strBuff.append(gradeName);
strBuff.append("级学生 ");
return strBuff.toString();
}
public String printEmail(){
StringBuffer strBuff =new StringBuffer();
strBuff.append("姓名 :");
strBuff.append(studentName);
strBuff.append(" ");
strBuff.append(" Email地址是:");
strBuff.append(email);
return strBuff.toString();
}
}