当前位置: 代码迷 >> Eclipse >> java 程序有关问题 请教如何修改?
  详细解决方案

java 程序有关问题 请教如何修改?

热度:23   发布时间:2016-04-23 13:34:46.0
java 程序问题 请问怎么修改??
import javax.swing.JOptionPane;
class Student{
int no,math,english,chengxu;
double zongfen;
int name;
void St(int no,int math,int english, int chengxu,int name)
{
this.no=no;
this.math=math;
this.english=english;
this.chengxu=chengxu;
this.name=name;
}
public double zongfen()
{
return(math+english+chengxu);
}
}
class banji extends Student
{ String name;
  int number;
  Student mate[];
  void ban(String name,int number)
  { this.name=name;
  this.number=number;
  mate=new Student[number];
  }
  }

public class a {
 public static void main(String args[]){
banji 软件工程=new banji();
软件工程.number=5;
for(int i=0;i<5;i++)

String stri=JOptionPane.showInputDialog("请输入学生学号: ");
软件工程.mate[i].no=Integer.parseInt(stri);
String str=JOptionPane.showInputDialog("请输入学生名字: ");
软件工程.mate[i].name=Integer.parseInt(str);
String st=JOptionPane.showInputDialog("请输入学生英语成绩: ");
软件工程.mate[i].english=Integer.parseInt(st);
String s=JOptionPane.showInputDialog("请输入学生数学成绩: ");
  软件工程.mate[i].math=Integer.parseInt(s);
  String m=JOptionPane.showInputDialog("请输入学生程序设计成绩: ");
软件工程.mate[i].chengxu=Integer.parseInt(m);
软件工程.zongfen();
}
for(int j=0;j<5;j++)
{
System.out.println(软件工程.mate[j].no+"/t"+软件工程.mate[j].name+"/t"+软件工程.mate[j].english+"/t"+软件工程.mate[j].math+"/t"+软件工程.mate[j].chengxu+"/t"+软件工程.zongfen());
 
 
}
 }
}

------解决方案--------------------
你这个程序的问题太多了,规范方面自己去注意吧!


Java code
    public static void main(String args[])    {        banji 软件工程 = new banji();                // 加上这句,初始化Student数组        软件工程.ban("123", 2);        for (int i = 0; i < 2; i++)        {                        // 每次用一个学生来存储数据            Student student = new Student();            String stri = JOptionPane.showInputDialog("请输入学生学号: ");            student.no = Integer.parseInt(stri);            String str = JOptionPane.showInputDialog("请输入学生名字: ");            student.name = Integer.parseInt(str);            String st = JOptionPane.showInputDialog("请输入学生英语成绩: ");            student.english = Integer.parseInt(st);            String s = JOptionPane.showInputDialog("请输入学生数学成绩: ");            student.math = Integer.parseInt(s);            String m = JOptionPane.showInputDialog("请输入学生程序设计成绩: ");            student.chengxu = Integer.parseInt(m);                        // 将数据存到数组中            软件工程.mate[i] = student;                    }        for (int j = 0; j < 2; j++)        {                          // "\t" 或者是"//t"            System.out.println(软件工程.mate[j].no + "\t" + 软件工程.mate[j].name + "//t" + 软件工程.mate[j].english + "//t"                    + 软件工程.mate[j].math + "//t" + 软件工程.mate[j].chengxu + "//t" + 软件工程.mate[j].zongfen());        }    }
------解决方案--------------------
班级为什么要继承学生?
------解决方案--------------------
Java code
import javax.swing.JOptionPane;class Student {    int no, math, english, chengxu;    double zongfen;    String name="";    public Student(){            }    public void St(int no, int math, int english, int chengxu, String name) {        this.no = no;        this.math = math;        this.english = english;        this.chengxu = chengxu;        this.name = name;    }    public double zongfen() {        return (math + english + chengxu);    }}class Banji{//继承去掉,逻辑就说不过去。要调用zongfen方法,直接调用mate中student对象的方法。    String name;    int number;    Student mate[];    public Banji(int number) {        this.number = number;        mate = new Student[number];    }    public Banji(String name, int number) {        this(number);        this.name = name;    }}public class a {    public static void main(String args[]) {        Banji 软件工程 = new Banji(5);        for (int i = 0; i < 5; i++) {            软件工程.mate[i] = new Student();//初始化student实例            String stri = JOptionPane.showInputDialog("请输入学生学号: ");            软件工程.mate[i].no = Integer.parseInt(stri);            String str = JOptionPane.showInputDialog("请输入学生名字: ");            软件工程.mate[i].name = str;//姓名也是int?倒是可以。。。            String st = JOptionPane.showInputDialog("请输入学生英语成绩: ");            软件工程.mate[i].english = Integer.parseInt(st);            String s = JOptionPane.showInputDialog("请输入学生数学成绩: ");            软件工程.mate[i].math = Integer.parseInt(s);            String m = JOptionPane.showInputDialog("请输入学生程序设计成绩: ");            软件工程.mate[i].chengxu = Integer.parseInt(m);        }        for (int j = 0; j < 5; j++) {            System.out.println(软件工程.mate[j].no + "\t" + 软件工程.mate[j].name                    + "\t" + 软件工程.mate[j].english + "\t" + 软件工程.mate[j].math                    + "\t" + 软件工程.mate[j].chengxu + "\t" + 软件工程.mate[j].zongfen()+"\n");        }    }}
  相关解决方案