Java作业考试真题
私串姓;//(学生的姓氏)
私有字符串firstName//(学生姓名)
private int assignment 1 mark;//(作业1的分数)
private int assignment2Mark//(作业2的分数)
private int assignment3Mark//(作业3的分数)
私有int examMark//(期末考试成绩)
公共编程2Student(){
assignment 1 mark = 0;
assignment 2 mark = 0;
assignment 3 mark = 0;
}
public Programming2Student(字符串名,字符串姓){
this();
this.firstName = name
this.surname =姓氏;
}
public Programming2Student(字符串名,字符串姓,int a1,int a2,int a3,int exam) {
这个(名,姓);
this . assignment 1 mark = a 1;
this . assignment 2 mark = a2;
this . assignment 3 mark = a3;
this.examMark =考试;
}
传递了公共布尔值(){
return((assignment 2 mark+assignment 3 mark)& gt;= 20)& amp;& amp((assignment 1 mark+exam mark)& gt;= 30);
}
公共字符串getGrade() {
布尔is passed = passed();
int sum = assignment 1 mark+assignment 2 mark+assignment 3 mark+exam mark;
if(sum & lt;40){
返回“F”;
} else if(sum & lt;50 | |(sum & gt;= 50 & amp& amp!isPassed)){
返回“MF”;
} else if(is passed & amp;& ampsum & gt= 50 & amp& ampsum & lt60){
返回“P”;
} else if(is passed & amp;& ampsum & gt= 60 & amp& ampsum & lt70){
返回“C”;
} else if(is passed & amp;& ampsum & gt= 70 & amp& ampsum & lt80){
返回“D”;
}否则{
返回“高清”;
}
}
公共字符串toString() {
最终字符串NEW _ LINE = " \ n
StringBuilder sb = new StringBuilder();
某人追加(姓)。追加(" ")。追加(名字)。append(NEW _ LINE);
sb . append(" \ tas assignment 1 ")。追加(" \t ")。追加(赋值1标记)。append(NEW _ LINE);
sb . append(" \ tas assignment 2 ")。追加(" \t ")。append(assignment2Mark)。append(NEW _ LINE);
sb . append(" \ tas assignment 3 ")。追加(" \t ")。append(assignment3Mark)。append(NEW _ LINE);
sb.append("\tExam ")。追加(" \t ")。追加(检查标记)。append(NEW _ LINE);
Sb追加(" \t等级")。追加(" \t ")。append(get grade());
return sb . tostring();
}
公共静态void main(String[] args) {
编程2Student韩梅梅=新编程2Student("梅梅","韩",0,8,16,34);
system . out . println(hanmeimei . tostring());
}
//成绩范围,比如min,你期末成绩是0,max期末成绩最多是50。
公共空集合(int grade,int min,int max)抛出异常{
如果(等级& lt最低||等级& gt最大){
抛出新异常(“等级无法设置,因为超出范围”);
}
}
public void set assignment 1 mark(int assignment 1 mark){
尝试{
set(assignment1Mark,0,50);
} catch(异常e) {
返回;
}
this . assignment 1 mark = assignment 1 mark;
}
public void set assignment 2 mark(int assignment 2 mark){
尝试{
set(assignment2Mark,0,50);
} catch(异常e) {
返回;
}
this . assignment 2 mark = assignment 2 mark;
}
public void set assignment 3 mark(int assignment 3 mark){
尝试{
set(assignment3Mark,0,50);
} catch(异常e) {
返回;
}
this . assignment 3 mark = assignment 3 mark;
}
public void setExamMark(int examMark){
尝试{
set(examMark,0,50);
} catch(异常e) {
返回;
}
this . exam mark = exam mark;
}
}
-很简单的基础,努力学习,考试成绩-
韩梅梅
分配1 0
分配2 8
分配3 16
考试34
p级