S007_Sungjuk_UnivStudent 대학성적 계산예제

Posted by PeEn
2019. 5. 14. 11:32 Programing/Java
실행결과 소스코드
package kr.ac.jj.java201562054;

import java.util.Scanner;

public class S007_Sungjuk_UnivStudent {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		UnivStudent US = new UnivStudent();
		US.Input();
		US.Output();
	}

}

class UnivStudent {
	String stud_id; // 학번
	String name; // 이름
	String course; // 과목
	int pres; // 출석점수
	int rep; // 과제점수
	int midt; // 중간점수
	int finalt; // 기말점수
	double score; // 점수
	String grade; // 학점
	Scanner scan = new Scanner(System.in);

	void Input() {
		System.out.print("학번:");
		stud_id = scan.next();
		System.out.print("이름:");
		name = scan.next();
		System.out.print("과목:");
		course = scan.next();
		System.out.print("출석점수:");
		pres = scan.nextInt();
		System.out.print("과제점수:");
		rep = scan.nextInt();
		System.out.print("중간점수:");
		midt = scan.nextInt();
		System.out.print("기말점수:");
		finalt = scan.nextInt();
		Calcu();

	}

	void Output() {
		System.out.print(name + "학생의 총점은 " + score + "이고 학점은 " + grade + "입니다."

		);

	}

	void Calcu() {
		score = (pres + rep + midt + finalt) / 4.0;
		if (score >= 95) {
			grade = "A+";

		} else if (score <= 94 & score > 89) {
			grade = "A";
		} else if (score <= 89 & score > 84) {
			grade = "B+";
		} else if (score <= 84 & score > 79) {
			grade = "B";
		} else if (score <= 79 & score > 74) {
			grade = "C+";
		} else if (score <= 74 & score > 69) {
			grade = "C";
		} else if (score <= 69 & score > 64) {
			grade = "D+";
		} else if (score <= 64 & score > 59) {
			grade = "D";
		} else {
			grade = "F";
		}
	}

}