Menu



Manage

Study_C# > 5/Car.cs Lines 74 | 2.7 KB
다운로드

                        using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ParkingManager
{
    internal class Car  //++ 인스턴스는 프라이빗이 기본임 / const 변수는 인스턴스로 사용불가 Static 자동부여
    {
         public const int PricePerMin = 100;//클래스 변수 ++ 100원으로 설정
                
         public const int TurningTime = 10; //회차시간은 10분으로 설정
        
        //++ 본인 이해를 위해 프리베이트 셋팅 하는게 좋음
         private string CarNumber; //인스턴스 변수 ++ 차번호는 보통 수동 막는게 보통임/ getter 로 조회는 ㄱㄴ 
         private DateTime InTime;  //인스턴스 변수 ++ 인타입만 게터로
         private DateTime OutTime; //인스턴스 변수

        //++private 변수에서 주로 사용함 // 가장중요 은닉성 - 기본적으로 막아두고 부분적으로만 구멍뚫기
        //++ getter() - 변수값 조회, setter() - 변수값 설정 -> 바꾸기 / 둘 다 있어야함
        //++getter와 setter은 주로 퍼블릭으로 만들음
        public string GetCarNumber()
        {
            return this.CarNumber;
        }
        //Shift f12 =  사용하는 모든 위치

        public DateTime GetInTime()
        {
            return this.InTime;
        }

        public int Out()
        {
            this.OutTime = DateTime.Now;
            return (int)((OutTime - InTime).TotalMinutes);
        }

        internal string Info(int emptyLot)  // ++ 배열 위치는 모르니 외부서 받아오기
        {
            string result = $"차량번호 : {CarNumber}";
            result += Environment.NewLine;
            result += $"입차시간 : {InTime}";
            result += Environment.NewLine;
            result += $"주차구역 : {emptyLot}";   // ++ 배열 위치는 모르니 외부서 받아오기
            result += Environment.NewLine;
            return result ;
        }

        /// <summary>
        /// 기본 생성자는 생성자가 하나도 없으면, 컴파일러가 아래 생성자를 만들어준다.
        /// 단 , 하나라도 직접 사용자가 만든 생성자가ㅏ 있다면 컴파일러는 관여하지 않음.
        /// </summary>
        public Car()
        {
        
        }

        public Car(string carnumber) 
            : this(carnumber, DateTime.Now) // ++ C#과 자바의 다른점
        {
            
        }

        public Car(string carnumber, DateTime intime)
        {
            this.CarNumber = carnumber;
            this.InTime = intime;

        }
    }
}