본문 바로가기
웹 풀스택 스터디(뉴렉처-학원)--> 이거 꼭 보세요

10. for,while문 과제 공부 및 복습

by 백엔드개발자0107 2021. 8. 15.
package ex6;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.PrintStream;
import java.util.Scanner;

public class GradeProgram {

	public static void main(String[] args) throws IOException {
		
		File data = new File("res/data-copy2.txt");
		
		FileInputStream fis = new FileInputStream(data);
		
		Scanner scanner = new Scanner(fis);
		
		File gradePath = new File("res/data-grade1.txt");
		
		if(!gradePath.exists())
			gradePath.mkdir();
		
		FileOutputStream fos = new FileOutputStream(gradePath);
		PrintStream ps = new PrintStream(fos);
		
		int gradeInt = 0;
		String grade = "";
		String total = "";
		
		while(scanner.hasNext()) {
			
			String g = scanner.next();
			gradeInt = Integer.parseInt(g);
			
			if(gradeInt>100 || gradeInt<0) {
				ps.print("wrong score Inserted");
				break;
				
			}else if(gradeInt>=95 && gradeInt<=100) {
				
				grade = "A+";
			}else if(gradeInt>=90 && gradeInt<=94) {
				

				grade = "A";
			}
			
			
			
			
			
		}
		
		
		
		
		
		
	}
	
	
}

자, 위 코드는 학점관리 프로그램 코드이다.