java运动会管理系统

目录

一、项目介绍

1、主要功能介绍 

二、分析与设计

三、问题与分析

四、小结

五、代码


一、项目介绍

1、主要功能介绍 

对于管理者

         1、登录系统来发布运动会的项目以及对应项目的比赛规则

         2、管理者也可以修改运动会比赛时间和地点,如果管理者需要修改比赛时间或者比赛地点,必须提前一天修改然后再重新发布。

对于用户

       1、 登录系统报名参加运动会的项目,报名志愿者,或者报名裁判。

       2、 当用户报名参加运动会项目时,首先要先选择身份,如果是老师则进入老师参赛页面(老师与老师之间比赛),需要登记老师的学院、姓名、参赛项目以及给老师分配参赛号。

        3、如果是学生则进入学生参赛页面(学生和学生之间比赛),需要登记学生的学院,专业、班级、姓名、性别、学号、参赛项目以及给学生分配参赛号,同时参赛者可以查看项目的相关信息以及自己的得分和排名。

        4、当用户报名裁判时(仅限老师报名),将该用户的信息存入裁判信息文件中。当该用户登录系统之后,可以查阅项目相关信息,可以对选手进行打分(信息存入文件中)、判断选手是否违规、记录参赛选手的成绩(信息存入文件中),根据打分给出运动员的排名。

       5、 当用户报名志愿者时,可以查阅项目相关信息。

二、分析与设计

三、问题与分析

1、参赛号分配问题(以学生参赛为例):
参赛选手的信息录入到同一个文件中,当选手A报名一分钟跳绳比赛的时候,首先检索文件中已有的一分钟跳绳比赛参赛人数,其次为选手A分配参赛号,最后将选手A的个人基本信息和参赛号存入到文件中。
2、人数上限问题:
志愿者人数不超过20人,裁判人数不超过10人,当志愿者或者裁判人数超出系统设定的上限,则给出警告并且超出的部分的信息不再录入文件。
3、多次报名问题
当用户登录系统报名参加比赛时,则该用户将无法报名志愿者和裁判;或者用户报名了志愿者,则将无法报名参加比赛和裁判。

4、登录/注册异常问题:
当用户账号不存在时,系统给出“请先注册”提示;当用户输入的账号和密码不满足8位时,系统给出“填写出错”警告;当用户输入的密码错误时,系统给出“密码输入错误”警告。
5、选手违规记录问题:
当参赛选手在比赛过程中的违规次数达到上限的时候,则直接将该选手的参赛信息从文件中删除,也即是取消比赛资格。
6、裁判登录问题:
当用户A(账号已存在)报名裁判之后,用户A的信息也会被存入裁判信息的文件中,报名结束之后,当A再次登录该系统时,登录成功后系统直接跳转到裁判操作页面。

四、小结

        此运动会管理系统相对来说比较的简陋,有些功能和问题还没来得及实现和更改,有需要的友友谨慎拿取!

五、代码

package Game;
//问题1:参赛号分配问题  问题2:志愿者人数上限问题  问题3:裁判人数上限问题
//问题4:将所有参赛教职工的信息直接全部录入一个文件当中,读取的时候按照参赛项目进行读取
//问题5:例:当一个人报名志愿者的时候,需要检查这个人是否报了其它的项目(比如裁判)
//问题6:当一个人已经报名成功裁判之后,应该有一个裁判登录界面,登陆之后可以直接给运动员们打分
import java.io.*;
import java.util.Scanner;

public class Game {
	public static void main(String[] args) throws IOException {
		Menu();
	}
	public static void Menu() throws IOException {//管理员和用户身份选择
		while(true) {
			System.out.println("==========****大学运动会管理系统==========");
			System.out.println("1.管理员");
			System.out.println("2.普通用户");
			System.out.println("3.裁判");
			System.out.print("请输入您的操作:");
			@SuppressWarnings("resource")
			Scanner sc=new Scanner(System.in);
			int command=sc.nextInt();
			switch(command) {
				case 1:
					managerLogin();//管理员
					break;
				case 2:
					userLogin();//用户
					break;
				case 3:
					judgeLogin();//裁判
				default:
					System.out.println("输入的命令不存在!");
				
			}
		}
	}
	public static void managerLogin() throws IOException {//管理员登录
		@SuppressWarnings("resource")
		Scanner sc=new Scanner(System.in);
		while(true) {
			System.out.println("==============管理员登录页面==============");
			System.out.print("请输入姓名:");
			String name=sc.nextLine();
			System.out.print("请输入密码:");
			String code=sc.nextLine();
			if(check(name,code)==true) {
				System.out.println("登录成功!");
				managerMenu();
				break;
			}
			else {
				System.out.println("密码错误或者用户名错误,请重新输入!");
			}
		}
	}
	public static boolean check(String name,String code) throws IOException {//创建check方法,来检查注册的用户是否已经存在
		String dir="D:/programming/MyJava/管理员信息.txt";
		File file=new File(dir);
		if(!file.exists()){
			file.createNewFile();
		}
		@SuppressWarnings("resource")
		BufferedReader b=new  BufferedReader(new FileReader(file));
		String temp=null;
		temp=b.readLine();//先读取一行
		while(temp!=null) {
			String sbstring=temp.toString();//转化为String
			int n=sbstring.length();//测字符串长度
			String []message=new String[2];
			int k=0;
			for(int i=0;i<2;i++) {
				message[i]="";
			}
			for(int i=0;i<n;i++) {
				if(sbstring.charAt(i)==',') {
					k++;
				}
				else {
					message[k]+=sbstring.charAt(i);
				}
				//System.out.print(sbstring.charAt(i));
			}
			if(name.equals(message[0])&&code.equals(message[1])) {
				return true;
			}
			temp=b.readLine();
		}
		return false;	
	}
	public static void userLogin() throws IOException {//用户登录
		@SuppressWarnings("resource")
		Scanner sc=new Scanner(System.in);
		while(true) {
			System.out.println("==============用户登录页面==============");
			System.out.print("请输入姓名:");
			String name=sc.nextLine();
			System.out.print("请输入密码:");
			String code=sc.nextLine();
			if(check1(name,code)==true) {//检查输入的姓名或者密码是否正确
				System.out.println("登录成功!");
				userMenu();
				break;
			}
			else {
				System.out.println("密码错误或者用户名错误,请重新输入!");
			}
		}
	}
	private static boolean check1(String name,String code) throws IOException {
		String dir="D:/programming/MyJava/用户信息.txt";
		File file=new File(dir);
		if(!file.exists()){
			file.createNewFile();
		}
		@SuppressWarnings("resource")
		BufferedReader b=new  BufferedReader(new FileReader(file));
		String temp=null;
		temp=b.readLine();//先读取一行
		while(temp!=null) {
			String sbstring=temp.toString();//转化为String
			int n=sbstring.length();//测字符串长度
			String []message=new String[2];
			int k=0;
			for(int i=0;i<2;i++) {
				message[i]="";
			}
			for(int i=0;i<n;i++) {
				if(sbstring.charAt(i)==',') {
					k++;
				}
				else {
					message[k]+=sbstring.charAt(i);
				}
				//System.out.print(sbstring.charAt(i));
			}
			if(name.equals(message[0])&&code.equals(message[1])) {
				return true;
			}
			temp=b.readLine();
		}
		return false;	
	}
	public static void judgeLogin() throws IOException {//裁判登录
		@SuppressWarnings("resource")
		Scanner sc=new Scanner(System.in);
		while(true) {
			System.out.println("==============裁判登录页面==============");
			System.out.print("请输入姓名:");
			String name=sc.nextLine();
			System.out.print("请输入密码:");
			String code=sc.nextLine();
			if(check2(name,code)==true) {//检查输入的姓名或者密码是否正确
				System.out.println("登录成功!");
				judgeMenu();//打分功能,查看运动员分数
				break;
			}
			else {
				System.out.println("密码错误或者用户名错误,请重新输入!");
			}
		}
	}
	//裁判给运动员们打分
	private static boolean check2(String name, String code) throws IOException {
		String dir="D:/programming/MyJava/裁判信息.txt";
		File file=new File(dir);
		if(!file.exists()){
			file.createNewFile();
		}
		@SuppressWarnings("resource")
		BufferedReader b=new  BufferedReader(new FileReader(file));
		String temp=null;
		temp=b.readLine();//先读取一行
		while(temp!=null) {
			String sbstring=temp.toString();//转化为String
			int n=sbstring.length();//测字符串长度
			String []message=new String[4];
			int k=0;
			for(int i=0;i<4;i++) {
				message[i]="";
			}
			for(int i=0;i<n;i++) {
				if(sbstring.charAt(i)==',') {
					k++;
				}
				else {
					message[k]+=sbstring.charAt(i);
				}
				//System.out.print(sbstring.charAt(i));
			}
			if(name.equals(message[0])&&code.equals(message[1])) {
				return true;
			}
			temp=b.readLine();
		}
		return false;	
	}
	public static void judgeMenu() throws IOException {
		@SuppressWarnings("resource")
		Scanner sc=new Scanner(System.in);
		while(true) {
			System.out.println("==============裁判操作页面==============");
			System.out.println("1.录入成绩");
			System.out.println("2.查看分数");
			System.out.println("3.退出");
			System.out.print("请输入您的操作:");
			int command=sc.nextInt();
			switch(command) {
			case 1:
				giveScore();//打分
				break;
			case 2:
				readScore();//查看分数
				break;
			case 3:
				return;
			default:
				System.out.println("输入的命令不存在!");	
			}
		}
	}
	public static void giveScore() throws IOException {//裁判给运动员们打分
		@SuppressWarnings("resource")
		Scanner sc=new Scanner(System.in);
		String dir="D:/programming/MyJava/运动员得分.txt";
		File file=new File(dir);
		if(!file.exists()) {
			file.createNewFile();
		}
		BufferedWriter bu=new BufferedWriter(new FileWriter(file,true));
		System.out.print("请输入运动员的学院:");
		String college=sc.nextLine();
		System.out.print("请输入运动员的姓名:");
		String name=sc.nextLine();
		System.out.print("请输入运动员的学号:");
		String id=sc.nextLine();
		System.out.print("请输入运动员的分数:");
		String score=sc.nextLine();
		bu.append(college+",");
		bu.append(name+",");
		bu.append(id+",");
		bu.append(score+"");
		bu.append("\n");
		bu.close();
		System.out.println("信息已成功存入文件!");
	}
	public static void readScore() throws IOException {//裁判查看所有运动员的分数
		String dir="D:/programming/MyJava/运动员得分.txt";
		File file=new File(dir);
		if(!file.exists()) {//如果文件不存在,则创建文件
			file.createNewFile();
		}
		BufferedReader bu=new BufferedReader(new FileReader(file));//缓冲流读取
		String line;//整行读取
		System.out.println("==============运动员得分信息如下所示==============");
		System.out.println("学院\t\t姓名\t学号\t分数");
		while((line=bu.readLine())!=null) {
			System.out.println(line);
		}
		bu.close();//关闭文件
	}
	public static void managerMenu() throws IOException {//管理员操作主菜单
		@SuppressWarnings("resource")
		Scanner sc=new Scanner(System.in);
		while(true) {
			System.out.println("==============管理员操作页面==============");
			System.out.println("1.发布运动会项目以及项目的规则");
			System.out.println("2.修改运动会的比赛信息");//时间或者地点或者规则
			System.out.println("3.退出");
			System.out.print("请输入您的操作:");
			int command=sc.nextInt();
			switch(command) {
			case 1:
				releaseInformation();//1.发布运动会项目以及项目的规则
				break;
			case 2:
				correctInformation();//2.修改运动会的比赛时间或者地点或者规则
				break;
			case 3:
				return;
			default:
				System.out.println("输入的命令不存在!");	
			}
		}
	}
	//发布运动会项目和比赛规则,管理员将比赛信息存入文件当中,发布之后所有用户可以查看比赛信息
	public static void releaseInformation() throws IOException {
		@SuppressWarnings("resource")
		Scanner sc=new Scanner(System.in);
		String dir="D:/programming/MyJava/运动会项目规则.txt";
		File file=new File(dir);
		if(!file.exists()) {
			file.createNewFile();
		}
		BufferedWriter bu=new BufferedWriter(new FileWriter(file));
		System.out.print("请输入运动会的项目以及对应的比赛规则:");
		String information=sc.nextLine();
			bu.write(information);
		bu.close();
		System.out.println("信息已成功存入文件!");
	}
	//修改比赛时间或者规则
	public static void correctInformation() throws IOException {
		@SuppressWarnings("resource")
		Scanner sc=new Scanner(System.in);
		String dir="D:/programming/MyJava/比赛时间地点.txt";
		File file=new File(dir);
		if(!file.exists()) {
			file.createNewFile();
		}
		BufferedWriter bu=new BufferedWriter(new FileWriter(file));
		String first="比赛时间和地点如下所示:";
		String second="比赛时间:";
		String third="比赛地点:";
		String stop="\n";
		bu.write(first);
		bu.write(stop);
		bu.write(second);
		System.out.print("请输入修改后的比赛时间:");
		String time=sc.nextLine();
		bu.write(time);
		bu.write(stop);
		bu.write(third);
		System.out.print("请输入修改的比赛地点:");
		String place=sc.nextLine();
		bu.write(place);
		
		bu.close();
		System.out.println("信息修改成功!");
	}
	public static void userMenu() throws IOException {//用户操作主菜单
		@SuppressWarnings("resource")
		Scanner sc=new Scanner(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.print("请输入您的操作:");
			int Command=sc.nextInt();
			switch(Command) {
			case 1:
				Choose();//选择身份
				break;
			case 2:
				Volunteer();//志愿者信息录入相应文件中,并且当名额满的时候不再录入
				break;
			case 3:
				Judge();//裁判信息录入相应文件中,并且当名额满的时候不再录入
				break;
			case 4:
				return;
			default:
				System.out.println("输入的命令不存在!");
				
			}
		}
	}
	public static void Choose() throws IOException {
		while(true) {
			@SuppressWarnings("resource")
			Scanner sc=new Scanner(System.in);
			System.out.println("==============报名比赛页面==============");
			System.out.println("1.教职工");
			System.out.println("2.学生");
			System.out.println("3.查看比赛信息");
			System.out.println("4.退出");
			System.out.print("请输入您的操作:");
			int Command=sc.nextInt();
			switch(Command) {
			case 1:
				teacherGame();//教职工
				break;
			case 2:
				studentGame();//学生
				break;
			case 3:
				readFile();//查看比赛规则
				break;
			case 4:
				return;
			default:
				System.out.println("输入的指令不存在!");
				
			}
		}
	}
	public static void teacherGame() throws IOException {//教职工参加比赛,将参赛信息存入文件
		int f=0;//统计文件中已有参赛者的个数
		@SuppressWarnings("resource")
		Scanner sc=new Scanner(System.in);
		String dir="D:/programming/MyJava/教职工参赛信息.txt";
		File file=new File(dir);
		if(!file.exists()) {//如果文件不存在,则创建文件
			file.createNewFile();
		}
		//统计已报名的人数
		BufferedReader b=new BufferedReader(new FileReader(file));//缓冲流读取
		@SuppressWarnings("unused")
		String line;//整行读取
		while((line=b.readLine())!=null) {
			f++;
		}
		f=f+1;
		b.close();//关闭文件
		
		BufferedWriter bu=new BufferedWriter(new FileWriter(file,true));
		System.out.print("请输入参赛教师的学院:");
		String college=sc.nextLine();
		System.out.print("请输入参赛教师的姓名:");
		String name=sc.nextLine();
		System.out.print("请输入参赛教师的性别:");
		String sex=sc.nextLine();
		System.out.print("请输入参赛教师的参赛项目:");
		String game=sc.nextLine();
		bu.append(college+",");
		bu.append(name+",");
		bu.append(sex+",");
		bu.append(game+",");
		bu.append(f+"");
		bu.append("\n");
		bu.close();
		System.out.println(name+"老师在"+game+"项目中的参赛号为:"+f);
		System.out.println("信息已成功存入文件!");
	}
	public static void studentGame() throws IOException {//学生参加比赛,将参赛信息存入文件
		int f=0;
		@SuppressWarnings("resource")
		Scanner sc=new Scanner(System.in);
		String dir="D:/programming/MyJava/学生参赛信息.txt";
		File file=new File(dir);
		if(!file.exists()) {
			file.createNewFile();
		}
		//统计已报名的人数
		BufferedReader b=new BufferedReader(new FileReader(file));//缓冲流读取
		@SuppressWarnings("unused")
		String line;//整行读取
		while((line=b.readLine())!=null) {
			f++;
		}
		f=f+1;
		b.close();//关闭文件
		
		BufferedWriter bu=new BufferedWriter(new FileWriter(file,true));
		System.out.print("请输入参赛学生的学院:");
		String college=sc.nextLine();
		System.out.print("请输入参赛学生的专业:");
		String major=sc.nextLine();
		System.out.print("请输入参赛学生的姓名:");
		String stuName=sc.nextLine();
		System.out.print("请输入参赛学生的性别:");
		String sex=sc.nextLine();
		System.out.print("请输入参赛学生的学号:");
		String ID=sc.nextLine();
		System.out.print("请输入参赛学生的参赛项目:");
		String g=sc.nextLine();
		//将参赛学生的信息存入文件
		bu.append(college+",");
		bu.append(major+",");
		bu.append(stuName+",");
		bu.append(sex+",");
		bu.append(ID+",");
		bu.append(g+",");
		bu.append(f+"");
		bu.append("\n");
		bu.close();
		System.out.println(stuName+"同学在"+g+"中的参赛号为:"+f);
		System.out.println("信息已成功存入文件!");
	}
	public static void Volunteer() throws IOException {//报名志愿者
		while(true) {		
			@SuppressWarnings("resource")
			Scanner sc=new Scanner(System.in);
			System.out.println("==============报名志愿者页面==============");
			System.out.println("1.登记信息");
			System.out.println("2.查看比赛信息");
			System.out.println("3.退出");
			System.out.println("请输入您的操作:");
			int command=sc.nextInt();
			switch(command) {
			case 1:
				VInformation();//登记信息,将报名志愿者的人的信息录入文件
				break;
			case 2:
				readFile();//查看比赛规则
				break;
			case 3:
				return;
			default:
				System.out.println("您输入的命令不存在!");
				
			}
		}
	}
	public static void VInformation() throws IOException {//将志愿者信息录入文件
		@SuppressWarnings("resource")
		Scanner sc=new Scanner(System.in);
		String dir="D:/programming/MyJava/志愿者信息.txt";
		File file=new File(dir);
		if(!file.exists()) {//如果文件不存在,则创建文件
			file.createNewFile();
		}
		BufferedWriter bu=new BufferedWriter(new FileWriter(file,true));
		System.out.print("请输入您的学院:");
		String college=sc.nextLine();
		System.out.print("请输入您的学号:");
		String ID=sc.nextLine();
		System.out.print("请输入您的姓名:");
		String VName=sc.nextLine();
		System.out.print("请输入您的性别:");
		String sex=sc.nextLine();
		//将志愿者的信息存入到文件中
		bu.append(college+",");
		bu.append(ID+",");
		bu.append(VName+",");
		bu.append(sex);
		bu.append("\n");
		bu.close();
		System.out.println("信息已成功存入文件!");
	}
	public static void Judge() throws IOException {//报名裁判页面
		while(true){
			@SuppressWarnings("resource")
			Scanner sc=new Scanner(System.in);
			System.out.println("==============报名裁判页面==============");
			System.out.println("1.登记信息");
			System.out.println("2.查看比赛信息");
			System.out.println("3.退出");
			System.out.print("请输入您的操作:");
			int command=sc.nextInt();
			switch(command) {
			case 1:
				JInformation();//登记信息
				break;
			case 2:
				readFile();//查看比赛规则
				break;
			case 3:
				return;
			default:
				System.out.println("输入的指令不存在!");	
			}
		}
	}
	public static void JInformation() throws IOException {//将裁判信息存入文件
		@SuppressWarnings("resource")
		Scanner sc=new Scanner(System.in);
		String dir="D:/programming/MyJava/裁判信息.txt";
		File file=new File(dir);
		if(!file.exists()) {//如果文件不存在,则创建文件
			file.createNewFile();
		}
		BufferedWriter bu=new BufferedWriter(new FileWriter(file,true));
		System.out.print("请输入您的姓名:");
		String VName=sc.nextLine();
		System.out.print("请输入您的密码:");
		String code=sc.nextLine();
		System.out.print("请输入您的学院:");
		String college=sc.nextLine();
		System.out.print("请输入您的性别:");
		String sex=sc.nextLine();
		//将志愿者的信息存入到文件中
		bu.append(VName+",");
		bu.append(code+",");
		bu.append(college+",");
		bu.append(sex);
		bu.append("\n");
		bu.close();
		System.out.println("信息已成功存入文件!");
	}
	public static void readFile() throws IOException{//查看比赛规则
		String dir="D:/programming/MyJava/运动会项目规则.txt";
		File file=new File(dir);
		if(!file.exists()) {//如果文件不存在,则创建文件
			file.createNewFile();
		}
		String dir1="D:/programming/MyJava/比赛时间地点.txt";
		File file1=new File(dir1);
		if(!file1.exists()) {
			file1.createNewFile();
		}
		BufferedReader bu=new BufferedReader(new FileReader(file));//缓冲流读取
		@SuppressWarnings("resource")
		BufferedReader bu1=new BufferedReader(new FileReader(file1));
		String line;//整行读取
		String line1;
		System.out.println("==============比赛信息如下所示==============");
		while((line1=bu1.readLine())!=null) {
			System.out.println(line1);
		}
		System.out.println("");
		while((line=bu.readLine())!=null) {
			System.out.println(line);
		}
		bu.close();//关闭文件
	}
}

猜你喜欢

转载自blog.csdn.net/ZQY211210400628/article/details/131328555