S007_Sungjuk 성적계산 및 입출력
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; } }
'Programing > Java' 카테고리의 다른 글
S007_Sungjuk _허용할 범위_public, private, protect 개념 (0) | 2019.05.14 |
---|---|
S007_Sungjuk_UnivStudent 대학성적 계산예제 (0) | 2019.05.14 |
S003_ContactsClass2 여러 Class 사용 (0) | 2019.05.14 |
S003_ContactsClass1 클래스 사용 (0) | 2019.05.14 |
S003_Contacts (0) | 2019.05.14 |