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类型不能匹配了。
展开