package struct;
import java.util.Scanner;
public class Program2
{
static int inputMenu() //메뉴출력함수
{
Scanner scan= new Scanner(System.in);
int menu;
System.out.println("┌─────────────────┐");
System.out.println("│ 메인 메뉴 │");
System.out.println("└─────────────────┘");
System.out.print("\t\t1.성적 입력\n");
System.out.print("\t\t2.성적 출력\n");
System.out.print("\t\t3.종료\n");
menu = scan.nextInt();
return menu;
}
static void inputRecord(Record record) //성적입력함수
{
Scanner scan= new Scanner(System.in);
int kor, eng, math; //임시변수선언
System.out.println("┌─────────────────┐");
System.out.println("│ 성적 입력 │");
System.out.println("└─────────────────┘");
do{
System.out.println("\t\t국어 :");
kor = scan.nextInt();
if(kor<0 || kor>100)
System.out.println("범위벗어남");
}
while(kor<0 || kor>100);
do{
System.out.print("\t\t영어 :");
eng = scan.nextInt();
if(eng<0 || eng>100)
System.out.println("범위벗어남");
}
while(eng<0 || eng>100);
do{
System.out.print("\t\t수학 :");
math = scan.nextInt();
if(math<0 || math>100)
System.out.println("범위벗어남");
}
while(math<0 || math>100);
record.kor=kor;
record.eng=eng;
record.math=math;
}
static void printRecord(Record record)//성적출력함수
{
int total = record.kor + record.eng + record.math;
float avg = total / 3.0f;
System.out.printf("┌─────────────────┐\n");
System.out.printf("│ @본인 이름 성적표@ │\n");
System.out.printf("├──┬──┬──┬──┬──┬──┤\n");
System.out.printf("│번호│국어│영어│수학│총점│평균│\n");
for(int i=0 ; i<3 ; i++)
{
System.out.printf("├──┼──┼──┼──┼──┼──┤\n");
System.out.printf("│%-5d│%-5d│%-5d│%-5d│%-5d│%4.2f│\n",i+1,record.kor,record.eng,record.math,total,avg);
}
System.out.printf("└──┴──┴──┴──┴──┴──┘\n");
}
public static void main(String[] args)
{
Record record = new Record();
/* int kor=0;
int eng=0;
int math=0;*/
int menu;
int i;
Scanner scan = new Scanner(System.in);
exit:while(true)
{
/*menu = inputMenu();*/
/* System.out.println("┌─────────────────┐");
System.out.println("│ 메인 메뉴 │");
System.out.println("└─────────────────┘");
System.out.print("\t\t1.성적 입력\n");
System.out.print("\t\t2.성적 출력\n");
System.out.print("\t\t3.종료\n");
menu = scan.nextInt();*/
switch(menu = inputMenu())
{
case 1:
inputRecord(record);
//inputRecord(kor,eng,math);
/* System.out.println("┌─────────────────┐");
System.out.println("│ 성적 입력 │");
System.out.println("└─────────────────┘");
do{
System.out.println("\t\t국어 :");
kor = scan.nextInt();
if(kor<0 || kor>100)
System.out.println("범위벗어남");
}
while(kor<0 || kor>100);
do{
System.out.print("\t\t영어 :");
eng = scan.nextInt();
if(eng<0 || eng>100)
System.out.println("범위벗어남");
}
while(eng<0 || eng>100);
do{
System.out.print("\t\t수학 :");
math = scan.nextInt();
if(math<0 || math>100)
System.out.println("범위벗어남");
}
while(math<0 || math>100);
*/
break;
case 2:
printRecord(record);
/*total = kor + eng + math;
avg = total / 3.0f;
System.out.printf("┌─────────────────┐\n");
System.out.printf("│ @본인 이름 성적표@ │\n");
System.out.printf("├──┬──┬──┬──┬──┬──┤\n");
System.out.printf("│번호│국어│영어│수학│총점│평균│\n");
for(i=0 ; i<3 ; i++)
{
System.out.printf("├──┼──┼──┼──┼──┼──┤\n");
System.out.printf("│%-5d│%-5d│%-5d│%-5d│%-5d│%4.2f│\n",i+1,kor,eng,math,total,avg);
}
System.out.printf("└──┴──┴──┴──┴──┴──┘\n");*/
break;
case 3:
System.out.println("프로그램이 종료됩니다.");
break exit;
default:
System.out.println("입력 오류");
}
}
}
}