import java.util.*;
import java.io.*;class Teacher
{
String name;
int age;
String position; //职务
String academy; //工作院系 public Teacher(){}
public Teacher(String name,int age,String position,String academy)
{
this.name = name;
this.age = age;
this.position = position;
this.academy = academy;
} public String getName()
{
return this.name;
} public int getAge()
{
return this.age;
} public String getPosi()
{
return this.position;
} public String getAcad()
{
return this.position;
}
}
class TeacherManage
{
ArrayList a = new ArrayList();
Teacher u = new Teacher(); public void addTeacher()
{
System.out.print("输入要添加的姓名:");
Scanner keyboard = new Scanner(System.in);
String name = keyboard.nextLine();
System.out.print("输入该人的年龄:");
int age = keyboard.nextInt();
System.out.print("输入该人的职务:");
String position = keyboard.nextLine();
System.out.print("输入该人的工作院系:");
String academy = keyboard.nextLine();
a.add(u);
} public void display()
{
Iterator i = a.iterator();
while(i.hasNext())
{
Teacher u = (Teacher)(i.next()); //把它转换为自己的对象
System.out.println("name:"+u.name+" "+"age:"+u.age+" "+"position:"+u.position+" "+"academy"+u.academy);
}
} public void searchByName()
{
System.out.print("输入要查询的姓名:");
Scanner keyboard = new Scanner(System.in);
String name = keyboard.nextLine();
boolean singal = true;
for(int i=0;i<a.size();i++)
{
Teacher p = (Teacher)a.get(i);
if(p.getName().equals(name))
{
System.out.println("该人对应的信息为 name:"+p.getName()+" age:"+p.getAge()+" position"+p.getPosi()+" academy"+p.getAcad());
singal = false;
}
if(singal)
System.out.println("无你要找的ID信息!");
else return;
}
}
}
public class ArrayListTeacher
{
public static void main(String[] args)
{
TeacherManage f = new TeacherManage();
String index;
System.out.println("输入要执行的操作: a.添加 b.按姓名详细查询 c.显示信息 其它字符退出操作");
Scanner keyboard = new Scanner(System.in);
index = keyboard.next();
while(index.equals("a") || index.equals("b") || index.equals("c"))
{
if(index.equals("a"))
f.addTeacher();
if(index.equals("b"))
f.searchByName();
if(index.equals("c"))
f.display();
System.out.println("输入要执行的操作: a.添加 b.按姓名详细查询 c.显示信息 其它字符退出操作");
index = keyboard.next();
}
System.out.println("操作退出!");
}
}
编译后显示 注意:使用了未经检查或不安全的操作
注意:要了解详细信息,请使用-Xlint:unchecked重新编译
新手,请多帮忙
import java.io.*;class Teacher
{
String name;
int age;
String position; //职务
String academy; //工作院系 public Teacher(){}
public Teacher(String name,int age,String position,String academy)
{
this.name = name;
this.age = age;
this.position = position;
this.academy = academy;
} public String getName()
{
return this.name;
} public int getAge()
{
return this.age;
} public String getPosi()
{
return this.position;
} public String getAcad()
{
return this.position;
}
}
class TeacherManage
{
ArrayList a = new ArrayList();
Teacher u = new Teacher(); public void addTeacher()
{
System.out.print("输入要添加的姓名:");
Scanner keyboard = new Scanner(System.in);
String name = keyboard.nextLine();
System.out.print("输入该人的年龄:");
int age = keyboard.nextInt();
System.out.print("输入该人的职务:");
String position = keyboard.nextLine();
System.out.print("输入该人的工作院系:");
String academy = keyboard.nextLine();
a.add(u);
} public void display()
{
Iterator i = a.iterator();
while(i.hasNext())
{
Teacher u = (Teacher)(i.next()); //把它转换为自己的对象
System.out.println("name:"+u.name+" "+"age:"+u.age+" "+"position:"+u.position+" "+"academy"+u.academy);
}
} public void searchByName()
{
System.out.print("输入要查询的姓名:");
Scanner keyboard = new Scanner(System.in);
String name = keyboard.nextLine();
boolean singal = true;
for(int i=0;i<a.size();i++)
{
Teacher p = (Teacher)a.get(i);
if(p.getName().equals(name))
{
System.out.println("该人对应的信息为 name:"+p.getName()+" age:"+p.getAge()+" position"+p.getPosi()+" academy"+p.getAcad());
singal = false;
}
if(singal)
System.out.println("无你要找的ID信息!");
else return;
}
}
}
public class ArrayListTeacher
{
public static void main(String[] args)
{
TeacherManage f = new TeacherManage();
String index;
System.out.println("输入要执行的操作: a.添加 b.按姓名详细查询 c.显示信息 其它字符退出操作");
Scanner keyboard = new Scanner(System.in);
index = keyboard.next();
while(index.equals("a") || index.equals("b") || index.equals("c"))
{
if(index.equals("a"))
f.addTeacher();
if(index.equals("b"))
f.searchByName();
if(index.equals("c"))
f.display();
System.out.println("输入要执行的操作: a.添加 b.按姓名详细查询 c.显示信息 其它字符退出操作");
index = keyboard.next();
}
System.out.println("操作退出!");
}
}
编译后显示 注意:使用了未经检查或不安全的操作
注意:要了解详细信息,请使用-Xlint:unchecked重新编译
新手,请多帮忙
解决方案 »
- 求把这段C++代码转换成java代码~不胜感激啊
- jdbc的小问疑惑
- 一个关于格式化日期的问题
- B Tree问题 如果在树里从小到大排序
- 一个JAVA图形问题
- 求救!!!!!!!!!!!!!!!!!!!!!!!!!!!1
- 作为socket连接的client端,监听输入流是否有数据的好方法?
- Tomcat5.0.28+SQL Server2000连接池配置的问题
- 字符串插入问题,超级简单的问题?
- socket传java简单对象出错,java.io.StreamCorruptedException: invalid
- 在线等,菜鸟问题,用递归表示循环的问题
- for(;;)和while(true)的区别
如果不带泛型参数的话就会有这个警告。如果不想要这个警告的话,可以改成这样:ArrayList a = new ArrayList(); ----> ArrayList<Teacher> a = new ArrayList<Teacher>();
Iterator i = a.iterator(); ----> Iterator<Teacher> i = a.iterator();
Teacher u = (Teacher)(i.next()); //把它转换为自己的对象
----> Teacher u = i.next(); // 由于采用了泛型参数,就不需要再转换了
Teacher p = (Teacher)a.get(i); ----> Teacher p = a.get(i);
看了一下,基本上就这些了。
没事的
可以继续运行
我弄与sql连接时也出现这种提示
是不是这样更好一些。
import java.util.*;
import java.io.*; class Teacher
{
String name;
int age;
String position; //职务
String academy; //工作院系 public Teacher(){}
public Teacher(String name,int age,String position,String academy)
{
this.name = name;
this.age = age;
this.position = position;
this.academy = academy;
} public String getName()
{
return this.name;
}
public int getAge()
{
return this.age;
}
public String getPosi()
{
return this.position;
}
public String getAcad()
{
return this.position;
}
}
class TeacherManage
{
ArrayList<Teacher> a = new ArrayList<Teacher>();
//Teacher u = new Teacher();
public void addTeacher()
{
System.out.print("输入要添加的姓名:");
Scanner keyboard = new Scanner(System.in);
String name = keyboard.nextLine();
System.out.print("输入该人的年龄:");
int age = keyboard.nextInt();
System.out.print("输入该人的职务:");
String position = keyboard.nextLine();
System.out.print("输入该人的工作院系:");
String academy = keyboard.nextLine();
Teacher u = new Teacher(name,age,position,academy);
a.add(u);
} public void display()
{
Iterator<Teacher> i = a.iterator();
while(i.hasNext())
{
Teacher u = i.next(); //把它转换为自己的对象
System.out.println("name:"+u.name+" "+"age:"+u.age+" "+"position:"+u.position+" "+"academy"+u.academy);
}
} public void searchByName()
{
System.out.print("输入要查询的姓名:");
Scanner keyboard = new Scanner(System.in);
String name = keyboard.nextLine();
boolean singal = true;
for(int i=0;i <a.size();i++)
{
Teacher p = a.get(i);
if(p.getName().equals(name))
{
System.out.println("该人对应的信息为 name:"+p.getName()+" age:"+p.getAge()+" position"+p.getPosi()+" academy"+p.getAcad());
singal = false;
}
if(singal)
System.out.println("无你要找的ID信息!");
else return;
}
}
}
public class ArrayListTeacher
{
public static void main(String[] args)
{
TeacherManage f = new TeacherManage();
String index;
System.out.println("输入要执行的操作: a.添加 b.按姓名详细查询 c.显示信息 其它字符退出操作");
Scanner keyboard = new Scanner(System.in);
index = keyboard.next();
while(index.equals("a") || index.equals("b") || index.equals("c"))
{
if(index.equals("a"))
f.addTeacher();
if(index.equals("b"))
f.searchByName();
if(index.equals("c"))
f.display();
System.out.println("输入要执行的操作: a.添加 b.按姓名详细查询 c.显示信息 其它字符退出操作");
index = keyboard.next();
}
System.out.println("操作退出!");
}
}