小菜鸟又来了 关于Java的一个函数问题

pasta_loveless 2008-08-05 05:41:40
在Student类中 大家仔细看看哈请问我这样写函数有错没?

import java.util.Scanner;
public class Student{ // 定义一个学生类 该类包括学生姓名 性别 成绩三个属性

private String name;
private String sex;
private float score;
public Student(){

}



public Student(String name,String sex,float score){
this.name=name;
this.sex=sex;
this.score=score;
}

public String getName(){
return name;
}
public String getSex(){
return sex;
}
public float getScore(){
return score;
}
public void getMax(int length, Student [] std){//获取最高分的方法
float max;
max=std[0].getScore();

for(int i=0;i <length;i++){

if(std[i].getScore()>max){

max=std[i].getScore();

}
System.out.println("最大值为:"+max);
}
}
public void getMin(int length,Student [] std){ //获取最低分的方法
float min;
min=std[0].getScore();
for(int i=0;i <std.length;i++){

if(std[i].getScore() <min){

min=std[i].getScore();

}





}
System.out.println("最小值为:"+min);
}

public void Delete(int length,Student []std){ // 删除某个学生信息的方法
int index=0,i=0;
length--;
System.out.println("请输入要删除的学生姓名:");
Scanner S=new Scanner(System.in);
String name=S.next();
for(;i <length;i++){
if(name==std[i].getName())
index=i;break;
}
if(i <length){


for( i=index;i <length;i++){
std[i]=std[i+1];
}

}

else
System.out.println("你忽悠我啊!");

}




public void Add(int length,Student []std){ //增加某个学生信息的方法
int index=0 ,i=0;
length++;
Scanner S=new Scanner(System.in);
System.out.println("请输入要添加的学生的信息:");
String name=S.next();
String sex=S.next();
float score=S.nextFloat();
Student goodboy=new Student(name,sex,score);
for(;i <length;i++){
if(goodboy.getScore()>std[i].getScore())
index=i;break;
}
if(i==length-1){
std[length]=goodboy;



}
else{
for( i=length-1;i>=index;i--){
std[i+1]=std[i];
}
std[i]=goodboy;

}

}
public void reSearch(int length,Student []std){ //查找某个学生信息的方法
Scanner S=new Scanner(System.in);
System.out.println("请输入要查找到学生姓名:");
String name=S.next();
for(int i=0;i <length;i++){
if(std[i].getName()==name){
System.out.println("改学生的具体信息如下:");
std[i].disPlay();

}
else
System.out.println("查无此人!");

}

}

public void Change(int length,Student []std){ //更改某个学生信息的方法
Scanner S=new Scanner(System.in);
System.out.println("请输入你要更改的学生姓名");
String name1=S.next();
for(int i=0;i <length;i++){
if(std[i].getName()==name){
String name=S.next();
String sex=S.next();
float score=S.nextFloat();
std[i]=new Student(name,sex,score);

}
}


}
public void Sort(int length ,Student []std){ //按照成绩降序来排序
int i,j;
Student jack=new Student();
for(i=0;i <length;i++){
for(j=0;j <length-1-i;j++){
if(std[j].getScore() <std[j+1].getScore())
jack=std[j];
std[j]=std[j+1];
std[j+1]=jack;

}
}
}
public void disPlay(){ // 输出函数
System.out.println("姓名:"+name+"性别:"+sex+"成绩:"+score);
}
}



--------------------------------------------------------------------
以下内容为自动编辑的内容,并非楼主的发贴内容,此仅用于显示而已,并无任何其他特殊作用
楼主【pasta_loveless】截止到2008-08-05 17:41:49的历史汇总数据(不包括此帖):
发帖的总数量:19 发帖的总分数:720 每贴平均分数:37
回帖的总数量:6 得分贴总数量:0 回帖的得分率:0%
结贴的总数量:17 结贴的总分数:670
无满意结贴数:2 无满意结贴分:80
未结的帖子数:2 未结的总分数:50
结贴的百分比:89.47 % 结分的百分比:93.06 %
无满意结贴率:11.76 % 无满意结分率:11.94 %
楼主加油

取消马甲机器人,请点这里:http://www.java2000.net/mycsdn/robotStop.jsp?usern=pasta_loveless
...全文
152 16 打赏 收藏 转发到动态 举报
写回复
用AI写文章
16 条回复
切换为时间正序
请发表友善的回复…
发表回复
chinamickey 2008-09-04
  • 打赏
  • 举报
回复
错误很多,修改后如下:

package package2;

import java.util.Scanner;

public class Student { // 定义一个学生类 该类包括学生姓名 性别 成绩三个属性

private String name;

private String sex;

private float score;

public Student() {

}

public Student(String name, String sex, float score) {
this.name = name;
this.sex = sex;
this.score = score;
}

public String getName() {
return name;
}

public String getSex() {
return sex;
}

public float getScore() {
return score;
}

public static void getMax(int length, Student[] std) {// 获取最高分的方法
float max;
if (null == std) {
throw new NullPointerException();
}
max = std[0].getScore();

for (int i = 1; i < length; i++) {

if (std[i].getScore() > max) {

max = std[i].getScore();

}
System.out.println("最大值为:" + max);
}
}

public static void getMin(int length, Student[] std) { // 获取最低分的方法
if (null == std) {
throw new NullPointerException();
}
float min;
min = std[0].getScore();
for (int i = 1; i < std.length; i++) {

if (std[i].getScore() < min) {

min = std[i].getScore();

}

}
System.out.println("最小值为:" + min);
}

public static void Delete(Student[] std) { // 删除某个学生信息的方法
if (null == std) {
throw new NullPointerException();
}
int index = 0, i = 0;
System.out.println("请输入要删除的学生姓名:");
Scanner S = new Scanner(System.in);
String name1 = S.next();
for (; i < std.length; i++) {
if (name1 == std[i].getName()) {
index = i;
break;
}
}
if (i < std.length) {

for (i = index; i < std.length; i++) {
std[i] = std[i + 1];
}

}

else
System.out.println("你忽悠我啊!");

}

public static void Add(Student[] std) { // 增加某个学生信息的方法
if (null == std) {
throw new NullPointerException();
}
int index = 0, i = 0;
Scanner S = new Scanner(System.in);
System.out.println("请输入要添加的学生的信息:");
String name = S.next();
String sex = S.next();
float score = S.nextFloat();
Student goodboy = new Student(name, sex, score);
Student[] tempStd = new Student[std.length + 1];

for (; i < std.length; i++) {
if (goodboy.getScore() > std[i].getScore()) {
index = i;
break;
}
tempStd[i] = std[i];
}
tempStd[index] = goodboy;
for (i = index; i < std.length; i++) {
tempStd[i + 1] = std[i];
}
std = tempStd;
}

public static void reSearch(int length, Student[] std) { // 查找某个学生信息的方法
if (null == std) {
throw new NullPointerException();
}
Scanner S = new Scanner(System.in);
System.out.println("请输入要查找到学生姓名:");
String name1 = S.next();
for (int i = 0; i < length; i++) {
if (std[i].getName() == name1) {
System.out.println("改学生的具体信息如下:");
std[i].disPlay();

} else
System.out.println("查无此人!");

}

}

public static void Change(int length, Student[] std) { // 更改某个学生信息的方法
if (null == std) {
throw new NullPointerException();
}
Scanner S = new Scanner(System.in);
System.out.println("请输入你要更改的学生姓名");
String name1 = S.next();
for (int i = 0; i < length; i++) {
if (std[i].getName() == name1) {
String name = S.next();
String sex = S.next();
float score = S.nextFloat();
std[i] = new Student(name, sex, score);
break;
}
}

}

public static void Sort(int length, Student[] std) { // 按照成绩降序来排序
if (null == std) {
throw new NullPointerException();
}
int i, j;
Student jack = new Student();
for (i = 0; i < length; i++) {
for (j = i; j < length; j++) {
if (std[i].getScore() < std[j].getScore())
{
jack = std[i];
std[i] = std[j];
std[j] = jack;
}

}
}
}

public void disPlay() { // 输出函数
System.out.println("姓名:" + name + "性别:" + sex + "成绩:" + score);
}
}
rabbit_zizhu 2008-08-31
  • 打赏
  • 举报
回复
没看完,看到这里发先一个问题。

public void getMax(int length, Student [] std){//获取最高分的方法
float max;
max=std[0].getScore();

for(int i=0;i <length;i++){ //这里应该是i <std.length吧
if(std[i].getScore()>max){

max=std[i].getScore();

}
System.out.println("最大值为:"+max);
}
}
whatwhyhope 2008-08-28
  • 打赏
  • 举报
回复
没有main函数,需要添加一个public static void main(String[] args){ ....}
throad0 2008-08-27
  • 打赏
  • 举报
回复
在修改信息时,
String name1=S.next();
for(int i=0;i <length;i++){
if(std[i].getName()==name){
好像有点问题。


我也是一个菜鸟,以上仅为个人看法阿!!
volcanofifa 2008-08-27
  • 打赏
  • 举报
回复
總之寫的很亂,類有自己的行為,比如人可以走,跑,跳,但是從一堆人中挑出最高的一個來,恐怕不應該算是一個人的行為。
不夠規范,建議重新構造一次你的程序。
hanxueyuwulei 2008-08-25
  • 打赏
  • 举报
回复
楼上真强悍
没有MAIN()方法
我都不知道程序怎么运行的
hunterzhang0812 2008-08-21
  • 打赏
  • 举报
回复
没MAIN方法.
ljh0242 2008-08-21
  • 打赏
  • 举报
回复
好像没有错,编译下,巴错误报出来啊
ncm0227120 2008-08-18
  • 打赏
  • 举报
回复
没有main 函数啊
sasgsc 2008-08-05
  • 打赏
  • 举报
回复
eclipse
找个IDE,就不会出现书写错误了
wufongming 2008-08-05
  • 打赏
  • 举报
回复
没有入口函数,不知道程序从哪开始运行
public static void main()
JAVA_mentu 2008-08-05
  • 打赏
  • 举报
回复
java.lang.NoSuchMethodError: main
Exception in thread "main"


没有 main 函数 ?不懂
panweijian 2008-08-05
  • 打赏
  • 举报
回复
setXXX(){}
Binculturetimes 2008-08-05
  • 打赏
  • 举报
回复
没有错吧,你可以调试一下,就知道那错了
dongqdonglin 2008-08-05
  • 打赏
  • 举报
回复
你那里出错了?

51,407

社区成员

发帖
与我相关
我的任务
社区描述
Java相关技术讨论
javaspring bootspring cloud 技术论坛(原bbs)
社区管理员
  • Java相关社区
  • 小虚竹
  • 谙忆
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧