用java创建一个学生类 急急急 30
建立一个学生类,其中成员变量为学号,姓名及三门课成绩。另外建立一个包含主方法的类,定义两个学生类的对象,求出这两个学生三门课总分的最高分,并将最高分的这个学生的信息输出。...
建立一个学生类,其中成员变量为学号,姓名及三门课成绩。另外建立一个包含主方法的类,定义两个学生类的对象,求出这两个学生三门课总分的最高分,并将最高分的这个学生的信息输出。
展开
4个回答
展开全部
public class TestStu {
/**
* @param args
*/
public static void main(String[] args) {
Student s1 = new Student("001","Jack",56,70,80);
Student s2 = new Student("007","Lucy",90,80,70);
float result1 = s1.getChinese()+s1.getEnglish()+s1.getMath();
float result2 = s2.getChinese()+s2.getEnglish()+s2.getMath();
if(result1>result2){
System.out.println(s1.toString());
}else{
System.out.println(s2.toString());
}
}
}
class Student{
private String id;
private String name;
private float chinese;
private float english;
private float math;
public Student(){}
public Student(String id,String name,float chinese,float english,float math){
this.id=id;
this.name=name;
this.chinese=chinese;
this.english=english;
this.math=math;
}
public float getChinese() {
return chinese;
}
public void setChinese(float chinese) {
this.chinese = chinese;
}
public float getEnglish() {
return english;
}
public void setEnglish(float english) {
this.english = english;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public float getMath() {
return math;
}
public void setMath(float math) {
this.math = math;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String toString(){
return "id:"+id+"\n name:"+"\n chinese:"+chinese+"\n english:"+english+"\n math:"+math;
}
}
/**
* @param args
*/
public static void main(String[] args) {
Student s1 = new Student("001","Jack",56,70,80);
Student s2 = new Student("007","Lucy",90,80,70);
float result1 = s1.getChinese()+s1.getEnglish()+s1.getMath();
float result2 = s2.getChinese()+s2.getEnglish()+s2.getMath();
if(result1>result2){
System.out.println(s1.toString());
}else{
System.out.println(s2.toString());
}
}
}
class Student{
private String id;
private String name;
private float chinese;
private float english;
private float math;
public Student(){}
public Student(String id,String name,float chinese,float english,float math){
this.id=id;
this.name=name;
this.chinese=chinese;
this.english=english;
this.math=math;
}
public float getChinese() {
return chinese;
}
public void setChinese(float chinese) {
this.chinese = chinese;
}
public float getEnglish() {
return english;
}
public void setEnglish(float english) {
this.english = english;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public float getMath() {
return math;
}
public void setMath(float math) {
this.math = math;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String toString(){
return "id:"+id+"\n name:"+"\n chinese:"+chinese+"\n english:"+english+"\n math:"+math;
}
}
展开全部
//学生类
public class Student{
private String stu_id;
private String stu_name;
private float math;
private float chinese;
private float computer;
public void setStu_id(String stu_id){
this.stu_id=stu_id;
}
public String getStu_id(){
return stu_id;
}
public void setStu_name(String stu_name){
this.stu_name=stu_name;
}
public String getStu_name(){
return stu_name;
}
public void setMath(float math){
this.math=math;
}
public float getMath(){
return math;
}
public void setChinese(float chinese){
this.chinese=chinese;
}
public float getChinese(){
return chinese;
}
public void setComputer(float computer){
this.computer=computer;
}
public float getComputer(){
return computer;
}
}
//主方法的类
public class Start{
public static void main(String[] args){
Student stu1=new Student();
stu1.setStu_id("No1");
stu1.setStu_name("张三");
stu1.setMath(89.5f);
stu1.setChinese(70f);
stu1.setComputer(98f);
Student stu2=new Student();
stu2.setStu_id("No2");
stu2.setStu_name("李四");
stu2.setMath(79.5f);
stu2.setChinese(90f);
stu2.setComputer(68f);
float stu1Sum = stu1.getMath()+stu1.getChinese()+stu1.getComputer();
float stu2Sum = stu2.getMath()+stu2.getChinese()+stu2.getComputer();
if(stu1Sum > stu2Sum){
System.out.println ("总分最高分为:"+stu1Sum);
System.out.println ("学号:"+stu1.getStu_id());
System.out.println ("姓名:"+stu1.getStu_name());
System.out.println ("数学:"+stu1.getMath());
System.out.println ("语文:"+stu1.getChinese());
System.out.println ("计算机:"+stu1.getComputer());
}else if(stu1Sum < stu2Sum){
System.out.println ("总分最高分为:"+stu2Sum);
System.out.println ("学号:"+stu2.getStu_id());
System.out.println ("姓名:"+stu2.getStu_name());
System.out.println ("数学:"+stu2.getMath());
System.out.println ("语文:"+stu2.getChinese());
System.out.println ("计算机:"+stu2.getComputer());
}else{
System.out.println ("总分一样高为:"+stu1Sum);
System.out.println ("学号:"+stu1.getStu_id());
System.out.println ("姓名:"+stu1.getStu_name());
System.out.println ("数学:"+stu1.getMath());
System.out.println ("语文:"+stu1.getChinese());
System.out.println ("计算机:"+stu1.getComputer());
System.out.println ("学号:"+stu2.getStu_id());
System.out.println ("姓名:"+stu2.getStu_name());
System.out.println ("数学:"+stu2.getMath());
System.out.println ("语文:"+stu2.getChinese());
System.out.println ("计算机:"+stu2.getComputer());
}
}
}
希望对你有帮助!
public class Student{
private String stu_id;
private String stu_name;
private float math;
private float chinese;
private float computer;
public void setStu_id(String stu_id){
this.stu_id=stu_id;
}
public String getStu_id(){
return stu_id;
}
public void setStu_name(String stu_name){
this.stu_name=stu_name;
}
public String getStu_name(){
return stu_name;
}
public void setMath(float math){
this.math=math;
}
public float getMath(){
return math;
}
public void setChinese(float chinese){
this.chinese=chinese;
}
public float getChinese(){
return chinese;
}
public void setComputer(float computer){
this.computer=computer;
}
public float getComputer(){
return computer;
}
}
//主方法的类
public class Start{
public static void main(String[] args){
Student stu1=new Student();
stu1.setStu_id("No1");
stu1.setStu_name("张三");
stu1.setMath(89.5f);
stu1.setChinese(70f);
stu1.setComputer(98f);
Student stu2=new Student();
stu2.setStu_id("No2");
stu2.setStu_name("李四");
stu2.setMath(79.5f);
stu2.setChinese(90f);
stu2.setComputer(68f);
float stu1Sum = stu1.getMath()+stu1.getChinese()+stu1.getComputer();
float stu2Sum = stu2.getMath()+stu2.getChinese()+stu2.getComputer();
if(stu1Sum > stu2Sum){
System.out.println ("总分最高分为:"+stu1Sum);
System.out.println ("学号:"+stu1.getStu_id());
System.out.println ("姓名:"+stu1.getStu_name());
System.out.println ("数学:"+stu1.getMath());
System.out.println ("语文:"+stu1.getChinese());
System.out.println ("计算机:"+stu1.getComputer());
}else if(stu1Sum < stu2Sum){
System.out.println ("总分最高分为:"+stu2Sum);
System.out.println ("学号:"+stu2.getStu_id());
System.out.println ("姓名:"+stu2.getStu_name());
System.out.println ("数学:"+stu2.getMath());
System.out.println ("语文:"+stu2.getChinese());
System.out.println ("计算机:"+stu2.getComputer());
}else{
System.out.println ("总分一样高为:"+stu1Sum);
System.out.println ("学号:"+stu1.getStu_id());
System.out.println ("姓名:"+stu1.getStu_name());
System.out.println ("数学:"+stu1.getMath());
System.out.println ("语文:"+stu1.getChinese());
System.out.println ("计算机:"+stu1.getComputer());
System.out.println ("学号:"+stu2.getStu_id());
System.out.println ("姓名:"+stu2.getStu_name());
System.out.println ("数学:"+stu2.getMath());
System.out.println ("语文:"+stu2.getChinese());
System.out.println ("计算机:"+stu2.getComputer());
}
}
}
希望对你有帮助!
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
主方法的类:
public class DriverStudent {
public static void main(String[] args){
Student s1 = new Student();
Student s2 = new Student();
float sum1,sum2;
s1.setId("001");
s1.setName("学生甲");
s1.setScore(70.5f,75.0f,87.0f);
s2.setId("002");
s2.setName("学生乙");
s2.setScore(89.5f,61.0f,92.0f);
sum1 = s1.getSum();
sum2 = s2.getSum();
if(sum1 > sum2){
System.out.println(s1.getInfo());
}else if(sum1 < sum2){
System.out.println(s2.getInfo());
}else{
System.out.println("The two students got same sum scores."+s1.getSum());
System.out.println(s1.getInfo());
System.out.println(s2.getInfo());
}
}
}
-----------------------------------------------------------------------
学生类
public class Student {
private String id;
private String name;
private int size = 3;
private float[] score;
public Student(){
size =3;
score = new float[size];
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public float[] getScore() {
return score;
}
public void setScore(float a,float b,float c) {
score[0] = a;
score[1] = b;
score[2] = c;
}
public float getSum(){
float sum = 0;
for(int i = 0; i<size;i++){
sum += score[i];
}
return sum;
}
public String getInfo(){
return "ID = "+ id +" Name = " + name + " sum ="+ this.getSum();
}
}
public class DriverStudent {
public static void main(String[] args){
Student s1 = new Student();
Student s2 = new Student();
float sum1,sum2;
s1.setId("001");
s1.setName("学生甲");
s1.setScore(70.5f,75.0f,87.0f);
s2.setId("002");
s2.setName("学生乙");
s2.setScore(89.5f,61.0f,92.0f);
sum1 = s1.getSum();
sum2 = s2.getSum();
if(sum1 > sum2){
System.out.println(s1.getInfo());
}else if(sum1 < sum2){
System.out.println(s2.getInfo());
}else{
System.out.println("The two students got same sum scores."+s1.getSum());
System.out.println(s1.getInfo());
System.out.println(s2.getInfo());
}
}
}
-----------------------------------------------------------------------
学生类
public class Student {
private String id;
private String name;
private int size = 3;
private float[] score;
public Student(){
size =3;
score = new float[size];
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public float[] getScore() {
return score;
}
public void setScore(float a,float b,float c) {
score[0] = a;
score[1] = b;
score[2] = c;
}
public float getSum(){
float sum = 0;
for(int i = 0; i<size;i++){
sum += score[i];
}
return sum;
}
public String getInfo(){
return "ID = "+ id +" Name = " + name + " sum ="+ this.getSum();
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
public class Train009
{
public static void main(String args[])
{
Student studentA=new Student();
Student studentB=new Student();
Student studentC=new Student();
studentA.name="A";
studentA.number="001";
studentA.scoreA=97;
studentA.scoreB=93;
studentA.scoreC=93;
studentB.name="B";
studentB.number="002";
studentB.scoreA=89;
studentB.scoreB=83;
studentB.scoreC=83;
double AllscoreA,AllscoreB;
AllscoreA=studentA.scoreA+studentA.scoreB+studentA.scoreC;
AllscoreB=studentB.scoreA+studentB.scoreB+studentB.scoreC;
if(AllscoreA>AllscoreB)
{
System.out.println("name:"+studentA.name+"\t"+"number:"+studentA.number+"\t"+"all score:"+AllscoreA);
}
else
System.out.println("name:"+studentB.name+"\t"+"number:"+studentB.number+"\t"+"all score:"+AllscoreB);
}
}
class Student
{
String name,number;
double scoreA,scoreB,scoreC;
}
{
public static void main(String args[])
{
Student studentA=new Student();
Student studentB=new Student();
Student studentC=new Student();
studentA.name="A";
studentA.number="001";
studentA.scoreA=97;
studentA.scoreB=93;
studentA.scoreC=93;
studentB.name="B";
studentB.number="002";
studentB.scoreA=89;
studentB.scoreB=83;
studentB.scoreC=83;
double AllscoreA,AllscoreB;
AllscoreA=studentA.scoreA+studentA.scoreB+studentA.scoreC;
AllscoreB=studentB.scoreA+studentB.scoreB+studentB.scoreC;
if(AllscoreA>AllscoreB)
{
System.out.println("name:"+studentA.name+"\t"+"number:"+studentA.number+"\t"+"all score:"+AllscoreA);
}
else
System.out.println("name:"+studentB.name+"\t"+"number:"+studentB.number+"\t"+"all score:"+AllscoreB);
}
}
class Student
{
String name,number;
double scoreA,scoreB,scoreC;
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询