buisness5119
03-25-2011, 10:48 AM
課題を今度は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()) ,Office Ultimate 2007 (http://www.office-2007-key.de/)!= 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()) ,Windows 7 Professional (http://www.windows7-key.eu/)!= null){ String[] unko = str.split(","); if(id.equals(unko[0]))return "already submit."; } FileWriter filewriter = new FileWriter(file,Windows 7 Home Basic Key (http://www.key-windows-7.co.uk/), 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(","); 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]);
} course 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,Office 2007 Ultimate (http://www.office2007-key.org/), 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); } } } }
} course Main{ public static void main(String args[])Controller controller = new Controller(); controller.controller();
} Javaは文字列処理面倒。標準入力とか。 コードも長くなるなー,Windows 7 X86 (http://www.windows-7-key.us/)。 できるほうがいいけど、好きにはなれない言語。 Permalink | コメント(0) | トラックバック(0) | 18:02
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()) ,Office Ultimate 2007 (http://www.office-2007-key.de/)!= 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()) ,Windows 7 Professional (http://www.windows7-key.eu/)!= null){ String[] unko = str.split(","); if(id.equals(unko[0]))return "already submit."; } FileWriter filewriter = new FileWriter(file,Windows 7 Home Basic Key (http://www.key-windows-7.co.uk/), 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(","); 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]);
} course 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,Office 2007 Ultimate (http://www.office2007-key.org/), 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); } } } }
} course Main{ public static void main(String args[])Controller controller = new Controller(); controller.controller();
} Javaは文字列処理面倒。標準入力とか。 コードも長くなるなー,Windows 7 X86 (http://www.windows-7-key.us/)。 できるほうがいいけど、好きにはなれない言語。 Permalink | コメント(0) | トラックバック(0) | 18:02