Java

试题信息管理系统无需数据库

2021-04-18  本文已影响0人  花伤情犹在

Test类:

package 试题信息管理系统无需数据库;

public class Test {
    public static void main(String[] args) {
        new QuestionInfo().Initialization();//初始化信息
        new QuestionInfo().Menu();//调用菜单
    }
}

信息类:

package 试题信息管理系统无需数据库;

public class QuestionInfoManger {
    //试题编号
    int Questionid;
    //题干
    String Question;
    //选项A
    String optionA;
    //选项B
    String optionB;
    //选项C
    String optionC;
    //选项D
    String optionD;
    //科目
    String subject;
    //正确答案
    String answer;

    public int getQuestionid() {
        return Questionid;
    }

    public void setQuestionid(int questionid) {
        Questionid = questionid;
    }

    public String getQuestion() {
        return Question;
    }

    public void setQuestion(String question) {
        Question = question;
    }

    public String getOptionA() {
        return optionA;
    }

    public void setOptionA(String optionA) {
        this.optionA = optionA;
    }

    public String getOptionB() {
        return optionB;
    }

    public void setOptionB(String optionB) {
        this.optionB = optionB;
    }

    public String getOptionC() {
        return optionC;
    }

    public void setOptionC(String optionC) {
        this.optionC = optionC;
    }

    public String getOptionD() {
        return optionD;
    }

    public void setOptionD(String optionD) {
        this.optionD = optionD;
    }

    public String getSubject() {
        return subject;
    }

    public void setSubject(String subject) {
        this.subject = subject;
    }

    public String getAnswer() {
        return answer;
    }

    public void setAnswer(String answer) {
        this.answer = answer;
    }

    @Override
    public String toString() {
        return Questionid+"、"+Question+"\n"+"\t\t\t"+"选项A:"+optionA
                +"\n"+"\t\t\t"+"选项B:"+optionB+"\n"+"\t\t\t"+"选项C:"+optionC
                +"\n"+"\t\t\t"+"选项D:"+optionD+"\t\t\t"+"\n"+"\t\t\t"+"正确答案:"+answer+"\n";
    }
}

菜单类:

package 试题信息管理系统无需数据库;

import java.util.ArrayList;
import java.util.Scanner;

public class QuestionInfo {
    //定义QuestionInfoManger对象数组
    static ArrayList<QuestionInfoManger> Question=new ArrayList<>();
    //初始化信息
    public void Initialization(){
                //创建对象
                QuestionInfoManger questionInfoManger = new QuestionInfoManger();
                //填充信息到对象
                questionInfoManger.setQuestionid(1);
                questionInfoManger.setQuestion("变量命名规范说法正确的是");
                questionInfoManger.setOptionA("变量由字母、下划线、数字、符号随意组成;");
                questionInfoManger.setOptionB("变量不能以数字作为开头;");
                questionInfoManger.setOptionC("A和a在java中是同一个变量");
                questionInfoManger.setOptionD("不同类型的变量,可以起相同的名字;");
                questionInfoManger.setSubject("Java");
                questionInfoManger.setAnswer("B");
                //将对象添加到对象数组中
                Question.add(questionInfoManger);
                //创建对象
                QuestionInfoManger questionInfoManger2 = new QuestionInfoManger();
                //填充信息到对象
                questionInfoManger2.setQuestionid(2);
                questionInfoManger2.setQuestion("以下叙述正确的是:");
                questionInfoManger2.setOptionA("接口中可以有虚方法");
                questionInfoManger2.setOptionB("一个类可以实现多个接口");
                questionInfoManger2.setOptionC("接口不能被实例化");
                questionInfoManger2.setOptionD("接口中可以包含已实现的方法 ");
                questionInfoManger2.setSubject("C#");
                questionInfoManger2.setAnswer("BC");
                //将对象添加到对象数组中
               Question.add(questionInfoManger2);
    }
    //菜单
    public void Menu(){
        while (true){
            System.out.println("*****************欢迎使用试题管理系统*****************");
            System.out.println();
            System.out.println("请选择操作(1.列出所有试题 2.按科目查询 3.按题干查询 4.添加试题 5.删除试题 6.退出系统)");
            Scanner scanner=new Scanner(System.in);
            int num=scanner.nextInt();
            switch (num){
                case 1:
                    one();break;
                case 2:
                    two();break;
                case 3:
                    three();break;
                case 4:
                    four();break;
                case 5:
                    five();break;
                case 6:
                    six();break;
                default:
                    System.out.println("输入错误,请重新输入!");
            }
        }
    }

    //1.列出所有试题
    public void one(){
        for (int i = 0; i < Question.size(); i++) {
            System.out.println(Question.get(i).toString());
        }
    }
    //2.按科目查询
    public void two(){
            System.out.println("请输入科目:(1.Java 2.C# 3.JSP)");
            Scanner scanner=new Scanner(System.in);
            int num=scanner.nextInt();
            switch (num){
                case 1:
                    for (int i = 0; i < Question.size(); i++) {
                        if (Question.get(i).subject.equals("Java")) {
                            System.out.println(Question.get(i).toString());
                        }
                    }
                    break;
                case 2:
                    for (int i = 0; i < Question.size(); i++) {
                        if (Question.get(i).subject.equals("C#")) {
                            System.out.println(Question.get(i).toString());
                        }
                    }
                    break;
                case 3:
                    for (int i = 0; i < Question.size(); i++) {
                        if (Question.get(i).subject.equals("JSP")) {
                            System.out.println(Question.get(i).toString());
                        }
                    }
                    break;
                default:
                    System.out.println("输出错误,请重新输入!");
            }
    }

    //3.按题干查询
    public void three(){
        System.out.println("请输入题干:");
        Scanner scanner=new Scanner(System.in);
        String str=scanner.nextLine();
        for(int i=0;i<Question.size();i++){
            if(Question.get(i).getQuestion().indexOf(str)>=0) {
                System.out.println(Question.get(i).toString());
            }
        }
    }


    //4.添加试题
    public void four(){
        int size=Question.size()+1;
        Scanner scanner=new Scanner(System.in);
        System.out.println("请输入题干:");
        String question=scanner.nextLine();
        System.out.println("请输入选项A:");
        String optionA=scanner.nextLine();
        System.out.println("请输入选项B:");
        String optionB=scanner.nextLine();
        System.out.println("请输入选项C:");
        String optionC=scanner.nextLine();
        System.out.println("请输入选项D:");
        String optionD=scanner.nextLine();
        System.out.println("请输入科目:");
        String subject=scanner.nextLine();
        System.out.println("请输入答案:");
        String answer=scanner.nextLine();
        QuestionInfoManger questionInfoManger=new QuestionInfoManger();
        questionInfoManger.setQuestionid(size);
        questionInfoManger.setQuestion(question);
        questionInfoManger.setOptionA(optionA);
        questionInfoManger.setOptionB(optionB);
        questionInfoManger.setOptionC(optionC);
        questionInfoManger.setOptionD(optionD);
        questionInfoManger.setSubject(subject);
        questionInfoManger.setAnswer(answer);
        Question.add(questionInfoManger);
        System.out.println("添加成功");
    }

    // 5.删除试题
    public void five(){
        while (true){
            System.out.println("请输入要删除的试题编号:");
            Scanner scanner=new Scanner(System.in);
            int i=scanner.nextInt();
            int size=Question.size();
            if (i>size){
                System.out.println("对不起,没有要删除的试题编号,请重新输入");
            }else {
                Question.remove(i-1);
                System.out.println("删除成功");
                break;
            }
        }
    }

    //6.退出系统
    public void six(){
        System.out.println("退出系统");
        System.exit(0);
    }
}


上一篇下一篇

猜你喜欢

热点阅读