20220225 º¹½À³ëÆ®
¹Ì´ÏÇÁ·ÎÁ§Æ® 5ÀÏÂ÷ + JAVA 3Â÷ ½ÃÇè (¼ºÀûó¸® ÇÁ·Î±×·¥)
package jslhrd.view;
import java.util.*;
import java.io.*;
public class jslScore {
static void scoreRead() {
String fname = "jslScore.txt";
String line = "";
File f = new File(fname);
try {
if (!f.exists()) {
FileWriter fw = new FileWriter(fname);
BufferedWriter bw = new BufferedWriter(fw);
bw.close();
}
} catch (IOException e) {
System.out.println("ÆÄÀÏÀ» ¸¸µé ¼ö°¡ ¾ø½À´Ï´Ù.");
}
try {
int i;
FileReader fr = new FileReader(fname);
BufferedReader br = new BufferedReader(fr);
for (i = 0; ( line = br.readLine() ) != null; i++) {
String[] ln=line.split(",");
String sub1=ln[3];
String sub2=ln[4];
String sub3=ln[5];
String sub4=ln[6];
String sub5=ln[7];
int total;
double avg;
total = Integer.parseInt(sub1)+Integer.parseInt(sub2)
+Integer.parseInt(sub3)+Integer.parseInt(sub4)+Integer.parseInt(sub5);
avg = total / 5 ;
for (int j = 0; j < ln.length; j++) {
System.out.printf("[%5s]",ln[j]);
}System.out.println();
System.out.println("Total: "+total);
System.out.println("AVG: "+avg);
}
if (i==0) { // ÆÄÀÏÀÌ ºñ¾îÀÖÀ¸¸é for¹®À» ¹Ù·Î ºüÁ®³ª¿À±â ¶§¹®¿¡ i´Â 0ÀÌ´Ù.
// ¸®½ºÆ®¿¡ ÇϳªÀÇ lineÀÌ¶óµµ Á¸ÀçÇϸé i++À» ÅëÇØ i´Â 1 ÀÌ»óÀÌ µÈ´Ù.
System.out.println("¸®½ºÆ®°¡ Á¸ÀçÇÏÁö ¾Ê½À´Ï´Ù.");
}
br.close();
} catch (IOException e) {
System.out.println("Error - FileReading");
}
}
static void scoreCreate() {
Scanner sc = new Scanner(System.in);
String fname="jslScore.txt";
String course;
String num;
String name;
String sub1;
String sub2;
String sub3;
String sub4;
String sub5;
String score_list="";
try{
FileWriter fw = new FileWriter(fname, true);
BufferedWriter bw = new BufferedWriter(fw);
System.out.println("Ãß°¡ÇÒ °úÁ¤¸íÀ» ÀÔ·ÂÇϽÿÀ.");
course = sc.nextLine();
System.out.println("Ãß°¡ÇÒ ±â¼ö¸¦ ÀÔ·ÂÇϽÿÀ.");
num = sc.nextLine();
System.out.println("Ãß°¡ÇÒ À̸§À» ÀÔ·ÂÇϽÿÀ.");
name = sc.nextLine();
System.out.println("Ãß°¡ÇÒ java¼ºÀûÀ» ÀÔ·ÂÇϽÿÀ.");
sub1 = sc.nextLine();
System.out.println("Ãß°¡ÇÒ jsp&servlet¼ºÀûÀ» ÀÔ·ÂÇϽÿÀ.");
sub2 = sc.nextLine();
System.out.println("Ãß°¡ÇÒ DB¼ºÀûÀ» ÀÔ·ÂÇϽÿÀ.");
sub3 = sc.nextLine();
System.out.println("Ãß°¡ÇÒ spring¼ºÀûÀ» ÀÔ·ÂÇϽÿÀ.");
sub4 = sc.nextLine();
System.out.println("Ãß°¡ÇÒ project¼ºÀûÀ» ÀÔ·ÂÇϽÿÀ.");
sub5 = sc.nextLine();
score_list=course+","+num+","+name+","+sub1+","+sub2+","+sub3+","+sub4+","+sub5;
System.out.println("Ãß°¡ÇÑ ³»¿ë: "+score_list);
bw.write(score_list);
bw.newLine();
bw.close();
} catch (IOException e) {
System.out.println("Error - FileWriting");
}
}
static void scoreUpdate() {
System.out.println("update!!");
}
static void scoreDelete() {
System.out.println("delete!!");
}
static void scoreSearch() {
System.out.println("search!!.");
}
static void scoreBackup() {
System.out.println("backup!!");
}
static void scoreMenu() {
System.out.println("1. ¼ºÀû¸®½ºÆ® º¸±â");
System.out.println("2. ¼ºÀû Ãß°¡");
System.out.println("3. ¼ºÀû ¼öÁ¤");
System.out.println("4. ¼ºÀû »èÁ¦");
System.out.println("5. ¼ºÀû °Ë»ö");
System.out.println("6. Á¾·á");
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String select="";
while (select!="6") {
scoreMenu();
System.out.println("¿øÇÏ´Â ¸Þ´ºÀÇ ¹øÈ£¸¦ ¼±ÅÃÇϽÿÀ.");
select = sc.nextLine();
System.out.println("¼±Åà ¹øÈ£: "+select);
switch (select) {
case "1":
scoreRead();
break;
case "2":
scoreCreate();
break;
case "3":
scoreUpdate();
break;
case "4":
scoreDelete();
break;
case "5":
scoreSearch();
break;
case "6":
scoreBackup();
return;
default:
System.out.println("À߸øµÈ ¹øÈ£. ´Ù½Ã ÀÔ·ÂÇϽÿÀ.");
break;
}
}
}
}