import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
public class Demo6
{
public static void main(String[] args) throws IOException
{
StuManage sManage = new StuManage();
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
while (true)
{
System.out.println("-----请选择需要实现的功能-----");
System.out.println("1:新增学生");
System.out.println("2:查找学生信息");
System.out.println("3:修改餐费");
System.out.println("4: 删除学生");
System.out.println("5: 退出系统");
String no = br.readLine().toString();
if (no.equals("1"))
{
System.out.println("输入学生姓名:");
String name = br.readLine();
System.out.println("输入学生年龄:");
int age = Integer.parseInt(br.readLine());
System.out.println("输入学生餐费:");
float money = Float.parseFloat(br.readLine());
Student student = new Student(age, name, money);
sManage.addStu(student);
} else if (no.equals("2"))
{
System.out.println("输入学生姓名:");
String name = br.readLine();
sManage.showInf(name);
} else if (no.equals("3"))
{
System.out.println("输入学生姓名:");
String name = br.readLine();
System.out.println("请输入需要修改的餐费:");
Float money = Float.parseFloat(br.readLine());
sManage.updateMoney(name, money);
} else if (no.equals("4"))
{
System.out.println("输入学生姓名:");
String name = br.readLine();
sManage.deleteStudent(name);
} else if (no.equals("5"))
{
System.exit(1);
;
}
}
}
}
class Student
{
int age;
String name;
float money;
public Student(int age, String name, float money)
{
this.age = age;
this.name = name;
this.money = money;
}
/**
* @return age
*/
public int getAge()
{
return age;
}
/**
* @param age
* 要设置的 age
*/
public void setAge(int age)
{
this.age = age;
}
/**
* @return name
*/
public String getName()
{
return name;
}
/**
* @param name
* 要设置的 name
*/
public void setName(String name)
{
this.name = name;
}
/**
* @return money
*/
public float getMoney()
{
return money;
}
/**
* @param money
* 要设置的 money
*/
public void setMoney(float money)
{
this.money = money;
}
}
class StuManage
{
ArrayList aList = new ArrayList();
public void addStu(Student st)
{
aList.add(st);
System.out.println("新增学生成功!");
}
public void showInf(String name)
{
for (int i = 0; i < aList.size(); i++)
{
Student stu = (Student) aList.get(i);
if (stu.getName().equals(name))
{
System.out.println("找到学生的信息 姓名:" + name + " 年龄:" + stu.getAge() + " 餐费:" + stu.getMoney());
}
}
}
public void updateMoney(String name, Float money)
{
for (int i = 0; i < aList.size(); i++)
{
Student stu = (Student) aList.get(i);
if (stu.getName().equals(name))
{
Float oldmoney = stu.getMoney();
stu.setMoney(money);
System.out.println("修改餐费成功 姓名:" + name + " 修改前餐费:" + oldmoney + " 修改后餐费:" + stu.getMoney());
}
}
}
public void deleteStudent(String name)
{
for (int i = 0; i < aList.size(); i++)
{
Student stu = (Student) aList.get(i);
if (stu.getName().equals(name))
{
aList.remove(i);
System.out.println("删除学生成功 姓名:" + name);
}
}
}
}