其他分享
首页 > 其他分享> > 新课程添加

新课程添加

作者:互联网

(1)新课程信息必须唯一,如有重复,提示用户“课程名称重复,重新录入”;

(2)要求判断任课教师为王建民、刘立嘉、刘丹、王辉、杨子光五位教师的其中一位。

(3)要求上课地点开头为“一教、二教、三教、基教”中的一种;

(4)将新课程信息添加入库。

package Curriculum;

import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.Scanner;

import javax.swing.JOptionPane;

public class Curriculum 
{
    public static String[] readFile()
    {
        int i=0;
        String pathname="课程.txt";
        String[] m=new String[26];
        try
        (
                FileReader reader=new FileReader(pathname);
                BufferedReader br=new BufferedReader(reader)
        )
        {
            String d;
            while((d=br.readLine())!=null)
            {
                m[i]=d;
                i++;
            }
        }
        catch(IOException e)
        {
            e.printStackTrace();
        }
        return m;
    }
    public static void main(String[] args) 
    {
        String[] line=readFile();
        String a1="王建民",a2="刘立嘉",a3="刘丹",a4="王辉",a5="杨子光";
        String b1="一教*",b2="二教*",b3="三教*",b4="基教*";
        String imput1,imput2,imput3;
        for(int i=0;;i++)
        {
            imput1=JOptionPane.showInputDialog("课程名称:");
            int sign=1;
            for(int j=0;j<line.length;j++)
            {
                String[] words=line[i].split("/");
                if(imput1.equals(words[0]))
                {
                    sign=0;
                    break;
                }
            }
            if(sign==1);
            {
                JOptionPane.showMessageDialog(null, "录入成功,请继续录入。");
                break;
            }
            else
            {
                JOptionPane.showMessageDialog(null, imput1+"已存在,请重新录入。");
            }
        }
        for(int j=0;;j++)
        {
            imput2=JOptionPane.showInputDialog("任课老师:");
            if(a1.equals(imput2)||
               a2.equals(imput2)||
               a3.equals(imput2)||
               a4.equals(imput2)||
               a5.equals(imput2))
            {
                JOptionPane.showMessageDialog(null, "录入成功,请继续录入。");
                break;
            }
            else
            {
                JOptionPane.showMessageDialog(null, "没有任课老师:"+imput2+",请重新录入。");
            }
        }
        for(int k=0;;k++)
        {
            imput3=JOptionPane.showInputDialog("上课地点:");
            if(b1.equals(imput3)||
               b2.equals(imput3)||
               b3.equals(imput3)||
               b4.equals(imput3))
            {
                JOptionPane.showMessageDialog(null, "录入完成。");
                break;
            }
            else
            {
                JOptionPane.showMessageDialog(null, "没有上课地点:"+imput3+",请重新录入。");
            }
        }
        PrintWriter wi=new PrintWriter(new OutputStreamWriter(new FileOutputStream("file.txt"),"gbk"));
        wi.println(imput1+"/"+imput2+"/"+imput3+"/");
        wi.close();
        BufferedReader re=new BufferedReader(new InputStreamReader(new FileInputStream("file.txt"),"gbk"));
        String ss=null;
        if((ss=re.readLine())!=null)
        {
        System.out.println(ss);
        }
        re.close();
    }            
}

 

标签:新课程,java,String,int,添加,io,import
来源: https://www.cnblogs.com/zql-42/p/11708113.html