下面是我编写的程序class Student
{
private String name;
private float englishScore;
private float computerScore;
private float historyScore;
private float mathematicsScore;
public void setname(String s)
{
this.name=s;
}
public void setenglishScore(float n)
{
this.englishScore=n;
}
public void setcomputerScore(float n)
{
this.computerScore=n;
}
public void sethistoryScore(float n)
{
this.historyScore=n;
}
public void setmathematicsScore(float n)
{
this.mathematicsScore=n;
}
public String getname()
{
return this.name;
}
public float getenglishScore()
{
return this.englishScore;
}
public float getcomputerScore()
{
return this.computerScore;
}
public float gethistoryScore()
{
return this.historyScore;
}
public float getmathematicsScore()
{
return this.mathematicsScore;
}
public Student(String s)
{
this.setname(s);
}
public float totalScore()
{
float total=this.getenglishScore()+this.getcomputerScore()+this.gethistoryScore()+this.getmathematicsScore();
return total;
}
public float avarageScore()
{
float total=this.getenglishScore()+this.getcomputerScore()+this.gethistoryScore()+this.getmathematicsScore();
float avarage=total/4;
return avarage;
}
public float highScore()
{
float high;
if (this.getenglishScore()>this.getcomputerScore())
{
high=this.getenglishScore();
}else
{
high=this.getcomputerScore();
}
if (high<this.gethistoryScore())
{
high=gethistoryScore();
}
if (high<this.getmathematicsScore())
{
high=getmathematicsScore();
}
return high;
}
public float lowScore()
{
float low;
if (this.getenglishScore()<this.getcomputerScore())
{
low=this.getenglishScore();
}else
{
low=this.getcomputerScore();
}
if (low>this.gethistoryScore())
{
low=gethistoryScore();
}
if (low>this.getmathematicsScore())
{
low=getmathematicsScore();
}
return low;
}
public void PrintStudentInformation()
{
System.out.println("姓名:"+this.getname()+"   英语成绩:"+this.getenglishScore()+"   计算机成绩:"+this.getcomputerScore()+
                 "    历史成绩"+this.gethistoryScore()+"    数学成绩"+this.getmathematicsScore());
System.out.println("总成绩:"+this.totalScore()+"平均成绩:"+this.avarageScore()+"最高分:"+this.highScore()+"最低分:"+this.lowScore());
}}public class Hello{
public static void main(String arg[]){
Student student1=null;
student1=new Student("sun");
student1.setenglishScore(90.5f);
student1.setcomputerScore(93.5f);
student1.sethistoryScore(88.0f);
student1.setmathematicsScore(99.0f);
student1.PrintStudentInformation();
}
};编译之后文件下面有hello.class与student.class文件,以上程序在Netbeans中可以正确编译与运行,但是在命令行下可以编译通过,运行部了

解决方案 »

  1.   

    楼主你好:
    student.java   class Student
    {
    private String name;
    private float englishScore;
    private float computerScore;
    private float historyScore;
    private float mathematicsScore;
    public void setname(String s)
    {
    this.name=s;
    }
    public void setenglishScore(float n)
    {
    this.englishScore=n;
    }
    public void setcomputerScore(float n)
    {
    this.computerScore=n;
    }
    public void sethistoryScore(float n)
    {
    this.historyScore=n;
    }
    public void setmathematicsScore(float n)
    {
    this.mathematicsScore=n;
    }
    public String getname()
    {
    return this.name;
    }
    public float getenglishScore()
    {
    return this.englishScore;
    }
    public float getcomputerScore()
    {
    return this.computerScore;
    }
    public float gethistoryScore()
    {
    return this.historyScore;
    }
    public float getmathematicsScore()
    {
    return this.mathematicsScore;
    }
    public Student(String s)
    {
    this.setname(s);
    }
    public float totalScore()
    {
    float total=this.getenglishScore()+this.getcomputerScore()+this.gethistoryScore()+this.getmathematicsScore();
    return total;
    }
    public float avarageScore()
    {
    float total=this.getenglishScore()+this.getcomputerScore()+this.gethistoryScore()+this.getmathematicsScore();
    float avarage=total/4;
    return avarage;
    }
    public float highScore()
    {
    float high;
    if (this.getenglishScore()>this.getcomputerScore())
    {
    high=this.getenglishScore();
    }else
    {
    high=this.getcomputerScore();
    }
    if (high<this.gethistoryScore())
    {
    high=gethistoryScore();
    }
    if (high<this.getmathematicsScore())
    {
    high=getmathematicsScore();
    }
    return high;
    }
    public float lowScore()
    {
    float low;
    if (this.getenglishScore()<this.getcomputerScore())
    {
    low=this.getenglishScore();
    }else
    {
    low=this.getcomputerScore();
    }
    if (low>this.gethistoryScore())
    {
    low=gethistoryScore();
    }
    if (low>this.getmathematicsScore())
    {
    low=getmathematicsScore();
    }
    return low;
    }
    public void PrintStudentInformation()
    {
    System.out.println("姓名:"+this.getname()+"   英语成绩:"+this.getenglishScore()+"   计算机成绩:"+this.getcomputerScore()+
                     "    历史成绩"+this.gethistoryScore()+"    数学成绩"+this.getmathematicsScore());
    System.out.println("总成绩:"+this.totalScore()+"平均成绩:"+this.avarageScore()+"最高分:"+this.highScore()+"最低分:"+this.lowScore());
    }}2、hello.java   public class Hello{
    public static void main(String arg[]){
    Student student1=null;
    student1=new Student("sun");
    student1.setenglishScore(90.5f);
    student1.setcomputerScore(93.5f);
    student1.sethistoryScore(88.0f);
    student1.setmathematicsScore(99.0f);
    student1.PrintStudentInformation();
    }
    }如下:执行第一步:打开cmd用管理员权限执行哦!第二步:D:\testjava>javac student.java第三步:D:\testjava>javac hello.java第四步:D:\testjava>java Hello
      

  2.   

    感谢二楼,我发现我犯了两个错误CMD没有用管理员权限执行
    java Hello写出了java hellojava是大小写敏感的,我用hello,java就找不到hello主类,因为主类是Hello