반응형
package dayday8;
/*
* 설계용 : Student Class
* field : 이름, 점수, 등급
* method :
* 이름과 점수를 저장할 setInfo()
* 등급을 세팅하는 setGrade()
* 모든 정보를 String으로 리턴하는 showAll();
* 합격 여부를 boolean으로 판별하는 pass();
* - 60점 이상이 합격
* main method :
* 메뉴 생성
* 1. 등록
* 2. 보기
* 3. 합격 확인
* 4. 종료
*/
import javax.swing.JOptionPane;
class Student {
String name;
int result;
char Grade;
void setInfo(String n, int r) { // 이름과 점수를 저장할 setInfo()
this.name = n;
this.result = r;
}
void setGrade() { // 등급을 세팅하는 setGrade()
if (this.result > 90) {
this.Grade = 'A';
} else if (this.result > 80) {
this.Grade = 'B';
} else if (this.result > 70) {
this.Grade = 'C';
} else if (this.result > 60) {
this.Grade = 'D';
} else
this.Grade = 'F';
}
String showAll() {// 모든 정보를 String으로 리턴하는 showAll();
return "이름 : " + this.name + " 점수 : " + this.result + " 등급 : " + this.Grade + "\n";
}
Boolean pass() {// 합격 여부를 boolean으로 판별하는 pass();
return (result > 60 ? true : false);
}
}
public class Quiz01 {
public static void main(String[] args) {
int end = 0;
int tmpInt = 0;
Student st = new Student();
while (end == 0) {
String tmp = JOptionPane.showInputDialog("메뉴입니다.\n1. 등록\n2. 보기\n3. 합격확인\n4. 종료");
int userSelect = Integer.parseInt(tmp);
switch (userSelect) {
case 1:
tmp = JOptionPane.showInputDialog("등록합니다. 이름과 점수를 입력하세요 \n1. 이름을 입력하세요");
st.name = tmp;
tmp = JOptionPane.showInputDialog("등록합니다. 이름과 점수를 입력하세요 \n2. 점수를 입력하세요");
tmpInt = Integer.parseInt(tmp);
st.result = tmpInt;
st.setGrade();
JOptionPane.showMessageDialog(null, "정상적으로 등록되었습니다.");
break;
case 2:
JOptionPane.showMessageDialog(null, st.showAll());
break;
case 3:
if (st.pass())
JOptionPane.showMessageDialog(null, "합격입니다!");
else
JOptionPane.showMessageDialog(null, "불합격입니다!");
break;
case 4:
end = 1;
break;
}
}
}
}
반응형
'IT > Programming' 카테고리의 다른 글
[JAVA] method 사용 예제 (0) | 2023.04.21 |
---|---|
[JAVA] method overloading 사용 예제 (0) | 2023.04.21 |
[JAVA] getter, setter, this 사용 예제 (0) | 2023.04.21 |
[JAVA] 생성자, this 사용 예제 (0) | 2023.04.21 |
[JAVA] static 사용 예제 (1) | 2023.04.21 |