Java简易餐与管理系统_java学生餐费管理系统(学习代码)

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);

}

}

}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值