본문 바로가기

백준 문제풀기/JAVA

[백준 25206 JAVA 자바] 너의 평점은

 

전공 평접을 출력합시다

 

과목 이름은 신경 쓰지 말고

학점과 성적을 곱한 값의

평균을 구해줍시다

 

코드입니다

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        

        double hap = 0;
        double jumsoo = 0;
        
        for(int i=0;i<20;i++) {
        	StringTokenizer st = new StringTokenizer(br.readLine());
        	
        	String str = st.nextToken();
            double a = Double.parseDouble(st.nextToken());
            String grade = st.nextToken();
            
            if(grade.equals("P"))continue;
            hap += a;
            
            if (grade.equals("A+")) jumsoo += a*4.5;
            else if (grade.equals("A0")) jumsoo += a*4.0;
            else if (grade.equals("B+")) jumsoo += a*3.5;
            else if (grade.equals("B0")) jumsoo += a*3.0;
            else if (grade.equals("C+")) jumsoo += a*2.5;
            else if (grade.equals("C0")) jumsoo += a*2.0;
            else if (grade.equals("D+")) jumsoo += a*1.5;
            else if (grade.equals("D0")) jumsoo += a*1.0;
            else if (grade.equals("F")) jumsoo += a*0.0;           
        }
        System.out.println(jumsoo/hap);        
    }
}