在Java中編寫程序,定義一個(gè)學(xué)生類,屬性包括姓名,學(xué)號(hào),語文成績,數(shù)學(xué)成績,英語成績,方法包括輸出數(shù)
public class Student(){
private int stuid; ? ? ? ? ? ? ? //學(xué)號(hào)
private String name; ? ? //姓名
private?double languagescore; ?//語文成績
private?double?mathscore; ?//數(shù)學(xué)成績
private?double?englishscore; ?//英語成績
?public int getStuid() {
? ? ? ? return stuid;
? ? }
? ? public void setStuid(int stuid) {
? ? ? ? this.stuid = stuid;
? ? }
? ? public String getName() {
? ? ? ? return name;
? ? }
? ? public void setName(String name) {
? ? ? ? this.name = name;
? ? }
? ? public double getLanguagescore() {
? ? ? ? return languagescore;
? ? }
? ? public void setLanguagescore(double languagescore) {
? ? ? ? this.languagescore = languagescore;
? ? }
? ? public double getMathscore() {
? ? ? ? return mathscore;
? ? }
? ? public void setMathscore(double mathscore) {
? ? ? ? this.mathscore = mathscore;
? ? }
? ? public double getEnglishscore() {
? ? ? ? return englishscore;
? ? }
? ? public void setEnglishscore(double englishscore) {
? ? ? ? this.englishscore = englishscore;
? ? }
public void total(){
System.out.println(總成績:+(this.languagescore+this.mathscore+this.englishscore));
}
public void avgscore(){
System.out.println(平均成績:+(this.languagescore+this.mathscore+this.englishscore)/3);
}
}
java編程問題(請(qǐng)直接給代碼)
public class Test {
public static void main(String[] args) {
Teacher teacher = new Teacher(Wang Laoshi, false, 19910123, qinghua, 3);
System.out.println(teacher.toString());
CollegeStudent collStu = new CollegeStudent(College Student, true, 19851231, Beijingdaxue,001, 2, Computer, 3);
System.out.println(collStu.toString());
MiddleSchStudent middStu = new MiddleSchStudent(Middle schoole student, false, 19910705, Di yi zhongxue, 002, 17, English, 5);
System.out.println(middStu.toString());
}
}
abstract class Person {
protected String name;
protected boolean sex;
protected int birthday;
public Person(){}
public Person(String name, boolean sex, int birthday){
this.name =name;
this.sex = sex;
this.birthday = birthday;
}
public String toString(){
return name: + name + , sex: + sex + , birthday: + birthday;
}
}
class Teacher extends Person{
private String school;
private int schoolType;
public Teacher(){
}
public Teacher(String name, boolean sex, int birthday, String school, int schoolType){
super(name, sex, birthday);
this.school = school;
this.schoolType = schoolType;
}
public String toString(){
return super.toString() + , school: + school + , school type: + schoolType;
}
}
abstract class Student extends Person{
protected String school;
protected String no;
protected int grade;
public Student(){
}
public Student(String name, boolean sex, int birthday, String school, String no, int grade){
super(name, sex, birthday);
this.school = school;
this.no = no;
this.grade = grade;
}
public String toString(){
return super.toString() + , school: + school + , student no: + no + , studeng grade: + grade;
}
}
class CollegeStudent extends Student{
private String major;
private int grade;
public CollegeStudent(){
}
public CollegeStudent(String name, boolean sex, int birthday, String school, String no, int grade, String major, int colledgeGrade){
super(name, sex, birthday,school, no,grade);
this.major = major;
this.grade = colledgeGrade;
}
public String toString(){
return super.toString() + , major: + major + , grade: + grade;
}
}
class MiddleSchStudent extends Student{
private int grade;
public MiddleSchStudent(){
}
public MiddleSchStudent(String name, boolean sex, int birthday, String school, String no, int grade, String major, int colledgeGrade){
super(name, sex, birthday,school, no,grade);
this.grade = colledgeGrade;
}
public String toString(){
return super.toString() + , grade: + grade;
}
}
---------------測試
name:Wang Laoshi, sex:false, birthday: 19910123, school: qinghua, school type: 3
name:College Student, sex:true, birthday: 19851231, school:Beijingdaxue, student no: 001, studeng grade: 2, major:Computer, grade: 3
name:Middle schoole student, sex:false, birthday: 19910705, school:Di yi zhongxue, student no: 002, studeng grade: 17, grade: 5
