S007_Sungjuk 성적계산 및 입출력

Posted by PeEn
2019. 5. 14. 11:31 Programing/Java
package kr.ac.jj.java201562054;

import java.util.Scanner;

public class S007_Sungjuk {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		
		HighStudent hs = new HighStudent();
		
		hs.Input();
		
		hs.Print();
		
		HighStudent hs2 = new HighStudent(100,99,100);
		hs2.Print();
		
	}

}

class HighStudent{
	String name = "No Name";	//이름
	int kor;	//국어성적
	int eng;	//영어성적
	int mat;	//수학성적
	int tot;	//합계	
	double ave;	//평균
	String grade;	//등급
	
	HighStudent(){
		
	
	}
	
	HighStudent(int kor, int eng, int mat){
		this.kor = kor;
		this.eng = eng;
		this.mat = mat;
	}
	
	void Input(){
		Scanner scan = new Scanner(System.in);
		System.out.print("이름:");
		name = scan.next();
		System.out.print("국어:");
		kor = scan.nextInt();
		System.out.print("영어:");
		eng = scan.nextInt();
		System.out.print("수학:");
		mat = scan.nextInt();
		Calc();
	}
	
	
	void Print(){
		System.out.println(
				name
				+"\t"+kor
				+"\t"+eng
				+"\t"+mat
				+"\t"+tot
				+"\t"+String.format("%6.2f",ave)//소수점 자르기
				);
	}
	
	void Calc() {
		tot = kor + eng + mat;
		ave = (double)tot / 3;				
	}
}