ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • 03/10 매개변수가 있고 반환 값이 있는 메서드 정의 및 호출
    C#/수업과제 2021. 3. 11. 01:07
    728x90

     

    using System;
    
    namespace Study00
    {
        class Program
        {
    
            static void Main(string[] args)
            {
                Console.WriteLine("메소드 호출");
                Console.WriteLine("아이템을 강화하여 {0}가 되었습니다.", ReinforceEquipment("무형검", "무색 큐브 조각"));
                Console.WriteLine(CompareNumbers(10, 20));
                Console.WriteLine("시험에 {0}하셨습니다.", JudgeScore(61));
                BuildGateway(160, true);
                Console.WriteLine("계좌에 돈을 입금하여 잔고가 {0}원이 되었습니다.", DepositMoney(10000));
                Console.WriteLine("(-1, -1)와 (-2, 4) 사이의 거리는 {0}입니다.",GetDistanceOfTwoCoordinates(-1, -1, -2, 4));
                Console.WriteLine("0~100사이의 랜덤한 수 취득 : {0}",GetRandom(100));
            }
    
            //아이템을 강화한다.
            static private string ReinforceEquipment(string equipmentName, string material)
            {
                if (material != null)
                {
                    return "강화된 무형검";
                }
                else
                {
                    return equipmentName;
                }
            }
    
            //두 수를 비교한다.
            static private string CompareNumbers(int a, int b)
            {
                if (a > b)
                {
                    return b + "보다" + a + "가 더 큽니다.";
                }
                else if (a == b)
                {
                    return a + "와" + b + "는 같습니다.";
                }
                else
                {
                    return a + "보다" + b + "가 더 큽니다.";
                }
            }
    
            //합격 불합격 점수 판정.
            static private string JudgeScore(int score)
            {
                if (60 <= score)
                {
                    return "합격";
                }
                return "불합격";
            }
    
            //프로토스 게이트웨이 건설
            static private string BuildGateway(int mineral, bool pylonArea)
            {
                if (mineral >= 150 && pylonArea == true)
                {
                    return "게이트웨이를 건설하였습니다.";
                }
                return "게이트웨이를 건설하지 못했습니다.";
            }
    
            //계좌에 돈을 입금
            static private int DepositMoney(int money)
            {
                int depositMoney = 10000;
                depositMoney += money;
                return depositMoney;
            }
    
            //두 좌표의 거리 취득
            static private double GetDistanceOfTwoCoordinates(float x, float y, float a, float b)
            {
                float tmpX = x - a;
                float tmpY = y - b;
                return Math.Sqrt((double)((tmpX * tmpX) + (tmpY * tmpY)));
            }
    
            //0~n 랜덤 숫자 취득
            static private int GetRandom(int n)
            {
                Random random = new Random();
                return random.Next(0, n + 1);
            }
    
    
        }
    }
    

    728x90
Designed by Tistory.