티스토리 뷰

반응형
package prj190703;

import java.util.*;

public class School {

	public static void main(String[] args) {
		
		Manager s = new Manager();
		Scanner scan = new Scanner(System.in);
		
		int count;
		
		boolean chk = false;
		
		System.out.print("입력할 학생 수 ?>>");
		count = scan.nextInt();
		Manager[] arr = new Manager[count];
		
		for(int i =0; i<arr.length; i++) {
			arr[i] = new Manager();
		} //배열도 초기화를 꼭 해줄 것. 
		
				
		while(true) {
			
			System.out.print("메뉴 입력>> 1. 입력 2. 출력 3.종료");
			
			int order = scan.nextInt();
			
			if(order == 1&&chk==false) { //manager s의 배열을 만들어서 for문을 돌려가며 저장하면? 
				for(int i =0; i<arr.length; i++) {
					System.out.print("이름 : ");
					arr[i].setName(scan.next());
					System.out.print("국어 : ");
					arr[i].setKor(scan.nextInt());
					System.out.print("수학 : ");
					arr[i].setMath(scan.nextInt());
					System.out.print("영어 : ");
					arr[i].setEng(scan.nextInt());
					System.out.printf("===================%d번째입력 끝===================\n", i+1);
				}//for end
				chk = true;
			} //if end
			else if(order==1 &&chk==true) {
				System.out.println("입력된 데이터가 존재합니다. 출력하세요.");
			}//else if end		
			else if(order == 2&&chk==true) { //manager s배열을 for문 만큼 돌려서 입력받고 for문으로 출력? 
				for(int i =0; i<arr.length; i++) {
					int total = 0;
					total = arr[i].getEng()+arr[i].getKor()+arr[i].getMath();
					float avg = total/3;
					
					System.out.println("이름 : " + arr[i].getName());
					System.out.println("국어 : " + arr[i].getKor());
					System.out.println("수학 :  " + arr[i].getMath());
					System.out.println("영어 : " + arr[i].getEng());
					System.out.println("총점 : " +total);
					System.out.println("평균 : " +(int)avg);
					System.out.println("등급 : "+grade((int)avg));
					System.out.printf("===================%d번째출력 끝===================\n", i+1);
				}//for end
				chk = false;
			}//else if end
			else if(order==2 && chk ==false) System.out.println("데이터 출력 완료, 재입력하세요");
			else if(order==3) {
				System.out.println("종료");
				break;
			}//else if end
		}//while end		
	} //class end
	
	public static char grade(int a) {
		char c=' ';
		if(a>=90 &&a<100) c= 'A';
		else if(a>=80) c = 'B';
		else if(a>=70) c = 'C';
		else if(a>=60) c = 'D';
		else c = 'F';
		return c;
		}
}//main end

 

 

 

//클래스 부분

package prj190703;

public class Manager {
	private String name = "";
	private int kor;
	private int math;
	private int eng;

	////////////setter
	public void setName(String name) {
		this.name = name;
	}
	public void setKor(int kor) {
		this.kor = kor;
	}
	public void setMath(int math) {
		this.math = math;
	}
	public void setEng(int eng) {
		this.eng = eng;
	}
	
	////////////getter
	public String getName() {
		return name;
	}
	public int getKor() {
		return kor;
	}
	public int getMath() {
		return math;
	}
	public int getEng() {
		return eng;
	}
}

 

 

 

 

 

반응형