C#--編寫旅行社程序

1、代碼:

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

namespace travel
{
    public class Travel
{
    private int tourCost =0;
        private string location;
        public int TourPrice
        {
            get
            {
                if ( location == "加利福尼亞")
                    return tourCost = 250;
                if (location == "北京")
                    return tourCost = 190;
                else
                    return tourCost = 0;
            }
        }

        public string Location
        {
            get
            {
                return location;
            }
            set
            {
                if (value != "加利福尼亞" && value != "北京")
                {
                    location = null;
                }
                else
                    location = value;
            }
        }
    }

    class Program
    {
        static void Main(string[] args)
        {
            Travel dizhi=new Travel();
            Console.WriteLine("請輸入你要去旅遊的地方");
            dizhi.Location=Console.ReadLine();
            Console.WriteLine("費用是" + dizhi.TourPrice);
        }
    }
}

2、實驗結果截圖:
這裏寫圖片描述

這裏寫圖片描述

發佈了81 篇原創文章 · 獲贊 141 · 訪問量 19萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章