자바 과제인데 여기까지는 해봤는데 그 다음부터는 어떻게 코드를 짜야 할지 모르겠습니다. 알려주시면 감사합니다.
1. 본인의 이름/학과/이메일/생년월일 의 정보를 저장하는 개인정보 클래스
✛ 클래스 이름은 본인의 이니셜을 사용할 것
[ 예) 홍길동의 경우 - class HGD ]
✛ 개인정보 클래스는 다음 정보를 저장
[ 정보는 인스턴스 생성시 생성자를 통해 초기화 ]
* 이름
* 학번
* 이메일
* 생년월일
✛ 메소드
1) 이름과 이메일의 도메인을 출력하는 메소드
[ String 클래스 또는 본인이 사용 가능한 클래스 적용 ]
- 이름과 이메일의 도메인을 추출하여 출력하는 메소드
2) 나이를 출력하는 메소드
[ Calendar 클래스 또는 본인이 사용 가능한 클래스 적용 ]
- 오늘 날자를 비교하여 만 나이를 출력하는 메소드
2. 실행 클래스
✛ 개인정보 클래스의 인스턴스를 생성
✛ 실행될 메소드 선택
* 실행될 메소드의 번호를 키보드 입력 : 1 , 2
[ Scanner 클래스 또는 본인이 사용 가능한 클래스 적용 ]
* 키보드 입력시 예외처리를 적용할 것.
* ”1“ 번 입력시 결과 화면
< 개발자의 이름은 홍길동입니다.
개발자는 iscu.ac.kr 메일을 사용합니다 >
* ”2“ 번 입력시 결과 화면
< 개발자의 나이는 만 00세 입니다 >
* ”1“, ”2“ 이외의 문자 입력시
< 1, 2번 중에 하나를 선택해주세요 >
import java.util.*;
import java.util.Scanner;
public static class LSH{
private String name;
private int StudentID;
private String email;
private String birthday;
LSH(String name,int StudentID,String email,String birthday){
this.name = name;
this.StudentID = StudentID;
this.email = email;
this.birthday = birthday;
}
public void Scanner(String email){
String[] ema = this.email.split("@");
System.out.println("개발자의 이름은"+name+"입니다"+'\n'+ema[1]+" 메일을 사용합니다.");
}
public void Scanner(String birthday){
String[] bir = this.birthday.split("-");
Calendar today = Calendar.getInstance();
int year = today.get(Calendar.YEAR);
int month = today.get(Calendar.MONTH)+1;
int day = today.get(Calendar.DATE);
int man = year - Integer.parseInt(bir[0]);
boolean plus = false;
boolean manmonth = (month - Integer.parseInt(bir[1]))>0;
boolean manday = (day - Integer.parseInt(bir[2]))>=0;
if(manmonth){
plus = true;
}
if(month - Integer.parseInt(bir[1])==0){
if(manday){
plus = true;
}
}
System.out.println("오늘날짜는"+year+"년"+month+"월"+day+"일 입니다");
System.out.println("생년월일은"+bir[0]+"년"+bir[1]+"월"+bir[2]+"일로 만"+(plus?man:(man-1))+"세입니다.");
}
}
public class MainTest {
public static void main(String[] args){
LSH test = new LSH("이상호","[email protected]","2023-12-23");
test. Scanner("[email protected]"); // 1번
test. Scanner("2023-12-23"); // 2번
}
}