//2. 1차원 객체(참조)형배열
Photo p0=new Photo();
p0.setData(1, "부산에서", "bs.jpg", "2013-02-02");
p0.print();
Photo p1,p2,p3,p4,p5;
p1 = new Photo();
p1.setData(2, "대구1", "bs1.jpg", "2013-02-02");
p2 = new Photo();
p2.setData(3, "대구2", "bs2.jpg", "2013-02-02");
p3 = new Photo();
p3.setData(4, "대구3", "bs3.jpg", "2013-02-02");
p4 = new Photo();
p4.setData(5, "대구4", "bs4.jpg", "2013-02-02");
p5 = new Photo();
p5.setData(6, "대구5", "bs5.jpg", "2013-02-02");
Photo[] photoArray ;
photoArray = new Photo[7];
photoArray[0] = p0;
photoArray[1] = p1;
photoArray[2] = p2;
photoArray[3] = p3;
photoArray[4] = p4;
photoArray[5] = p5;
photoArray[6] = new Photo();
photoArray[7].setData(7, "안면도에서...", "jj.jpg", "2012-08-12");
photoArray[0].print();
p1.print();
System.out.println("**********전체출력**********");
for (int j = 0; j < photoArray.length; j++) {
photoArray[j].print();
}
}
}
-------------------------------------------------------------------
/*
* 사진 1개의 데이타를 저장할 객체
*/
public class Photo {
private int no;
//번호
private String title;
//제목
private String fileName;
//파일 이름
private String date;
//찍은 날짜
public void setData(int no,String title,String fileName,String date){
setNo(no);
setTitle(title);
setFileName(fileName);
setDate(date);
}
/*
* 사진정보 출력
*/
public void print(){
String info = this.getInFo();
System.out.println(info);
}
/*
* 객체 멤버 내용을 문자열로 반환
*/
public String getInFo(){
String info=no+"\t"+title+"\t"+fileName+"\t"+date ;
return info;
}
public int getNo() {
return no;
}
public void setNo(int no) {
this.no = no;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getFileName() {
return fileName;
}
public void setFileName(String fileName) {
this.fileName = fileName;
}
public String getDate() {
return date;
}
public void setDate(String date) {
this.date = date;
}
}
------------------------------------------------------------
public class CarArrayMain {
public static void main(String[] args) {
Car temp1 = new Car();
temp1.setData("4567", 5, 0, 0);
Car temp2 = new Car();
temp1.setData("2344", 5, 0, 0);
Car temp3 = new Car();
temp1.setData("6677", 5, 0, 0);
Car temp4 = new Car();
temp1.setData("1111", 5, 0, 0);
Car[] carArray = {
temp1,null,null,null,null,
null,temp2,null,null,null,
null,null,temp3,null,null,
null,null,null,temp4,null,
null,null,null,null,null,
null,null,null,null,null,
};
//입차
System.out.println("1.입차---------");
Car c1 = new Car();
c1.setData("1234", 10, 0, 0);
for (int i = 0; i < carArray.length; i++) {
if(carArray[i]==null){
carArray[i]=c1;
carArray[i].print();
break;
}
}
//총주차대수
int count=0;
for (int i = 0; i < carArray.length; i++) {
if(carArray[i]!=null){
count++;
}
}
System.out.println("2.현재 총 주차대수:"+count);
//현재차량의 15시현재 총주차요금
int tot=0;
for (int i = 0; i < carArray.length; i++) {
if(carArray[i]!=null){
carArray[i].setOutTime(15);
carArray[i].calculateFee();
tot=tot+ carArray[i].getFee();
carArray[i].setOutTime(0);
carArray[i].setFee(0);
}
}
System.out.println("3.현재차량의 15시현재 총주차요금:"+tot);
//9시 이후 입차 차량 찾기
System.out.println("4.9시 이후 입차차량 찾기");
for (int i = 0; i < carArray.length; i++) {
if(carArray[i]!=null){
if(carArray[i].getInTime()>=9){
carArray[i].print();
}
}
}
//1234 번 차량 출차(1234번차 차량찾기-->출차)
System.out.println("5.1234 번 차량 출차17시");
for (int i = 0; i < carArray.length; i++) {
String tempNo=carArray[i].getNo();
if(tempNo.equals("1234")){
carArray[i].setOutTime(17);
carArray[i].calculateFee();
carArray[i].print();
carArray[i]=null;
break;
}
}
//총주차대수
count=0;
for (int i = 0; i < carArray.length; i++) {
if(carArray[i]!=null){
count++;
}
}
System.out.println("6.현재총주차대수:"+count);
}
}
------------------------------------------------------
String 문자열 비교
public class StringCompare {
/*
* 문자열객체비교
*/
public static void main(String[] args) {
String str1 ="김경호";
String str2 ="김경호";
String str3 =new String("김경호");
System.out.println("str1="+str1);
System.out.println("str2="+str2);
System.out.println("str3="+str3);
if(str1==str2){
System.out.println("같다");
}
if(str1==str3){
System.out.println("같다용");
}else if(str1!=str3){
System.out.println("다르다용");
}
/*
* <<String class>>
* public boolean equals(string anotherString);
* -문자열이 일치하는지 비교
* -리턴값 true: 문자열 일치 , false: 문자열불일치
*
*/
boolean isSame = str1.equals(str3);
isSame = str1.equals(str3);
isSame = str1.equals("김경호");
}
}