0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

C# 勉強(1) class

Last updated at Posted at 2020-05-24

商品クラスの利用

クラス;

    public class Product {
        //プロパティ(set は非公開)
        public int Code {get;private set;}
        public string Name{get;private set;}
        public int Price{get;private set;}

        //コンストラクタ(特殊メソッド)
        public Product(int code,string name,int price){
            this.Code=code;
            this.Name=name;
            this.Price=price;
        }
        //税金メソッド
        public int GetTax(){
            return (int)(Price * 0.08);
        }
        public int GetPriceIncludingTax(){
            return Price + GetTax();
        }
    }

プログラム;


    class Program
    {
        static void Main(string[] args)
        {
            Product choco = new Product(123,"チョコチップ",110);
            Product boltgum = new Product(234,"ボトルガム",500);

            int chocoTax = choco.GetTax();
            int boltgumTax = boltgum.GetTax();

            Console.WriteLine("{0},{1},{2}",choco.Name,choco.Price,chocoTax);
            Console.WriteLine("{0},{1},{2}",boltgum.Name,boltgum.Price,boltgumTax);

        }
    }
0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?