課題を今度はJavaで Java (25 修正) 多分Windowsじゃないと動かんです。 ソースコード
import java.io.*; course Model{ public boolean login(String id, String password){ boolean flag = false; try{ File file = new File("accunt.txt"); BufferedReader br = new BufferedReader(new FileReader(file)); String str; while((str = br.readLine()) ,
Windows 7 Product Key!= null){ if ((id + "," + password).equals(str))flag = true; } br.close(); }catch(FileNotFoundException e)System.out.println(e);catch(IOException e)System.out.println(e); return flag; } public String submit(String id){ try{ File file = new File("submit.txt"); BufferedReader br = new BufferedReader(new FileReader(file)); String str; while((str = br.readLine()) != null){ String[] unko = str.split(","); if(id.equals(unko[0]))return "already submit."; } FileWriter filewriter = new FileWriter(file, true); filewriter.write(id + "\r\n"); filewriter.close(); return "true"; }catch(FileNotFoundException e)System.out.println(e);catch(IOException e)System.out.println(e); return "false"; } public int[] getscore(String id){ int[] timpo = new int[2]; try{ File file = new File("score.txt"); BufferedReader br = new BufferedReader(new FileReader(file)); String str; while((str = br.readLine()) != null){ String[] unko = str.split(","); if(id.equals(unko[0]))timpo[0] = Integer.valueOf(unko[1]).intValue(); System.out.println("aaaaaaa"); timpo[1] = this.getaverage(); return timpo; } }catch(FileNotFoundException e)System.out.println(e);catch(IOException e)System.out.println(e); return timpo; } public int getaverage(){ int i = 0; try{ File file = new File("score.txt"); BufferedReader br = new BufferedReader(new FileReader(file)); String str; while((str = br.readLine()) != null)String[] unko = str.split(","); i += Integer.valueOf(unko[1]).intValue(); }catch(FileNotFoundException e)System.out.println(e);catch(IOException e)System.out.println(e); return i; } public String check(String student){ try{ File file = new File("submit.txt"); BufferedReader br = new BufferedReader(new FileReader(file)); String str; while((str = br.readLine()) != null){ String[] unko = str.split(","); if(student.equals(unko[0]))return "true"; } }catch(FileNotFoundException e)System.out.println(e);catch(IOException e)System.out.println(e); return "false"; } public String mark(String student, String score){ try{ File file = new File("score.txt"); BufferedReader br = new BufferedReader(new FileReader(file)); String str; while((str = br.readLine()) != null){ String[] unko = str.split(",
windows 7 pro serial key,"); if(student.equals(unko[0]))return "false"; } FileWriter filewriter = new FileWriter(file, true); filewriter.write(student + "," + score + "\r\n"); filewriter.close(); return "true"; }catch(FileNotFoundException e)System.out.println(e);catch(IOException e)System.out.println(e); return "false"; }
} course View{ public String[] login(){ String[] accunt = new String[2]; tryBufferedReader r1 = new BufferedReader(new InputStreamReader(System.in), 1); String id, password; System.out.flush(); System.out.print("Type ID : "); id = r1.readLine(); accunt[0] = id; BufferedReader r2 = new BufferedReader(new InputStreamReader(System.in), 1); System.out.print("Type PASSWORD : "); System.out.flush(); password = r2.readLine(); accunt[1] = password; return accunt;catch(IOException e)System.out.println(e); return accunt; } public String input_cmd(){ tryBufferedReader r = new BufferedReader(new InputStreamReader(System.in), 1); System.out.print("Type COMMAND : "); String cmd; System.out.flush(); cmd = r.readLine(); return cmd;catch(IOException e)System.out.println(e); return "exit"; } public String input_student(){ tryBufferedReader r = new BufferedReader(new InputStreamReader(System.in), 1); String student; System.out.print("Type Student ID : "); System.out.flush(); student = r.readLine(); return student;catch(IOException e)System.out.println(e); return ""; } public String input_score(){ tryBufferedReader r = new BufferedReader(new InputStreamReader(System.in), 1); String score; System.out.print("Type Student Score : "); System.out.flush(); score = r.readLine(); return score;catch(IOException e)System.out.println(e); return ""; } public void show(String result)System.out.println(result); public void show_score(int[] score)System.out.println(score[0] + " " + score[1]);
} class Controller{ String result; int[] score_result; Controller()result = " "; score_result = new int[2]; public void controller(){ View view = new View(); Model model = new Model(); String[] accunt = view.login(); String id = accunt[0]; String password = accunt[1]; if(model.login(id, password)==true){ while(true){ String cmd = view.input_cmd(); if(cmd.equals("q"))System.exit(1); if(id.equals("teacher")){ String student = view.input_student(); if(cmd.equals("mark"))String score = view.input_score(); result = model.mark(student,
Microsoft Office 2007 Código, score); view.show(result); else if(cmd.equals("check"))result = model.check(student); view.show(result); } else { if(cmd.equals("submit"))result = model.submit(id); view.show(result); else if(cmd.equals("getscore"))score_result = model.getscore(id); view.show_score(score_result); } } } }
} class Main{ public static void main(String args[])Controller controller = new Controller(); controller.controller();
} Javaは文字列処理面倒,
microsoft office Standard 2007。標準入力とか,
microsoft office 2007 Ultimate keygen。 コードも長くなるなー。 できるほうがいいけど、好きにはなれない言語。 Permalink | コメント(0) | トラックバック(0) | 18:02