⚡ 실행 파일 및 데이터 반환(보안코드 체크,로그인)
-실행파일
package oop;
import java.util.Scanner;
//실행 파일(load_class.java 와 연계)
public class class1 {
public static void main(String[] args) {
cl1_box cl = new cl1_box();
cl.abc();
cl.bbb();
}
}
class cl1_box {
load_class lc = new load_class(); //외부 클래스 로드
Scanner sc = new Scanner(System.in);
//----보안코드 체크
public void abc() { //void가 출력하는 곳에 많이 사용
//인증번호 체크 메소드로 값 전달 및 반환
String result = this.lc.sc_code(1234);//숫자로 던져서 문자로 받음
System.out.println(result);
}
//---로그인
public void bbb() {
System.out.println("아이디를 입력해주세요");
//로드파일 수정x(equals 말고 지금 파일에 intern 사용)
String mid = this.sc.nextLine().intern();
System.out.println("패스워드를 입력해주세요");
String mpw = this.sc.nextLine().intern();
//문자로 던져서 문자로 받음
String result = this.lc.login(mid,mpw); //사용자 정보 검토 프로세스
System.out.println(result); //출력
this.sc.close();
}
}
-데이터 처리(출력) 및 데이터 반환 파일
package oop;
//데이터 처리(출력) 및 데이터 반환
/*
public static void main(String[] args) 체크 x
- 이게 없으면 실행x(단순 데이터 처리 파일),이걸 먼저 짬
*/
public class load_class { //공용으로 사용하는 class
//로그인
public String login(String id,String pw) {
String msg = "";
if(id == "hong" && pw =="a123456") {
msg = "로그인 되셨습니다";
}else {
msg = "아이디 및 패스워드를 확인하세요";
}
return msg;
}
//인증코드 확인
public String sc_code(int a) {
String msg = "";
if(a == 1234) {
msg = "정상적으로 인증이 완료되었습니다.";
}else {
msg = "인증번호를 다시 확인하세요.";
}
return msg;
}
}
⚡ 실행 파일 및 데이터 반환(배열)
-실행파일
package oop;
import java.util.Scanner;
public class class1 {
public static void main(String[] args) {
cl1_box cl = new cl1_box();
cl.news_data();
}
}
class cl1_box {
load_class lc = new load_class(); //외부 클래스 로드
//----데이터로드(news)
public void news_data() {
String result[] = lc.news(); //반환된 배열값을 변수배열로 받음
System.out.println(Arrays.toString(result)); //출력
}
}
-데이터 처리(출력) 및 데이터 반환 파일
package oop;
public class load_class { //공용으로 사용하는 class
//데이터 출력
String data[] = null; //비어있는 문자1차배열 생성
public String[] news() {
//field에 있는 1차 배열 선언문을 이용하여 실제 데이터를 입력후 데이터 반환
//갯수를 지정해주지 않아 맘대로 막 집어 넣을수잇음
this.data = new String[]{"KBS","SBS","MBC","JTBC","채널A"};
return this.data;
}
}
⚡ 실행 파일 및 데이터 반환( 상품 출력 파트)
-실행파일
package oop;
import java.util.Arrays;
//상품 출력 파트(datalist.java와 연계)
public class prd_prduct {
public static void main(String[] args) {
new_prdoduct npd = new new_prdoduct();
npd.np();
}
}
class new_prdoduct{
datalist dl = new datalist();
public void np() { //상품 출력파트(할인 상품만 출력)
//2차배열로 넘어옴
String arr[][] = this.dl.product();
int gp = arr.length; //상품종류(그룹 갯수) : 9개
int ea = arr[0].length; //해당 상품 정보 : 6개
int w =0;
while(w<gp){
if(arr[w][1] == "Y") { //할인이 적용된 상품
int z = 0;
while(z<ea) {
//최종 상품 출력부분
System.out.println(arr[w][z]);
z++;
}
}
w++;
}
}
/*
응용문제
이벤트 상품으로 해당 상품을 출력하는 파트가 있습니다.
이벤트 상품중 할인율이 20% 이상 되는 상품만 출력하시오.
*/
public void ex() {
String exarr[][] = this.dl.product();
int exgp = exarr.length;
int exea = exarr[0].length;
int f,ff;
for(f=0; f<exgp; f++) {
if(exarr[f][1] == "Y" && exarr[f][4] != "" && Integer.valueOf(exarr[f][4]) >= 20) {
for(ff=0; ff<exea; ff++) {
System.out.println(exarr[f][ff]);
}
}
}
}
}
-데이터 처리(출력) 및 데이터 반환 파일(datalist.java)
//위에 class 생략
String product[][] = {
//2차배열
//상품명,할인여부,정상가,할인가,할인율,상품추천수
{ "솔브리빙 논슬립 내구성 좋은 고급형 옷걸이", "Y", "37000", "30400", "17", "250" },
{ "코끼리리빙 문걸이 전신거울", "Y", "265740", "258120", "2", "310" },
{ "리빙스타 스탠드 행거 트리", "Y", "46700", "35900", "23", "16" },
{ "스피드랙 업그레이드형 홈던트하우스 철제 선반", "N", "35900", "", "", "33" },
{ "보노하우스 슬림서랍장 4단", "N", "30400", "", "", "70" },
{ "보노하우스 맥스 서랍장 2단", "Y", "141000", "54900", "61", "120" },
{ "스피드랙 업그레이드형 홈던트하우스 철제 선반 3단", "Y", "144160", "132740", "7", "44" },
{ "스피드랙 업그레이드형 홈던트하우스 조립식 행거", "N", "30400", "", "", "57" },
{ "리빙스타 모던 스탠드 행거 화이트", "Y", "29900", "23900", "20", "314" }
};
return product;