Java 学生成绩管理系统

具备对学生信息的创建、显示、插入、查询、删除、更改等功能
system.java代码如下:

import java.util.*;
class Student
{
	private long x;
	private String n;
	private double s1,s2;
	public Student(long x,String n,double s1,double s2)
	{
		this.x=x;
		this.n=n;
		this.s1=s1;
		this.s2=s2;
	}
	public long get_x()
	{
		return x;
	}
	public void set_x(long x)
	{
		this.x=x;
	}
	public String get_n()
	{
		return n;
	}
	public void set_n(String n)
	{
		this.n=n;
	}
	public double get_s1()
	{
		return s1;
	}
	public void set_s1(double s1)
	{
		this.s1=s1;
	}
	public double get_s2()
	{
		return s2;
	}
	public void set_s2(double s2)
	{
		this.s2=s2;
	}
	public void nnss()
	{
		System.out.println("[ 'number':"+x+" 'name':"+n+" 'score1':"+s1+" 'score2':"+s2+" ]");
	}
}
public class system
{
	static Scanner a=new Scanner(System.in);
	static List<Student> l=new ArrayList<>();//创建关于类Student的列表,防止数据丢失
	static void create()
	{
		System.out.println("请输入:[学号] [姓名] [分数1] [分数2] (注意学号为0时输入结束!)");
		long x=a.nextLong();
		String n=a.next();
		double s1=a.nextDouble();
		double s2=a.nextDouble();
		Student b=new Student(x,n,s1,s2);
		l.add(b);
		while(x!=0)
		{
			x=a.nextLong();
			if(x==0)
				break;//学号为0,结束输入
			n=a.next();
			s1=a.nextDouble();
			s2=a.nextDouble();
			b=new Student(x,n,s1,s2);
			l.add(b);
		}
	}
	static void show_all()
	{
		System.out.println("所有学生的信息如下:");
		for(int i=0;i<l.size();i++)
		{
			Student c=l.get(i);
			c.nnss();
		}
	}
	static void search_x()
	{
		boolean e=true;
		System.out.println("请输入要查询的学生信息的学生学号:");
		System.out.print("number: ");
		long x=a.nextLong();
		System.out.println();
		for(int i=0;i<l.size();i++)
		{
			Student c=l.get(i);
			if(c.get_x()==x)
			{
				e=false;
				System.out.println("您所查询的学生信息如下:");
				c.nnss();
				break;
			}
		}
		if(e)
			System.out.println("Error! No such student !");
	}
	static void search_n()
	{
		boolean e=true;
		System.out.println("请输入要查询的学生信息的学生姓名:");
		System.out.print("name: ");
		String n=a.next();
		System.out.println();
		for(int i=0;i<l.size();i++)
		{
			Student c=l.get(i);
			if(n.equals(c.get_n()))
			{
				e=false;
				System.out.println("您所查询的学生信息如下:");
				c.nnss();
				break;
			}
		}
		if(e)
			System.out.println("Error! No such student !");
	}
	static void remove()
	{
		boolean e=true;
		System.out.println("请输入要删除的学生信息的学生学号:");
		System.out.print("number:");
		long x=a.nextLong();
		System.out.println();
		for(int i=0;i<l.size();i++)
		{
			Student c=l.get(i);
			if(c.get_x()==x)
			{
				e=false;
				System.out.println("您所删除的学生信息如下:");
				c.nnss();
				l.remove(i);
				break;
			}
		}
		if(e)
			System.out.println("Error! No such student !");
	}
	static void add() 
	{
		boolean e=true;
		System.out.println("请输入要插入的学生信息的学生[学号] [姓名] [分数1] [分数2] :");
		long x=a.nextLong();
		for(int i=0;i<l.size();i++)
		{
			Student c=l.get(i);
			if(x==c.get_x())
			{
				e=false;
				System.out.println("error! 这个学号已经存在了!!!"); //防止学号冲突
				break;
			}
		}
		if(e)
		{
			String n=a.next();
			double s1=a.nextDouble();
			double s2=a.nextDouble();
			Student b=new Student(x,n,s1,s2);
			l.add(b);
		}
	}
	static void modify()
	{
		boolean e=true;
		System.out.println("请输入要更改的学生信息的学生学号:");
		System.out.print("number: ");
		long x=a.nextLong();
		System.out.println();
		for(int i=0;i<l.size();i++)
		{
			Student c=l.get(i);
			if(c.get_x()==x)
			{
				e=false;
				c.nnss();
				System.out.println("请输入修改后的学生信息的学生[学号] [姓名] [分数1] [分数2] :");
				c.set_x(a.nextLong());
				c.set_n(a.next());
				c.set_s1(a.nextDouble());
				c.set_s2(a.nextDouble());
				break;
			}
		}
		if(e)
			System.out.println("Error! No such student !");
	}
	static void menu()
	{
		System.out.println("********************************");
		System.out.println("welcome to [JIT学生成绩管理系统]!!!");
		System.out.println("    1-创建学生信息");
		System.out.println("    2-查找某学号的学生信息");
		System.out.println("    3-查找某姓名的学生信息");
		System.out.println("    4-删除某学号的学生信息");
		System.out.println("    5-插入新的学生信息");
		System.out.println("    6-显示所有学生的个人信息");
		System.out.println("    7-更改学生个人信息");
		System.out.println("    0-退出");
		System.out.println("********************************");
		System.out.println();
		System.out.print("请选择您要执行的选项(以第一个数字为准):");
	}
	static void Enter()  
	{
		System.out.println();
		System.out.println("按回车继续");
		a.nextLine();
		a.nextLine();
	}
	public static void main(String[] args)
	{
		char g;
		boolean f=true;
		while(f)
		{
			menu();	
			g=a.next().charAt(0);
			switch(g)
			{
				case '1':
					if(l.isEmpty())
					{
						create();
						show_all();
					}
					else
						System.out.println("已有学生信息");
					Enter();
					break;
				case '2':
					if(l.isEmpty())
						System.out.println("没有学生的信息可查询");
					else
						search_x();
					Enter();
					break;
				case '3':
					if(l.isEmpty())
						System.out.println("没有学生的信息可查询");
					else
						search_n();
					Enter();
					break;
				case '4':
					if(l.isEmpty())
						System.out.println("没有学生的信息可删除");
					else
					{
						remove();
						if(l.isEmpty())
							System.out.println("学生信息已删空");
						else
							show_all();
					}
					Enter();
					break;
				case '5':
					add();
					show_all();
					Enter();
					break;
				case '6':
					if(l.isEmpty())
						System.out.println("没有学生的信息可显示");
					else
						show_all();
					Enter();
					break;
				case '7':
					if(l.isEmpty())
						System.out.println("没有学生的信息可修改");
					else
					{
						modify();
						show_all();
					}
					Enter();
					break;
				case '0':
					f=false;
					System.out.println("系统已退出!!!");
					break;
				default: 
					System.out.println("Wrong Selection!(输入错误!!)");
					Enter();
			}
		}
	}
}
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值