package kh.java.student.controller;
import java.util.Scanner;
import kh.java.student.model.vo.Student;
public class StudentMgr {
Scanner sc = new Scanner(System.in);
int index=0;
Student [] stu = new Student[20];
String name;
int q=0;
int sum;
public void start() {
while(true) {
System.out.println("< < < = = = = 메뉴 = = = = > > >");
System.out.println("");
System.out.println("1. 학생 등록");
System.out.println("2. 학생 검색");
System.out.println("3. 학생 목록");
System.out.println("4. 학생 수정");
System.out.println("5. 학생 삭제");
System.out.println("6. 종료");
System.out.print("선택 : ");
int sel = sc.nextInt();
switch(sel){
case 1 : insertStudent(); break;
case 2 : name=null; selectStudent(name); break;
case 3 : listStudent(); break;
case 4 : modifyStudent(); break;
case 5 : deleteStudent(); break;
case 6 : return;
default : return;
}
}
}
public void deleteStudent() {
System.out.print("삭제할 학생 이름 : ");
String name1 = sc.next();
for(int i=0; i<index;i++) {
if(name.equals(stu[i].getName())) {
q=i;
}
}
for(int i=0; i<index; i++) {
if(stu[i].getName()==stu[q].getName()) {
stu[i]=stu[i+1];
}
}
index--;
}
public void modifyStudent() {
System.out.print("수정할 학생 이름은? : ");
name=sc.next();
selectStudent(name);
while(true) {
System.out.println("수정할 항목을 선택 하시오");
System.out.println("1. 이름 2.나이 3.주소 4.점수 5. 수정종료");
System.out.print("선택 : ");
int sel = sc.nextInt();
switch(sel){
case 1 :
String tmp=stu[q].getName();
System.out.println("현재 이름 : "+tmp);
System.out.print("수정할 이름 : ");
stu[q].setName(sc.next());
System.out.println(tmp+" -> "+stu[q].getName()+"로 이름 수정 완료");
break;
case 2 :
int tmp1 = stu[q].getAge();
System.out.println("현재 나이 : "+stu[q].getAge()+"세");
System.out.print("수정할 나이 : ");
stu[q].setAge(sc.nextInt());
System.out.print("세");
System.out.println(tmp1+"세 -> "+stu[q].getAge()+"세로 나이 수정 완료");
break;
case 3 :
String tmp2 = stu[q].getAddr();
System.out.println("현재 주소 : "+tmp2);
System.out.print("수정할 주소 : ");
stu[q].setAddr(sc.next());
System.out.println(tmp2+" -> "+stu[q].getAddr()+"로 주소 수정 완료");
break;
case 4 :
System.out.println("현재 점수");
System.out.printf("국어 : %d 영어 : %d 수학 : %d\n",stu[q].getKor(),stu[q].getEng(),stu[q].getMath());
System.out.print("수정할 국어 점수 : ");
stu[q].setKor(sc.nextInt());
System.out.print("수정할 영어 점수 : ");
stu[q].setEng(sc.nextInt());
System.out.print("수정할 수학 점수 : ");
stu[q].setMath(sc.nextInt());
System.out.println("점수 수정 완료");
selectStudent(name);
break;
case 5 :
System.out.println("수정을 종료합니다.");
return;
}
}
}
public void listStudent() {
System.out.println("< < = = = = = information = = = = = = > >");
System.out.println("");
System.out.println("\t학생이름\t학생나이\t학생주소\t");
for(int i=0; i<index;i++) {
System.out.printf("\t%s \t\t %d \t %s\n",stu[i].getName(),stu[i].getAge(),stu[i].getAddr());
}
}
public void selectStudent(String name) {
if(name==null) {
System.out.println("검색할 이름 입력 : ");
name = sc.next();
}
else
System.out.print("");
q=0;
String rank;
for(int i=0; i<index;i++) {
if(name.equals(stu[i].getName())) {
q=i;
}
}
sum=stu[q].getKor()+stu[q].getEng()+stu[q].getMath();
if(stu[q].getRank()>=90) {
rank="A 등급";
}
else if(stu[q].getRank()>=80) {
rank="B 등급";
}
else if(stu[q].getRank()>=70) {
rank="C 등급";
}
else if(stu[q].getRank()>=60) {
rank="D 등급";
}
else {
rank="F 등급";
}
System.out.print("학생 이름 : "+stu[q].getName()+"\n");
System.out.print("학생 나이 : "+stu[q].getAge()+"세\n");
System.out.print("학생 주소 : "+stu[q].getAddr()+"\n");
System.out.print("국어 점수 : "+stu[q].getKor()+"\n");
System.out.print("영어 이름 : "+stu[q].getEng()+"\n");
System.out.print("수학 나이 : "+stu[q].getMath()+"\n");
System.out.print("합계 점수 : "+sum+"점\n");
System.out.print("평균 점수 : "+(double)sum/3.0+"점\n");
System.out.print("학생 등급 : "+rank+"\n");
}
public void insertStudent() {
System.out.print("학생 이름 입력 : ");
String name = sc.next();
System.out.print(name+" 학생 나이 입력 : ");
int age = sc.nextInt();
System.out.print(name+" 학생 주소 입력 : ");
String addr = sc.next();
System.out.print(name+"학생 국어 점수 : ");
int kor = sc.nextInt();
System.out.print(name+"학생 영어 점수 : ");
int eng = sc.nextInt();
System.out.print(name+"학생 수학 점수 : ");
int math = sc.nextInt();
System.out.println("학생 정보 입력 완료");
stu[index++]=new Student(name,age,addr,kor,eng,math);
}
}
----------------------------------------------------------------------------------------------
package kh.java.student.model.vo;
public class Student {
private String name;
private int age;
private String addr;
private int kor;
private int eng;
private int math;
public Student() {
}//기본 생성자
public Student(String name, int age, String addr, int kor, int eng, int math) {
this.name=name;
this.age=age;
this.addr=addr;
this.kor=kor;
this.eng=eng;
this.math=math;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public String getAddr() {
return addr;
}
public void setAddr(String addr) {
this.addr = addr;
}
public int getKor() {
return kor;
}
public void setKor(int kor) {
this.kor = kor;
}
public int getEng() {
return eng;
}
public void setEng(int eng) {
this.eng = eng;
}
public int getMath() {
return math;
}
public void setMath(int math) {
this.math = math;
}
public int getRank() {
return kor+eng+math;
}
}
-----------------------------------------------------------------------
package kh.java.student.run;
import kh.java.student.controller.StudentMgr;
public class Run {
public static void main(String[] args) {
StudentMgr s = new StudentMgr();
s.start();
}
}
'IT일반과목 > java' 카테고리의 다른 글
예외처리 (0) | 2018.07.26 |
---|---|
포인트관리프로그램(다형성) (0) | 2018.07.26 |
포인트 관리 프로그램(인터페이스를 만든후 그걸토대로만들기) (0) | 2018.07.26 |
자바 강제 타입 변환(Casting) (0) | 2018.07.24 |
이클립스 단축키 (0) | 2018.07.24 |