java vector 查找_JAVA vector 的查询与删除

importjava.io.*;importjava.util.*;publicclassStudent{publicstaticfinalVectorvector=newVector(10,5);publicStudent(){}publicstaticvoidmain(String[]args){menu();inttag=10;ne...

import java.io.*;

import java.util.*;

public class Student

{

public static final Vector vector = new Vector(10,5);

public Student()

{

}

public static void main(String[] args)

{

menu();

int tag=10;

new Student();

while(true)

{

String s=readInput();

tag=Integer.parseInt(s);

switch(tag)

{

case 1:

{

query();

};break;

case 2:

{

add();

};break;

case 3:

{

delete();

};break;

case 4:

{

viewAll();

};break;

case 5:

{

System.exit(0);

};break;

}

}

}

public static String readInput()

{

try

{

BufferedReader in=new BufferedReader(new InputStreamReader(System.in));

return in.readLine();

}

catch(IOException e){}

return "";

}

public static void query()

{

System.out.println("please input the student's ID.:");

}

public static void add()

{

}

public static void delete()

{

System.out.println("\t input the ID you want to delete:");

String i=readInput();

}

public static void viewAll()

{

vector.add(new Student1("001","a.mo",90,89));

vector.add(new Student1("002","b.mo",90,47));

vector.add(new Student1("003","c.mo",99,56));

for(int i=0;i

{

Student1 student = (Student1)vector.get(i);

System.out.println("\tID:"+student.getId());

System.out.println("\tname:"+student.getName());

System.out.println("\tMath:"+student.getScore());

System.out.println("\tEnglish:"+student.getScore1()+"\n");

}

menu();

}

public static void menu()

{

System.out.println("\t welcome to my student's score system!");

System.out.println("\t*********************************************");

System.out.println("\t************* 1.Query ****************");

System.out.println("\t************* 2.Add ****************");

System.out.println("\t************* 3.Delete ****************");

System.out.println("\t************* 4.View All ****************");

System.out.println("\t************* 5.Exit ****************");

System.out.println("\t*********************************************");

}

}

class Student1

{

private String id;

private String name;

private float score;

private float score1;

public Student1(String id,String name,float score,float score1)

{

this.name = name;

this.id = id;

this.score = score;

this.score1 = score1;

}

public String getId()

{

return id;

}

public String getName()

{

return name;

}

public float getScore()

{

return score;

}

public float getScore1()

{

return score1;

}

public void setId(String id)

{

this.id = id;

}

public void setName(String name)

{

this.name = name;

}

public void setScore(float score)

{

this.score = score;

}

public void setScore1(float score1)

{

this.score = score1;

}

}该程序,如何实现?

System.out.println("please input the student's math's score.:");

String s=readInput();

float s2=Float.parseFloat(s);

for(int i=0;i

{

Student1 student = (Student1)vector.get(i);

if(s2==student.getScore())

{

vector.removeElementAt(i) ;

System.out.println("Delete success!");

}

else

System.out.println("cannot find !");

请告诉我为什么会这样子,谢谢了。现在查找与删除就这个STRING类型不能匹配了。

展开

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值
>