OpenFrameWork
오픈프레임워크_Day08
px
2015. 4. 20. 09:46
### : 목차 구분 기호
--- : 목차 내에 항목 구분 기호
목차
1. 이론 및 정보
2. 설정 및 그 밖에
3. 소스코드
4. 과제
###################################
1. 이론 및 정보
-----------------------------------
--- : 목차 내에 항목 구분 기호
목차
1. 이론 및 정보
2. 설정 및 그 밖에
3. 소스코드
4. 과제
###################################
1. 이론 및 정보
-----------------------------------
String 클래스
1. 자바에서는 문자열을 객체로 취급한다.
- 이미 클래스로 만들어져 있다
- 필요한 기능이 만들어져 있어서 가져다 쓰면 된다.
1. 자바에서는 문자열을 객체로 취급한다.
- 이미 클래스로 만들어져 있다
- 필요한 기능이 만들어져 있어서 가져다 쓰면 된다.
2. 동일한 인스턴스를 중복해서 생성하지 않는다.
String str1 = "java";
String str2 = "java";
3. 절대로 수정 불가(주소가 다르다는 의미)
- 이유는 Heap의 주소를 String이 받기 때문에 아래 코드는
수정이 되는게 아니라 새로운 Heap의 주소를 받고 기존의 메모리는
가비지가 되는 것임
String str1 = "java";
str1 = "java one";
String이 데이터를 수정할 수 없는 클래스이기 때문에
이를 보완한 클래스가 있음
4. StringBuffer 클래스(수정이 가능)
- 문자열 수정이 많을때에는 이 클래스를 사용하라
1) 반드시 new를 통해서만 생성 가능
StringBuffer str = new StringBuffer();
StringBuffer str1 = "java"; (X)
2) 수정 가능
3) equals() : 주소를 비교 (String 클래스와 다른점)
- 원래 equals는 주소비교임 ,String이 고쳐쓰는 것임
-----------------------------------
Command Line Argument(명령행 인자)
F:\study\java>notepad 과제.txt
F:\study\java>notepad 예제.txt
F:\study\java>notepad 예제.txt
이러한 인자를 명령행 인자
-----------------------------------
bonus
1. 입력받기 쉬운 클래스 : java.util.Scanner
2. 소숫점 자리수 정리해주는 클래스 : java.text.DecimalFormat
-----------------------------------
클래스
변수 -> 배열 -> 클래스
------
단점? (c언어는 2,3번 문제를 LinkedList라는 알고리즘으로 해결)
1) 같은 데이터 타입 (c언어는 구조체로 해결)
2) 크기가 처음에 정해짐
3) 삽입, 삭제 힘듬(거의 불가능)
2. Access Modifier(접근 지정자)
1) default(anonymous) : 부분 허용 (같은 폴더 내에 만 접근 가능)
2) public : 완전 허용
3) private
4) protected
3. 메서드의 인자전달 방식 (인자가 있는 방식의 파생)
1) 값에 의한 전달(call by value)
: 소량의 데이터, 간단한 데이터
2) 참조에 의한 전달(call by reference)
: 대량의 또는 복잡한 데이터
간혹 소량의 데이터라 할지라도
반드시 참조의 의한 전달을
사용해야 하는 경우도 있다.
CLASS
1. 묶음
- 변수, 메서드
- 변수, 메서드
- 다양한 데이터 타입을 묶을 수 있음***추가됨
2. 최소 단위(캡슐화 단위)
3. 설계도(추상적)//가장 중요함!
- 인스턴스(Instance 클래스를 가지고 실제로 만든 것, 메모리 공간, 실제 메모리 데이터, 메모리 복사본)
4. 사용자 정의 데이터타입(User Define DataType)
1) Built-in DataType(비 객체형 데이터 타입 - 반드시 값만 저장, 메모리 주소 저장X)
byte short int long double float char boolean
2) User Define DataType(객체형 데이터 타입 - 반드시 주소만 저장)
class로 구현
2. 최소 단위(캡슐화 단위)
3. 설계도(추상적)//가장 중요함!
- 인스턴스(Instance 클래스를 가지고 실제로 만든 것, 메모리 공간, 실제 메모리 데이터, 메모리 복사본)
4. 사용자 정의 데이터타입(User Define DataType)
1) Built-in DataType(비 객체형 데이터 타입 - 반드시 값만 저장, 메모리 주소 저장X)
byte short int long double float char boolean
2) User Define DataType(객체형 데이터 타입 - 반드시 주소만 저장)
class로 구현
-----------------------------------
// 인스턴스 생성 되었을때 저장할 수 있는 변수를 세개 만듬
Sungjuk sj[] = new Sungjuk[3];
Sungjuk sj[] = new Sungjuk[3];
// 실제 생성자가 호출이 되어야 인스턴스가 생성됨
sj[0] = new Sungjuk();
sj[1] = new Sungjuk();
sj[2] = new Sungjuk();
sj[1] = new Sungjuk();
sj[2] = new Sungjuk();
//아래는 실제로 인스턴스가 생성이 된다.
//이유는 자바가 이를 지원하기 때문에
int arr[][] = new int[3][5];
-----------------------------------
-----------------------------------
-----------------------------------
-----------------------------------
-----------------------------------
###################################
2. 설정 및 그 밖에
-----------------------------------
###################################
2. 설정 및 그 밖에
-----------------------------------
프로젝트 day07 만듬
-----------------------------------
eclipse 단축키
ctrl + m 화면 코딩하는 곳 빼고 다 감추기
ctrl + y
ctrl + z
-----------------------------------
-----------------------------------
-----------------------------------
###################################
3. 소스코드
-----------------------------------
/day07/src/StringTest3.java
public class StringTest3 {
public static void main(String[] args) {
// TODO String클래스의 특징
String str1 = "java";
String str2 = "java";
if (str1 == str2)
System.out.println("주소가 같음");
else
System.out.println("주소가 다름");
// new를 통한 생성은 강제로 생성
String str3 = new String("java");
if (str2 == str3)
System.out.println("주소가 같음");
else
System.out.println("주소가 다름");
// 새로운 공간을 또 만들어짐, 아래 메서드를 쓰면
str2 = str1.concat("number one");
System.out.println(str1 + "\n" + str2);
if (str1 == str2)
System.out.println("주소가 같음");
else
System.out.println("주소가 다름");
System.out.println("------------------------------------------------");
// StringBuffer strBuff1 = (StringBuffer)"java";
// StringBuffer strBuff1 = "java";
StringBuffer strBuff1 = new StringBuffer("java");
StringBuffer strBuff2 = strBuff1.append("number one");
System.out.println(strBuff1 + "\n" + strBuff2);
if (strBuff1 == strBuff2)
System.out.println("주소가 같음");
else
System.out.println("주소가 다름");
}
}
public static void main(String[] args) {
// TODO String클래스의 특징
String str1 = "java";
String str2 = "java";
if (str1 == str2)
System.out.println("주소가 같음");
else
System.out.println("주소가 다름");
// new를 통한 생성은 강제로 생성
String str3 = new String("java");
if (str2 == str3)
System.out.println("주소가 같음");
else
System.out.println("주소가 다름");
// 새로운 공간을 또 만들어짐, 아래 메서드를 쓰면
str2 = str1.concat("number one");
System.out.println(str1 + "\n" + str2);
if (str1 == str2)
System.out.println("주소가 같음");
else
System.out.println("주소가 다름");
System.out.println("------------------------------------------------");
// StringBuffer strBuff1 = (StringBuffer)"java";
// StringBuffer strBuff1 = "java";
StringBuffer strBuff1 = new StringBuffer("java");
StringBuffer strBuff2 = strBuff1.append("number one");
System.out.println(strBuff1 + "\n" + strBuff2);
if (strBuff1 == strBuff2)
System.out.println("주소가 같음");
else
System.out.println("주소가 다름");
}
}
-----------------------------------
/day07/src/XorTest.java
public class XorTest {
public static void main(String[] args) {
// TODO xor연산자를 이용한 데이터 암호화 및 복호화
String sendData = "x맨은 홍길동이다. 몰랐지?";
String key = "123abc?";
String encData = "";
String decData = "";
int cnt = 0;
for (int i = 0; i < sendData.length(); i++) {
if( key.length()== cnt )
cnt = 0;
encData = encData + (char)(sendData.charAt(i) ^ key.charAt(cnt));
cnt++;
}
System.out.println("암호화 :" + encData);
cnt = 0;
for (int i = 0; i < sendData.length(); i++) {
if( key.length()== cnt )
cnt = 0;
decData = decData + (char)(encData.charAt(i) ^ key.charAt(cnt));
cnt++;
}
System.out.println("복호화 :" + decData);
}
}
public static void main(String[] args) {
// TODO xor연산자를 이용한 데이터 암호화 및 복호화
String sendData = "x맨은 홍길동이다. 몰랐지?";
String key = "123abc?";
String encData = "";
String decData = "";
int cnt = 0;
for (int i = 0; i < sendData.length(); i++) {
if( key.length()== cnt )
cnt = 0;
encData = encData + (char)(sendData.charAt(i) ^ key.charAt(cnt));
cnt++;
}
System.out.println("암호화 :" + encData);
cnt = 0;
for (int i = 0; i < sendData.length(); i++) {
if( key.length()== cnt )
cnt = 0;
decData = decData + (char)(encData.charAt(i) ^ key.charAt(cnt));
cnt++;
}
System.out.println("복호화 :" + decData);
}
}
-----------------------------------
/day07/src/CmdLineTest.java
public class CmdLineTest {
public static void main(String[] args) {
// TODO Command Line Argument
for (int i = 0; i < args.length; i++)
System.out.println(args[i]);
if(args.length == 0)
System.out.println("argument is empty");
}
}
-----------------------------------
/day07/src/ScannerTest.java
public class ScannerTest {
public static void main(String[] args) {
// TODO scanner클래스 사용법
java.util.Scanner scan = new java.util.Scanner(System.in);
System.out.println("정수 값 입력 : ");
int i = scan.nextInt();
System.out.println("실수 값 입력 : ");
double d = scan.nextDouble();
System.out.println("문자열 입력 : ");
String s = scan.next();
System.out.println(i + "\n" + d + "\n" + s);
}
}
public static void main(String[] args) {
// TODO scanner클래스 사용법
java.util.Scanner scan = new java.util.Scanner(System.in);
System.out.println("정수 값 입력 : ");
int i = scan.nextInt();
System.out.println("실수 값 입력 : ");
double d = scan.nextDouble();
System.out.println("문자열 입력 : ");
String s = scan.next();
System.out.println(i + "\n" + d + "\n" + s);
}
}
-----------------------------------
/day07/src/DecimalFormatTest.java
public class DecimalFormatTest {
public static void main(String[] args) {
// TODO
double d = 123.456789;
java.text.DecimalFormat format =
new java.text.DecimalFormat("#.##");
System.out.println(format.format(d));
d = 3.14;
double e = 0.0;
e = d + 2.5;
System.out.println(e);
String str = format.format(e);
e = Double.parseDouble(str);
if(e == 5.64){
System.out.println("처리가 되었습니다.");
}else{
System.out.println("처리가 안되었습니다.");
}
}
}
-----------------------------------
public static void main(String[] args) {
// TODO
double d = 123.456789;
java.text.DecimalFormat format =
new java.text.DecimalFormat("#.##");
System.out.println(format.format(d));
d = 3.14;
double e = 0.0;
e = d + 2.5;
System.out.println(e);
String str = format.format(e);
e = Double.parseDouble(str);
if(e == 5.64){
System.out.println("처리가 되었습니다.");
}else{
System.out.println("처리가 안되었습니다.");
}
}
}
-----------------------------------
/day07/src/Sungjuk_v3.java
class Sungjuk {
String name;
int no;
int kor;
int eng;
int math;
int tot;
int avg;
char hak;
int rank;
Sungjuk() {
this.rank = 1;
}
Sungjuk(String name, int no, int kor, int eng, int math) {
this.name = name;
this.no = no;
this.kor = kor;
this.eng = eng;
this.math = math;
this.rank = 1;
}
}
public class Sungjuk_v3 {
public static void main(String[] args) {
// TODO 성적표.. 클래스를 이용한 세번째 버전
// 입력을 받았다고 가정
// 인스턴스 생성 되었을때 저장할 수 있는 변수를 세개 만듬
// 실제 생성자가 호출이 되어야 인스턴스가 생성됨
Sungjuk sj[] = new Sungjuk[3];
sj[0] = new Sungjuk("홍길동", 1, 95, 90, 98);
sj[1] = new Sungjuk("임꺽정", 2, 75, 70, 78);
sj[2] = new Sungjuk("신돌석", 3, 82, 80, 88);
for (int i = 0; i < sj.length; i++) {
sj[i].tot = sj[i].kor + sj[i].eng + sj[i].math;
sj[i].avg = sj[i].tot / sj.length;
if (sj[i].avg >= 90)
sj[i].hak = 'A';
else if (sj[i].avg >= 80)
sj[i].hak = 'B';
else if (sj[i].avg >= 70)
sj[i].hak = 'C';
else if (sj[i].avg >= 60)
sj[i].hak = 'D';
else
sj[i].hak = 'F';
}
for (int i = 0; i < sj.length; i++) {
for (int j = 0; j < sj.length; j++) {
if (sj[i].tot > sj[j].tot)
sj[j].rank++;
}
}
System.out.println(" 성적표");
System.out
.println("---------------------------------------------------------------------");
System.out.println("학번\t이름\t국어\t영어\t수학\t총점\t평균\t학점\t등수");
System.out
.println("---------------------------------------------------------------------");
for (int i = 0; i < sj.length; i++) {
System.out.println(sj[i].no + "\t" + sj[i].name + "\t" + sj[i].kor
+ "\t" + sj[i].eng + "\t" + sj[i].math + "\t" + sj[i].tot
+ "\t" + sj[i].avg + "\t" + sj[i].hak + "\t" + sj[i].rank);
}
System.out.println();
System.out
.println("-----------------------정렬 후---------------------------------------");
for (int i = 0; i < sj.length - 1; i++) {
for (int j = i + 1; j < sj.length; j++) {
if (sj[i].tot < sj[j].tot) {
Sungjuk temp = sj[i];
sj[i] = sj[j];
sj[j] = temp;
}
}
}
System.out.println();
System.out.println(" 성적표");
System.out
.println("---------------------------------------------------------------------");
System.out.println("학번\t이름\t국어\t영어\t수학\t총점\t평균\t학점\t등수");
System.out
.println("---------------------------------------------------------------------");
for (int i = 0; i < sj.length; i++) {
System.out.println(sj[i].no + "\t" + sj[i].name + "\t" + sj[i].kor
+ "\t" + sj[i].eng + "\t" + sj[i].math + "\t" + sj[i].tot
+ "\t" + sj[i].avg + "\t" + sj[i].hak + "\t" + sj[i].rank);
}
}
}
String name;
int no;
int kor;
int eng;
int math;
int tot;
int avg;
char hak;
int rank;
Sungjuk() {
this.rank = 1;
}
Sungjuk(String name, int no, int kor, int eng, int math) {
this.name = name;
this.no = no;
this.kor = kor;
this.eng = eng;
this.math = math;
this.rank = 1;
}
}
public class Sungjuk_v3 {
public static void main(String[] args) {
// TODO 성적표.. 클래스를 이용한 세번째 버전
// 입력을 받았다고 가정
// 인스턴스 생성 되었을때 저장할 수 있는 변수를 세개 만듬
// 실제 생성자가 호출이 되어야 인스턴스가 생성됨
Sungjuk sj[] = new Sungjuk[3];
sj[0] = new Sungjuk("홍길동", 1, 95, 90, 98);
sj[1] = new Sungjuk("임꺽정", 2, 75, 70, 78);
sj[2] = new Sungjuk("신돌석", 3, 82, 80, 88);
for (int i = 0; i < sj.length; i++) {
sj[i].tot = sj[i].kor + sj[i].eng + sj[i].math;
sj[i].avg = sj[i].tot / sj.length;
if (sj[i].avg >= 90)
sj[i].hak = 'A';
else if (sj[i].avg >= 80)
sj[i].hak = 'B';
else if (sj[i].avg >= 70)
sj[i].hak = 'C';
else if (sj[i].avg >= 60)
sj[i].hak = 'D';
else
sj[i].hak = 'F';
}
for (int i = 0; i < sj.length; i++) {
for (int j = 0; j < sj.length; j++) {
if (sj[i].tot > sj[j].tot)
sj[j].rank++;
}
}
System.out.println(" 성적표");
System.out
.println("---------------------------------------------------------------------");
System.out.println("학번\t이름\t국어\t영어\t수학\t총점\t평균\t학점\t등수");
System.out
.println("---------------------------------------------------------------------");
for (int i = 0; i < sj.length; i++) {
System.out.println(sj[i].no + "\t" + sj[i].name + "\t" + sj[i].kor
+ "\t" + sj[i].eng + "\t" + sj[i].math + "\t" + sj[i].tot
+ "\t" + sj[i].avg + "\t" + sj[i].hak + "\t" + sj[i].rank);
}
System.out.println();
System.out
.println("-----------------------정렬 후---------------------------------------");
for (int i = 0; i < sj.length - 1; i++) {
for (int j = i + 1; j < sj.length; j++) {
if (sj[i].tot < sj[j].tot) {
Sungjuk temp = sj[i];
sj[i] = sj[j];
sj[j] = temp;
}
}
}
System.out.println();
System.out.println(" 성적표");
System.out
.println("---------------------------------------------------------------------");
System.out.println("학번\t이름\t국어\t영어\t수학\t총점\t평균\t학점\t등수");
System.out
.println("---------------------------------------------------------------------");
for (int i = 0; i < sj.length; i++) {
System.out.println(sj[i].no + "\t" + sj[i].name + "\t" + sj[i].kor
+ "\t" + sj[i].eng + "\t" + sj[i].math + "\t" + sj[i].tot
+ "\t" + sj[i].avg + "\t" + sj[i].hak + "\t" + sj[i].rank);
}
}
}
-----------------------------------
/day07/src/AccessTest.java
class EmpManager{
int no;
String name;
private double pay;
double getPay() {
return pay;
}
void setPay(double pay) {
this.pay = pay;
}
}
public class AccessTest {
public static void main(String[] args) {
// TODO 접근 지정자에 대한 예제
EmpManager hong = new EmpManager();
hong.no = 1;
hong.name = "홍길동";
hong.setPay(1000000);
System.out.println(hong.no + " : " + hong.name + " : " + hong.getPay());
}
}
int no;
String name;
private double pay;
double getPay() {
return pay;
}
void setPay(double pay) {
this.pay = pay;
}
}
public class AccessTest {
public static void main(String[] args) {
// TODO 접근 지정자에 대한 예제
EmpManager hong = new EmpManager();
hong.no = 1;
hong.name = "홍길동";
hong.setPay(1000000);
System.out.println(hong.no + " : " + hong.name + " : " + hong.getPay());
}
}
-----------------------------------
/day07/src/CallByTest1.java
// TODO 참조에 의한 전달방식 첫번째 예제
public class CallByTest1 {
// 값에 의한 전달
/*
void Display(int a, int b, int c, int d, int e){
System.out.println(a+","+b+","+c+","+d+","+e);
}
public static void main(String[] args) {
int a=10,b=7,c=9,d=3,e=6;
CallByTest1 obj = new CallByTest1();
obj.Display(a, b, c, d, e);
}
*/
// 주소에 의한 전달
/*
void Display(int arr[]){
for (int i = 0; i < arr.length; i++) {
System.out.print(arr[i]+"\t");
}
}
public static void main(String[] args) {
int arr[] = {10,7,9,3,6};
CallByTest1 obj = new CallByTest1();
obj.Display(arr);
}
*/
// 인스턴스 변수로 만듬
/*
int arr[] = {10,7,9,3,6};
void Display(){
for (int i = 0; i < arr.length; i++) {
System.out.print(arr[i]+"\t");
}
}
public static void main(String[] args) {
CallByTest1 obj = new CallByTest1();
obj.Display();
}
*/
// 타입이 전부 다른 경우
void Display(Data d){
System.out.println(d.a+","+d.b+","+d.c+","+d.d+","+d.e);
}
public static void main(String[] args) {
Data data = new Data();
//CallByTest1 obj = new CallByTest1();
int s = data.Display();
System.out.println(s);
System.out.println();
//obj.Display(data);
}
}
class Data {
int a = 10;
double d = 7.8;
char c = 'a';
boolean b = true;
String e = "문자열";
int Display(){
System.out.println(a+","+b+","+c+","+d+","+e);
return 3;
}
}
public class CallByTest1 {
// 값에 의한 전달
/*
void Display(int a, int b, int c, int d, int e){
System.out.println(a+","+b+","+c+","+d+","+e);
}
public static void main(String[] args) {
int a=10,b=7,c=9,d=3,e=6;
CallByTest1 obj = new CallByTest1();
obj.Display(a, b, c, d, e);
}
*/
// 주소에 의한 전달
/*
void Display(int arr[]){
for (int i = 0; i < arr.length; i++) {
System.out.print(arr[i]+"\t");
}
}
public static void main(String[] args) {
int arr[] = {10,7,9,3,6};
CallByTest1 obj = new CallByTest1();
obj.Display(arr);
}
*/
// 인스턴스 변수로 만듬
/*
int arr[] = {10,7,9,3,6};
void Display(){
for (int i = 0; i < arr.length; i++) {
System.out.print(arr[i]+"\t");
}
}
public static void main(String[] args) {
CallByTest1 obj = new CallByTest1();
obj.Display();
}
*/
// 타입이 전부 다른 경우
void Display(Data d){
System.out.println(d.a+","+d.b+","+d.c+","+d.d+","+d.e);
}
public static void main(String[] args) {
Data data = new Data();
//CallByTest1 obj = new CallByTest1();
int s = data.Display();
System.out.println(s);
System.out.println();
//obj.Display(data);
}
}
class Data {
int a = 10;
double d = 7.8;
char c = 'a';
boolean b = true;
String e = "문자열";
int Display(){
System.out.println(a+","+b+","+c+","+d+","+e);
return 3;
}
}
-----------------------------------
-----------------------------------
-----------------------------------
-----------------------------------
###################################
4. 과제
-----------------------------------
1. 간단한 주소록 프로그램
예를 들어 프로그램이 pms라면
입력을 아래와 같이 하면
java pms 홍길동
아래의 형식으로 출력
이름 전화번호 주소
출력화면
홍길도 111-1111 서울시 종로구
입력을 아래와 같이 하면
java pms 임꺽정
출력화면
임꺽정 222-2222 서울시 강남구
배열로 미리 정보를 만들어 놓아라
가능하면 클래스로 나눠서 만들어라?
3차원 배열로 해라?
-----------------------------------
2. sungjuk 클래스 입력 받아서 만들어라
scanner이용
v2, v3용으로 만들어라
-----------------------------------
-----------------------------------
-----------------------------------
-----------------------------------
-----------------------------------
###################################
4. 과제 해결
-----------------------------------
4. 과제 해결
-----------------------------------
1.
class Address {
private String name;
private String number;
private String address;
Address() {
}
Address(String name, String number, String address) {
this.name = name;
this.number = number;
this.address = address;
}
void Display() {
System.out.println(name + " " + number + " " + address);
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getNumber() {
return number;
}
public void setNumber(String number) {
this.number = number;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
}
public class Problem {
public static void main(String[] args) {
int total = 7;//Address 크기
int first = 0;//첫번째 argument
Address addBooks[] = new Address[10];
addBooks[0] = new Address("홍길동", "111-1111", "서울시 종로구");
addBooks[1] = new Address("임꺽정", "222-2222", "서울시 강남구");
addBooks[2] = new Address("유재석", "333-3333", "서울시 서초구");
addBooks[3] = new Address("박명수", "444-4444", "서울시 동대문구");
addBooks[4] = new Address("하하", "555-5555", "서울시 관악구");
addBooks[5] = new Address("정형돈", "666-6666", "서울시 도봉구");
addBooks[6] = new Address("정준하", "777-7777", "서울시 노원구");
addBooks[7] = new Address("노홍철", "888-8888", "서울시 광진구");
if (args.length > 0) {
for (int j = 0; j < addBooks.length; j++) {
if (addBooks[j].getName().equals(args[first])) {
addBooks[j].Display();
break;
}
if(j==total){
System.out.println("같은 이름이 없습니다");
break;
}
}
}else
System.out.println("이름을 입력하세요");
}
}
private String name;
private String number;
private String address;
Address() {
}
Address(String name, String number, String address) {
this.name = name;
this.number = number;
this.address = address;
}
void Display() {
System.out.println(name + " " + number + " " + address);
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getNumber() {
return number;
}
public void setNumber(String number) {
this.number = number;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
}
public class Problem {
public static void main(String[] args) {
int total = 7;//Address 크기
int first = 0;//첫번째 argument
Address addBooks[] = new Address[10];
addBooks[0] = new Address("홍길동", "111-1111", "서울시 종로구");
addBooks[1] = new Address("임꺽정", "222-2222", "서울시 강남구");
addBooks[2] = new Address("유재석", "333-3333", "서울시 서초구");
addBooks[3] = new Address("박명수", "444-4444", "서울시 동대문구");
addBooks[4] = new Address("하하", "555-5555", "서울시 관악구");
addBooks[5] = new Address("정형돈", "666-6666", "서울시 도봉구");
addBooks[6] = new Address("정준하", "777-7777", "서울시 노원구");
addBooks[7] = new Address("노홍철", "888-8888", "서울시 광진구");
if (args.length > 0) {
for (int j = 0; j < addBooks.length; j++) {
if (addBooks[j].getName().equals(args[first])) {
addBooks[j].Display();
break;
}
if(j==total){
System.out.println("같은 이름이 없습니다");
break;
}
}
}else
System.out.println("이름을 입력하세요");
}
}
-----------------------------------
-----------------------------------
-----------------------------------
-----------------------------------
-----------------------------------
-----------------------------------