1.employee_ex
1.InfoClass
package com.ohj.emp;
//public 접근제한자
//default : 접근제한자
public class InfoClass {
//멤버변수, 속성, 전역변수
int empNo; // 사원 식별번호
String eName; // 사원이름
String job; //직책
String hireData; //입사일
int sale; // 급여
int commision;//성과급
int deptNo;//부서식별번호
public InfoClass(){ //기본생성자
}
//1001, "송민호", "사원", "2007-03-01", 300, 0, 20
//외부로부터 데이터를 전달받는 생성자(식별번호, 사원이름, 직책, 입사일, 급여, 성과급, 부서식별번호의 변수를 잡아줌
public InfoClass(int e,String en,String j,String h,int s,int c,int d){
this.empNo=e; //this는 클래스 자기 자신을 말한다.
this.eName=en;
this.job=j;
this.hireData=h;
this.sale=s;
this.commision=c;
this.deptNo=d;
}
}
2.DateClass
package com.ohj.emp;
public class DateClass {
InfoClass[] ic =new InfoClass[14];
public DateClass(){//외부로 부터 전달 받은 값을 나타냄
//식별번호, 사원이름, 직책, 입사일, 급여, 성과급, 부서식별번호
ic[0] = new InfoClass(1001, "송민호", "사원", "2007-03-01", 300, 0, 20);
ic[1] = new InfoClass(1002, "이영민", "대리", "2007-04-02", 250, 80, 30);
ic[2] = new InfoClass(1003, "김민우", "과장", "2005-02-10", 500, 100, 30);
ic[3] = new InfoClass(1004, "장희재", "부장", "2003-09-02", 600, 0, 20);
ic[4] = new InfoClass(1005, "오종호", "과장", "2005-04-07", 450, 200, 30);
ic[5] = new InfoClass(1006, "최형우", "부장", "2003-10-09", 480, 0, 30);
ic[6] = new InfoClass(1007, "윤가람", "부장", "2004-01-08", 520, 0, 10);
ic[7] = new InfoClass(1008, "이명희", "차장", "2004-03-08", 500, 0, 30);
ic[8] = new InfoClass(1009, "송종영", "사장", "1996-10-04",1000, 0, 20);
ic[9] = new InfoClass(1010, "황영호", "과장", "2005-04-07", 500, 0, 10);
ic[10] = new InfoClass(1011, "김현정", "사원", "2007-03-01", 280, 0, 30);
ic[11] = new InfoClass(1012, "강정혜", "사원", "2007-08-09", 300, 0, 20);
ic[12] = new InfoClass(1013, "박민훈", "부장", "2002-10-09", 560, 0, 20);
ic[13] = new InfoClass(1014, "조인성", "사원", "2007-11-09", 250, 0, 10);
}
}
3.OperClass
package com.ohj.emp;
public class OperClass {//매소드를 저장하는 클래스
public OperClass(){ // 기본생성자
}
public void avgHireDate(InfoClass[] ic){//평균을 구하는 메소드
int sum=0; String hd; String[] s;
for(int i=0;i<ic.length;i++){
//String hd =dc.ic[0].hireData;
//System.out.println(hd);
hd =ic[i].hireData;
//String[]s=hd.split("-");// 쪼개는 것 "2007-03-01"-> "2007","03","01"
//System.out.println(s[0]);
//System.out.println(s[1]);
//System.out.println(s[2]);
s=hd.split("-");
//System.out.println(2020+s[0]);//숫자+문자=문자열
//int y = Integer.parseInt(s[0]);//문자열로 되어있는 숫자를 숫자로 바꿔주는 것 ex) "2007"=>2007
//System.out.println(2020-y); //숫자와 문자는 -를 할 수 없지만 문자를 숫자로 바꾸면 -를 할 수 있다.
sum = sum+(2020-Integer.parseInt(s[0]));
}//for ED
//평균 재직연수를 구하라
double avg = sum/(ic.length*1.0);
System.out.println(avg);
}
}
4. MainClass
package com.ohj.emp;
public class MainClass {
public static void main(String[] args) {
DateClass dc = new DateClass();
//OperClass oc = new OperClass(); // 1. 객체 생성해주고
//oc.avgHireData(dc.ic); // 2. operclass에 선언해놓은것을 여기로 불러옴
// 주의할점은 main에서 일단 코드를 먼저 만들어 놓고 그 다음에
// operclass를 만들어서 옮기는 식으로 해야 한다.
// System.out.println(dc.ic[13].commission); -->데이터 확인용
// 진짜 데이터가 확인이 되는지 먼저 점검 한 후에 코딩을 시작해야 한다.
// 2007년에 입사한 사람 (내가 해결한 코드)
String hd;
String[] s;
int year;
int year2;
for (int i = 0; i < dc.ic.length; i++) {
hd = dc.ic[i].hireData;
s = hd.split("-");
int y=Integer.parseInt(s[0]);
year=y;
year2=1995;
year2=y+1;
if(y<=year2){
System.out.println(y+"년 입사자 : "+dc.ic[i].eName);
}else if(year2<2008){
System.out.println("연산 종료");
}
/*
if(y==2005){
System.out.println("2005 입사자 : "+dc.ic[i].eName);
}
if(y==2004){
System.out.println("2004 입사자 : "+dc.ic[i].eName);
}
if(y==2003){
System.out.println("2003 입사자 : "+dc.ic[i].eName);
}
if(y==2002){
System.out.println("2002 입사자 : "+dc.ic[i].eName);
}
if(y==1996){
System.out.println("1996 입사자 : "+dc.ic[i].eName);
}
*/
}
/*
int dn;
String en;
for(int i=0; i<dc.ic.length;i++){
dn=dc.ic[i].deptNo;
if(dn==30){
System.out.println("30 부서 인원 : "+dc.ic[i].eName);
}
}
for(int i=0; i<dc.ic.length;i++){
en=dc.ic[i].job;
if(en.equals("과장")){
System.out.println("과장 직급자 : "+dc.ic[i].eName);
}
}
*/
}
}
2.member
1.InfoClass
package com.ohj.member;
public class InfoClass {
String name; //이름
String joinDate;//가입일
String lastVisitDate;//최종방문일
int numVisit;//방문횟수
String gender;//성별
String age;//연령대
public InfoClass(){//기본생성자
}
public InfoClass(String n,String j,String last,int nv, String g,String a){
this.name=n;
this.joinDate=j;
this.lastVisitDate=last;
this.numVisit=nv;
this.gender=g;
this.age=a;
}
}
2.DateClass
package com.ohj.member;
public class DateClass {
InfoClass[] ic=new InfoClass[98];// 쪼개진 데이타
public DateClass(){//외부로 부터 전달 받은 값을 나타냄
String[] member=new String[98];//원본 데이타(raw data) 생성자가 끝나면 소멸 시켜줘야하기 때문에
member[0]="임재,20190509,20190510,8,남,30대후반";
member[1]="성열,20190509,20190510,1,남,30대중반";
member[2]="천재,20190509,20190510,3,남,30대초반";
member[3]="현수,20190509,20190509,1,남,20대후반";
member[4]="진우,20190509,20190510,2,남,30대초반";
member[5]="영주,20190509,20190510,2,비공개,비공개";
member[6]="종화,20190509,20190509,0,남,20대후반";
member[7]="윤정,20190509,20190510,3,비공개,비공개";
member[8]="종호,20190509,20190510,3,남,20대중반";
member[9]="동현,20190509,20190510,5,남,20대중반";
member[10]="경래,20190509,20190510,1,남,20대후반";
member[11]="상일,20190509,20190510,6,남,30대후반";
member[12]="재형,20190509,20190510,2,남,30대중반";
member[13]="경민,20190509,20190510,4,남,20대중반";
member[14]="경애,20190507,20190507,0,비공개,비공개";
member[15]="동현,20190507,20190507,0,남,40대초반";
member[16]="종인,20190507,20190507,0,남,40대중반";
member[17]="은혁,20190426,20190504,3,남,30대후반";
member[18]="은정,20190426,20190426,1,여,30대중반";
member[19]="정은,20190426,20190426,0,여,40대후반";
member[20]="진수,20190426,20190426,1,비공개,비공개";
member[21]="은석,20190426,20190504,2,남,50대초반";
member[22]="수진,20190426,20190426,0,여,30대초반";
member[23]="비공개,20190426,20190426,1,비공개,비공개";
member[24]="재희,20190426,20190426,2,여,40대후반";
member[25]="의환,20190426,20190426,1,남,20대후반";
member[26]="관현,20190425,20190425,0,남,40대초반";
member[27]="성욱,20190425,20190426,3,남,30대후반";
member[28]="의열,20190425,20190426,5,여,30대후반";
member[29]="가영,20190425,20190426,1,여,30대중반";
member[30]="현수,20190425,20190505,5,남,40대초반";
member[31]="기대,20190425,20190426,2,남,40대중반";
member[32]="근준,20190425,20190425,0,남,20대후반";
member[33]="성준,20190425,20190426,3,남,20대후반";
member[34]="종오,20190425,20190426,3,남,50대중반";
member[35]="병욱,20190425,20190426,5,남,30대초반";
member[36]="서경,20190425,20190426,2,여,30대후반";
member[37]="비공개,20190425,20190426,1,비공개,비공개";
member[38]="관순,20190425,20190426,3,여,30대초반";
member[39]="충현,20190425,20190426,1,남,30대초반";
member[40]="시형,20190425,20190426,1,남,30대후반";
member[41]="정윤,20190425,20190426,3,여,30대중반";
member[42]="호섭,20190425,20190426,1,남,40대후반";
member[43]="상민,20190425,20190426,1,남,30대중반";
member[44]="수영,20190425,20190426,1,여,30대중반";
member[45]="경훈,20190425,20190426,1,비공개,비공개";
member[46]="남현,20190218,20190510,10,남,30대후반";
member[47]="두근,20190218,20190218,0,남,20대중반";
member[48]="윤정,20181022,20190114,18,여,20대후반";
member[49]="현민,20181022,20190115,31,남,20대후반";
member[50]="철우,20181011,20181024,7,남,30대초반";
member[51]="동주,20181011,20190324,75,남,20대후반";
member[52]="승민,20181002,20181208,48,남,20대중반";
member[53]="근학,20180927,20190129,45,남,20대후반";
member[54]="수민,20180927,20190412,50,남,20대후반";
member[55]="형석,20180927,20190418,7,남,20대후반";
member[56]="명재,20180927,20190118,41,남,30대초반";
member[57]="병호,20180927,20181008,3,남,50대초반";
member[58]="민태,20180927,20190208,49,남,20대중반";
member[59]="신혜,20180927,20190120,49,여,20대후반";
member[60]="성권,20180927,20180928,5,남,20대후반";
member[61]="영봉,20180927,20181217,45,남,20대후반";
member[62]="성구,20180927,20190123,47,남,20대후반";
member[63]="부욱,20180927,20181119,24,남,30대초반";
member[64]="주현,20180712,20180712,2,여,20대초반";
member[65]="다희,20180626,20180626,1,여,20대중반";
member[66]="다을,20180625,20180807,40,여,20대중반";
member[67]="대희,20180625,20181217,57,남,20대중반";
member[68]="자훈,20180625,20190305,47,여,20대중반";
member[69]="지원,20180625,20180727,38,여,20대중반";
member[70]="재학,20180625,20181101,45,남,20대중반";
member[71]="지혜,20180625,20190410,89,여,20대중반";
member[72]="중훈,20180625,20180727,31,남,20대중반";
member[73]="한솔,20180625,20181205,62,여,20대중반";
member[74]="예림,20180625,20181227,28,여,20대중반";
member[75]="수현,20180625,20190210,17,여,20대중반";
member[76]="소현,20180625,20180727,63,여,20대중반";
member[77]="해성,20180625,20180726,38,남,20대후반";
member[78]="진안,20180625,20180727,45,남,20대후반";
member[79]="지원,20180625,20180726,17,여,20대초반";
member[80]="경희,20180625,20190424,27,여,20대중반";
member[81]="도형,20180625,20190504,72,남,20대후반";
member[82]="태수,20180625,20180808,70,남,20대중반";
member[83]="가은,20180625,20180807,42,여,20대중반";
member[84]="힘찬,20180625,20180727,33,남,20대중반";
member[85]="상협,20180625,20181025,43,남,20대중반";
member[86]="용선,20180625,20190102,66,남,20대중반";
member[87]="승현,20180625,20181206,50,남,20대중반";
member[88]="지원,20180625,20180723,16,여,20대중반";
member[89]="한진,20180419,20180719,47,남,20대후반";
member[90]="유찬,20180419,20181017,71,남,20대후반";
member[91]="기태,20180419,20180813,39,남,20대후반";
member[92]="지훈,20180419,20190209,34,남,20대후반";
member[93]="봉기,20180419,20181002,71,남,20대후반";
member[94]="정규,20180419,20180627,39,남,20대초반";
member[95]="상준,20180419,20181228,95,남,20대후반";
member[96]="유림,20180419,20180701,53,여,20대후반";
member[97]="소영,20180419,20180615,44,여,20대후반";
for(int i=0; i<member.length;i++){
String[] s =member[0].split(",");// 띄어쓰기 했으면 쉼표 옆에 띄어쓰기를 해줘야함
int n =Integer.parseInt(s[3]);
ic[0]=new InfoClass(s[0],s[1],s[2],n,s[4],s[5]);
}
}
}
3.MainClass
package com.ohj.member;
import java.util.ArrayList;//외부클래스를 가져오는 것 JRE
import java.util.Random;
public class MainClass {
public static void main(String[] args){
//랜덤코드
ArrayList lottoNumber = new ArrayList();
for(int i=0; i<46;i++){
lottoNumber.add(i);
}
Random rnd = new Random();//임의의 정수를 위한 객체
ArrayList sixNumber=new ArrayList();//임의의 수 6개 저장
for(int i=0; i<6;i++){//중복되지않는 임의의 수 6개 추출
int index = rnd.nextInt(lottoNumber.size());
Object n = lottoNumber.remove(index);
sixNumber.add(n);
}
for(int i=0; i<sixNumber.size();i++){//추출된 6개 숫자 출력
System.out.println(sixNumber.get(i)+",");
}
////////////////////////////////////////////////////////////
/*ArrayList lottoNumber = new ArrayList();
for(int i=0; i<46;i++){
lottoNumber.add(i);
}
//lottNember[0]=>1 0번 방에는 1번
//lottNember[1]=>2 1번 방에는 2번
//lottNember[44]=>45 44번 방에는 45번
Random rnd = new Random();
int index = rnd.nextInt(lottoNumber.size());//-> 사이즈는 45개
//lottoNumber.size()->45
//rnd.nextInt(lottoNumber.size())=> 0~44
Object n = lottoNumber.remove(index);//중복값은 get이 아니고 remove로 값을 제거
System.out.println(n);
System.out.println(lottoNumber.size());
index = rnd.nextInt(lottoNumber.size());
n = lottoNumber.remove(index);//중복값은 get이 아니고 remove로 값을 제거
System.out.println(n);
System.out.println(lottoNumber.size());*/
}
}
':: IT > JAVA' 카테고리의 다른 글
20200107 메소드, String (0) | 2020.03.24 |
---|---|
20200106 JAVA arraylist 배열 (0) | 2020.03.23 |
20200102 JAVA Class(클래스, 메소드 기초, 배열) (0) | 2020.03.22 |
20191231 if문, 반복문(for문), 메소드 (0) | 2020.03.18 |
20191230 JAVA 시작 (0) | 2020.03.18 |