编写一个程序,模拟学校多个学生注册交学费流程。系统用户有学生、老师两类: (1)注册信息包括:学号、姓名、所属学院、专业、年级、班、宿舍。 缴费信息包括:学号、学期(例如:2022-2022-2)、学费、住宿费。 (2)功能需求:创建学生、老师两个子线程 1)学生线程实现注册、缴费; 2)老师线程统计不同学院的学费收缴金额、住宿费收缴金额。 (3)数据组织及存储要求 1)注册信息、缴费信息存储在.txt文件中; 2)注册、缴费信息要求使用泛型集合方式,具体实现类型自定; (4)测试数据要求: 1)存储注册信息的文件,至少有10条数据,至少涵盖2个学院、4个专业(不同专业对应的学费不同)。 2)存储缴费信息的文件,至少有10条数据,与注册信息关联。例如,某学生完成了注册,缴费,则在注册信息文件与缴费信息文件中新增两条信息,这两条信息有相同的学号。 (5)难度系数3,使用数据库、算法、前端等知识,可额外加分。

时间: 2024-03-25 07:41:25 浏览: 17
好的,下面是一个简单的Java程序,可以实现你所描述的功能: ```java import java.io.*; import java.util.*; class Student { private String id; private String name; private String college; private String major; private String grade; private String clazz; private String dormitory; public Student(String id, String name, String college, String major, String grade, String clazz, String dormitory) { this.id = id; this.name = name; this.college = college; this.major = major; this.grade = grade; this.clazz = clazz; this.dormitory = dormitory; } public String getId() { return id; } public String getName() { return name; } public String getCollege() { return college; } public String getMajor() { return major; } public String getGrade() { return grade; } public String getClazz() { return clazz; } public String getDormitory() { return dormitory; } } class Payment { private String id; private String term; private double tuition; private double accommodation; public Payment(String id, String term, double tuition, double accommodation) { this.id = id; this.term = term; this.tuition = tuition; this.accommodation = accommodation; } public String getId() { return id; } public String getTerm() { return term; } public double getTuition() { return tuition; } public double getAccommodation() { return accommodation; } } class CollegePayment { private String college; private double tuition; private double accommodation; public CollegePayment(String college, double tuition, double accommodation) { this.college = college; this.tuition = tuition; this.accommodation = accommodation; } public String getCollege() { return college; } public double getTuition() { return tuition; } public double getAccommodation() { return accommodation; } } class Registration { private List<Student> students = new ArrayList<>(); private List<Payment> payments = new ArrayList<>(); private Map<String, CollegePayment> collegePayments = new HashMap<>(); public void register(String id, String name, String college, String major, String grade, String clazz, String dormitory) { students.add(new Student(id, name, college, major, grade, clazz, dormitory)); } public void pay(String id, String term, double tuition, double accommodation) { payments.add(new Payment(id, term, tuition, accommodation)); } public void calculateCollegePayments() { for (Payment payment : payments) { String id = payment.getId(); String college = getCollegeById(id); CollegePayment collegePayment = collegePayments.get(college); if (collegePayment == null) { collegePayment = new CollegePayment(college, 0, 0); collegePayments.put(college, collegePayment); } collegePayment.tuition += payment.getTuition(); collegePayment.accommodation += payment.getAccommodation(); } } public void printCollegePayments() { System.out.println("College\tTuition\tAccommodation"); for (CollegePayment collegePayment : collegePayments.values()) { System.out.println(collegePayment.getCollege() + "\t" + collegePayment.getTuition() + "\t" + collegePayment.getAccommodation()); } } private String getCollegeById(String id) { for (Student student : students) { if (student.getId().equals(id)) { return student.getCollege(); } } return null; } } class StudentThread extends Thread { private Registration registration; public StudentThread(Registration registration) { this.registration = registration; } public void run() { // 在这里实现学生线程的注册、缴费功能 // 可以从.txt文件中读取数据,也可以手动创建测试数据 // 注册信息和缴费信息可以使用Registration类中的register()和pay()方法来添加 } } class TeacherThread extends Thread { private Registration registration; public TeacherThread(Registration registration) { this.registration = registration; } public void run() { // 在这里实现老师线程的统计不同学院的学费收缴金额、住宿费收缴金额功能 // 可以使用Registration类中的calculateCollegePayments()和printCollegePayments()方法来实现 } } public class Main { public static void main(String[] args) { Registration registration = new Registration(); StudentThread studentThread = new StudentThread(registration); TeacherThread teacherThread = new TeacherThread(registration); studentThread.start(); teacherThread.start(); } } ``` 这个程序使用了Java中的多线程技术,可以同时进行学生线程和老师线程的操作。其中,Registration类用于存储所有的学生注册信息和缴费信息,并且提供了对应的注册、缴费、统计功能。在实现学生线程和老师线程的功能时,可以使用Registration类的方法进行操作。

相关推荐

最新推荐

recommend-type

ASP.NET课程-学生信息管理系统实验报告.doc

编写学生信息管理系统,实现以下功能: 1. 学生信息管理:对在校学生信息进行添加、删除、修改、查询等操作。 2. 学生成绩管理:对已经录入的学生信息进行添加、删除、修改学习成绩,并可以通过关键字进行查询。 3...
recommend-type

python学生信息管理系统实现代码

主要介绍了python学生信息管理系统的实现代码,代码简单,复制即可使用,需要的朋友可以参考下
recommend-type

python+mysql实现学生信息查询系统

主要为大家详细介绍了python+mysql实现学生信息查询系统,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
recommend-type

jsp编写简单的学生信息注册界面

信息注册界面&lt;/title&gt; &lt;/head&gt; &lt;body&gt; &lt;form id="formal"name="formal"method="post"action="successful.jsp"&gt; 信息注册页面 学号: &lt;input name="usernum"type="text"id="usernum"/&...
recommend-type

java实验:编写一个java应用程序,用户从键盘输入一个1-99999的数,程序将判断这个数是几位数,并判断这个数是.pdf

java实验:编写一个java应用程序,用户从键盘输入一个1-99999的数,程序将判断这个数是几位数,并判断这个数是
recommend-type

zigbee-cluster-library-specification

最新的zigbee-cluster-library-specification说明文档。
recommend-type

管理建模和仿真的文件

管理Boualem Benatallah引用此版本:布阿利姆·贝纳塔拉。管理建模和仿真。约瑟夫-傅立叶大学-格勒诺布尔第一大学,1996年。法语。NNT:电话:00345357HAL ID:电话:00345357https://theses.hal.science/tel-003453572008年12月9日提交HAL是一个多学科的开放存取档案馆,用于存放和传播科学研究论文,无论它们是否被公开。论文可以来自法国或国外的教学和研究机构,也可以来自公共或私人研究中心。L’archive ouverte pluridisciplinaire
recommend-type

MATLAB柱状图在信号处理中的应用:可视化信号特征和频谱分析

![matlab画柱状图](https://img-blog.csdnimg.cn/3f32348f1c9c4481a6f5931993732f97.png) # 1. MATLAB柱状图概述** MATLAB柱状图是一种图形化工具,用于可视化数据中不同类别或组的分布情况。它通过绘制垂直条形来表示每个类别或组中的数据值。柱状图在信号处理中广泛用于可视化信号特征和进行频谱分析。 柱状图的优点在于其简单易懂,能够直观地展示数据分布。在信号处理中,柱状图可以帮助工程师识别信号中的模式、趋势和异常情况,从而为信号分析和处理提供有价值的见解。 # 2. 柱状图在信号处理中的应用 柱状图在信号处理
recommend-type

解释这行代码 c = ((double)rand() / RAND_MAX) * (a + b - fabs(a - b)) + fabs(a - b);

这行代码是用于生成 a 和 b 之间的随机数。首先,它使用 rand() 函数生成一个 [0,1) 之间的随机小数,然后将这个小数乘以 a、b 范围内的差值,再加上 a 和 b 中的较小值。这可以确保生成的随机数大于等于 a,小于等于 b,而且不会因为 a 和 b 之间的差距过大而导致难以生成足够多的随机数。最后,使用 fabs() 函数来确保计算结果是正数。
recommend-type

JSBSim Reference Manual

JSBSim参考手册,其中包含JSBSim简介,JSBSim配置文件xml的编写语法,编程手册以及一些应用实例等。其中有部分内容还没有写完,估计有生之年很难看到完整版了,但是内容还是很有参考价值的。