IT/Programming / / 2023. 4. 21. 17:41

[JAVA] 클래스를 활용한 기본 학생성적 확인 예제

반응형
public class People {
	String name;
	int age;
	String phone;
}
import javax.swing.JOptionPane;

class Student {
	String name;
	int point;
	char grade;
}

public class Quiz01 {
	/*
	 * Student 클래스 만들기 멤버 : 이름, 점수, 등급
	 * 
	 * Quiz01 - 메인클래스 메뉴 : 1. 등록하기 2. 점수보기 3. 등급보기 4. 종료하기
	 */
	public static void main(String[] args) {
		String message = "1. 등록하기\n"
						+"2. 점수보기\n"
						+"3. 등급보기\n"
						+"4. 종료하기";
		String select;
		Student st = null;
		while(true){
			select = JOptionPane.showInputDialog(message);
			if( select.equals("1") ){
				 st = new Student();
				 st.name = JOptionPane.showInputDialog("이름");
				 String tmp = JOptionPane.showInputDialog("점수");
				 st.point = Integer.parseInt(tmp);
				 if(st.point >= 90) st.grade = 'A';
				 else if(st.point >= 80) st.grade = 'B';
				 else if(st.point >= 70) st.grade = 'C';
				 else if(st.point >= 60) st.grade = 'D';
				 else st.grade = 'F';
				 JOptionPane.showMessageDialog(null, "저장 완료!");
			}
			else if( select.equals("2") ){
				if(st == null){// 등록 아직 안했음..
					JOptionPane.showMessageDialog(null, "등록부터 하세여..");
				}else{
					JOptionPane.showMessageDialog(null, st.point + "점");
				}
			}
			else if( select.equals("3") ){
				if(st == null){// 등록 아직 안했음..
					JOptionPane.showMessageDialog(null, "등록부터 하세여..");
				}else{
					JOptionPane.showMessageDialog(null, st.grade + "등급");
				}
			}
			else if( select.equals("4") ){
				return; // break;
			}
			else {
				JOptionPane.showMessageDialog(null, "잘못 입력");
			}
		}
	}
}
package dayday19;

import java.io.*;

import javax.swing.JOptionPane;

/*
* Quiz02 Class
*  student.stu의 모든 객체정보를 JOPtionPain으로 출력
*  
* 
*/
public class Quiz02 {
	public static void main(String[] args) {
		try {
			FileInputStream fis = new FileInputStream("student.stu");
			ObjectInputStream ois = new ObjectInputStream(fis);
			String mess = "";
			while(true){
				try{
					Student stu = (Student)ois.readObject();
					mess += stu.toString() +"\n";
				} catch(EOFException e){
					break;
				}
			}
			JOptionPane.showMessageDialog(null, mess);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

}
반응형

'IT > Programming' 카테고리의 다른 글

[JAVA] class와 객체 사용 예제  (0) 2023.04.21
[JAVA] 객체의 배열 사용 예제  (0) 2023.04.21
[JAVA] 객체 사용 예제  (0) 2023.04.21
[JAVA] method 사용 예제  (0) 2023.04.21
[JAVA] method overloading 사용 예제  (0) 2023.04.21
  • 네이버 블로그 공유
  • 네이버 밴드 공유
  • 페이스북 공유
  • 카카오스토리 공유