2013년 2월 22일 금요일

5일차 - car

/*
* class 선언
*  - 형식
*       접근제한자  class  클래스이름{
*       - 접근제한자:public,protected,없는거
*      
*       }
*       ex> public class Car{
*           }
*          
*  -구성요소
*     1.멤버변수선언(속성)
*        접근제한자(public,proected,없는거,private) 타입 indentifier;
*        ex> public String carName;
*      
*     2.멤버메쏘드 선언(행위)  
*        접근제한자 리턴타입 메쏘드이름(인자){
*           -인자: 나를 호출한놈이 데이타를 넣어줄 통로
*         -리턴타입: 나를 호출한놈에게 줄 데이타타입
*                     void --> 줄데이타가 없는경우
*        }
*        ex> public int test(int a){
*          
*            }
*/
public class Car {
public String no;
public int inTime;
public int outTime;
public int fee;
}
---------------------------------------------------------
public class CarMethodMain {
public static void main(String[] args){
//1.차가 들어 온다(입차)
//차 객체를 저장할 변수의 선언
CarMethod c1;
//차클래스를 사용해서 차 객체 생성후 Car 변수 초기화
c1 = new CarMethod ();//차 객체 찍기
//차객체안의 멤버변수 초기화
//c1.no="1234";
c1.setData(null, 0, 0, 0);
//시간이흐른후(2hr)
//2.출차
c1.setoutTime = 14;
c1.calculateFee();
//c1.fee = (c1.outTime - c1.inTime)*1000 ;
//3.출력
c1.print();
//번호 알아보기
String no=c1.getNo();
System.out.println(no);
}
}
--------------------------------------------------------
public class CarMethod {
public String no;
public int setinTime;
public int setoutTime;
public int setfee;
public int fee;
public int setInTime;
private int inTime;
private int outTime;
/*
* 기능(메쏘드)
* 1.요금계산하다
* 2.출력하다
*/
public void calculateFee(){
this.setfee=(this.setoutTime-this.setinTime)*1000;//this 생략가능
}
public void print(){
System.out.println("차량번호:"+no);
System.out.println("입차시간:"+setinTime);
System.out.println("출차시간:"+setoutTime);
System.out.println("주차요금:"+setfee);
}
public void setData(String no,int inTime,int outTime,int fee){
this.no=no;
this.inTime=inTime;
this.outTime=outTime;
this.fee=fee;
}
/*
* 멤버필드데이타 메쏘드(set, get)
* 1.setter method
* 2.getter method
*/
//setter
public void setNo(String no){
this.no = no ;
}
//getter
public String getNo(){
return this.no;
}
public int getInTime() {
return setinTime;
}
public void setInTime(int inTime) {
this.setinTime = inTime;
}
public int getOutTime() {
return setoutTime;
}
public void setOutTime(int outTime) {
this.setoutTime = outTime;
}
public int getFee() {
return setfee;
}
public void setFee(int fee) {
this.setfee = fee;
}

댓글 1개:

  1. 클레스...
    나중에 C공부하면서 알겠지만
    클레스는 아직 메모리를 가지지 못한 하나의 struct...

    같이 몰라도 되는건. 객체지향으로 시작한 사람과 객체지향을 본래 아는 것으로 소화해서 아는 사람과는 큰 차이가 있지.

    객체지향부터 배우는게 좋아. 아님 다른 모든게 그저 메모리 CPU 등의 연산작용으로 밖에 안 보여서 창의적인 설계가 막힌다고 생각하는 1人

    답글삭제

국정원의 댓글 공작을 지탄합니다.

UPBIT is a South Korean company, and people died of suicide cause of coin investment.

 UPBIT is a South Korean company, and people died of suicide cause of coin. The company helps the people who control the market price manipu...