无mysql,基于java控制台实现的低配版学生成绩管理系统---记本java小白的项目初尝试

注:本人java小白一枚,写这篇文章时还没有开始学习数据库相关知识,但是很想练练手,顺便巩固一下一段时间以来学习的所有知识,如果有时间的话等我弄懂了数据库再来搞个2.0版本。

实现目标:能增删改查学生成绩,并实现学生成绩的统计(每位学生的总分,平均分,暂无所有学生成绩排序)

实现原理:数据通过Scanner类从键盘获取,用HashMap存储,学号为key值,value值为自定义的学生类

学生类

四大要素:成员变量,Constructor(含参及无参),getter和setter

public class Student {
    private String name;
    private int number;
    private String sex;
    private double Math;
    private double English;
    private double Chinese;
    private double ave;
    private double total;

    public Student(String name, int number, String sex, double math, double english, double chinese) {
        this.name = name;
        this.number = number;
        this.sex = sex;
        Math = math;
        English = english;
        Chinese = chinese;
    }

    public Student() {
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getNumber() {
        return number;
    }

    public void setNumber(int number) {
        this.number = number;
    }

    public String getSex() {
        return sex;
    }

    public void setSex(String sex) {
        this.sex = sex;
    }

    public double getMath() {
        return Math;
    }

    public void setMath(double math) {
        Math = math;
    }

    public double getEnglish() {
        return English;
    }

    public void setEnglish(double english) {
        English = english;
    }

    public double getChinese() {
        return Chinese;
    }

    public void setChinese(double chinese) {
        Chinese = chinese;
    }

    public double getAve() {
        return ave;
    }

    public void setAve(double ave) {
        this.ave = ave;
    }

    public double getTotal() {
        return total;
    }

    public void setTotal(double total) {
        this.total = total;
    }

这里按格式输出需求重写toString方法

   @Override
    public String toString() {
        String msg="\t\t"+this.number+"\t"+this.name+"\t"+this.sex+"\t"+this.Math+"\t"+this.English+"\t"+this.Chinese+"\t"+this.total+"\t"+this.ave;
        return msg;
    }

温馨提示:由于此处分开截取代码,最后的“}”我没截,如果有需要想复制粘贴的,记得自己补上。

相关方法类
import java.util.HashMap;
import java.util.Iterator;
import java.util.Scanner;



public class CorrespondingMethod {

   private static HashMap map=new HashMap();
    public static Scanner sc=new Scanner(System.in);
   static String msg="\t\t学号\t姓名\t性别\t数学\t英语\t语文\t总分\t平均分\t\t";
    /*//CorrespondingMethod(){
        map=new HashMap();
    }*/
    /*主要实现功能:成绩的增删改查
    辅助功能:显示成绩(show),展示操作选项(mymenu)
    * */
  public static void creatdata(){
      Student student=new Student();
      System.out.println("学号:");
      student.setNumber(sc.nextInt());
      System.out.println("请输入学生姓名:");
      student.setName(sc.next());
      System.out.println("性别:");
      student.setSex(sc.next());
      System.out.println("数学成绩:");
      student.setMath(sc.nextDouble());
      System.out.println("英语成绩:");
      student.setEnglish(sc.nextDouble());
      System.out.println("语文成绩:");
      student.setChinese(sc.nextDouble());
     double total=student.getChinese()+student.getEnglish()+student.getMath();
     double ave=total/3.0;
      student.setTotal(total);
      student.setAve(ave);
int key=student.getNumber();
map.put(key,student);
      System.out.println("添加学生成功!");
      show();
  }
  public static void deletedata(){//通过输入学生的学号来删除所有信息
      System.out.println("请输入要删除信息的学生的学号:");
      int num=sc.nextInt();
      if(map.containsKey(num)){
          map.remove(num);
          System.out.println("学生删除成功!");
          show();
      }
      else{
          System.out.println("该学生信息不存在");
      }
  }
  public static  void updatedata(){
      System.out.println("请输入要修改信息的学生的学号:");
      int num=sc.nextInt();
      if(map.containsKey(num)){
          Student stu=(Student)map.get(num);
          System.out.println("提示:本系统仅支持更新学生的姓名与性别信息,详细成绩信息请联系管理员经由其他渠道更新。");
          System.out.println("请输入修改后的学生姓名:");
          stu.setName(sc.next());
          System.out.println("修改后的学生性别:");
          stu.setSex(sc.next());
          System.out.println("学生修改成功!");
          show();
      }
      else{
          System.out.println("该学生信息不存在");
      }
  }
  public static void mysearch(){

      System.out.println("请输入要查找信息的学生的学号:");
      int num=sc.nextInt();
      if(map.containsKey(num)){
          Student stu=(Student)map.get(num);
          System.out.println(msg);
          System.out.println(map.get(num));
      }
      else{
          System.out.println("该学生信息不存在");
      }
  }
  public static void itsmenu(){
      System.out.println("请输入你想实现的操作的序号:");
      System.out.println("1,增加学生信息");
      System.out.println("2,删除学生信息");
      System.out.println("3,查找学生信息");
      System.out.println("4,更新学生基本信息");
      System.out.println("5,退出系统");
  }
  public static void exits(){
System.exit(0);

  }
  public static void show(){
      if(map.size()==0){
          System.out.println("暂无学生信息数据");

      }
      else{
          System.out.println("目前共有"+map.size()+"位学生数据");
          System.out.println(msg);
          //取出所有map键
          Iterator it=map.keySet().iterator();
while(it.hasNext()){
    int key=Integer.parseInt(it.next().toString());
    Student stu=(Student) map.get(key);
    System.out.println(stu);
}
      }
  }
}

关于主方法
import java.util.Scanner;

import static Studentmanagement.CorrespondingMethod.*;


public class Demotrun {
    public static Scanner point=new Scanner(System.in);
    public static void main(String[] args) {
     while(true){
         itsmenu();//打印可执行的选项:12345分别指增删查改退功能
         int goal=point.nextInt();
         switch(goal){
             case 1:creatdata();break;
             case 2:deletedata();break;
             case 3:mysearch();break;
             case 4:updatedata();break;
             case 5:exits();break;
             default:
                 System.out.println("输入有误,请重新输入:");
         }
     }

    }
}

运行结果

在这里插入图片描述

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

(有点懒,输出那里没对齐……下次注意……)

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值