コード例 #1
0
 public Service_mode(Product[] product1,MoneyType[] change1)
 {
     Form1 frm = (Form1)this.Owner;
     money = new Money(this);
     InitializeComponent();
     this.product = product1;
     this.change = change1;
 }
コード例 #2
0
ファイル: Money.cs プロジェクト: CurlyN/Vending-Machine
 //counting the overall amount of money being iserted
 public double sumCoins(MoneyType[] coins)
 {
     double sum = 0;
     for (int i=0; i<coins.Length;i++)
     {
         if (coins[i].Unit!=0)
         {
             sum += coins[i].Value;
         }
     }
     return sum;
 }
コード例 #3
0
ファイル: Money.cs プロジェクト: CurlyN/Vending-Machine
        public Money(Form form1)
        {
            this.form = form1;

            InitializeComponent();
            money_inserted = 0;

            coins_inserted[0] = new MoneyType(0.01, 0);
            coins_inserted[1] = new MoneyType(0.02, 0);
            coins_inserted[2] = new MoneyType(0.05, 0);
            coins_inserted[3] = new MoneyType(0.1, 0);
            coins_inserted[4] = new MoneyType(0.2, 0);
            coins_inserted[5] = new MoneyType(0.5, 0);
            coins_inserted[6] = new MoneyType(1, 0);
            coins_inserted[7] = new MoneyType(2, 0);
        }
コード例 #4
0
ファイル: Form1.cs プロジェクト: CurlyN/Vending-Machine
        //algorithm to give change
        public void giveChange(MoneyType[] change, double money_inserted)
        {
            int mtype = change.Length - 1;
            //while we have sum to return, we giving change with the highest coin's vvalue that we have
            //and by minimum amount of coins.
            //thus, if, for example, we have £ 1.6 to give back, the change has to be:
            //1 coin of one pound, 1 coin of 50 pence, 1 coinn of 10 pence
            while ((money_inserted > 0) && (mtype >= 0))
            {
                while ((change[mtype].Unit >= 0) && (money_inserted >= change[mtype].Value))
                {
                    showChange.Text += " 1 coin of £ " + change[mtype].Value + " given \r\n";
                    change[mtype].Unit--;
                    money_inserted -= change[mtype].Value;
                    money_inserted = Math.Round(money_inserted, 4);
                }

                mtype--;
            }
        }
コード例 #5
-2
ファイル: Form1.cs プロジェクト: CurlyN/Vending-Machine
        int type; // profuct type

        #endregion Fields

        #region Constructors

        public Form1()
        {
            InitializeComponent();

            type = 0;
            insert_money = new Money(this);
            service1 = new Service_mode(product, change);

            //initialising product array
            product[0] = new Product(4, 0.5, "Coke");
            product[1] = new Product(4, 0.5, "Sprite");
            product[2] = new Product(4, 0.4, "Mirinda");
            product[3] = new Product(4, 0.4, "Pepsi");
            product[4] = new Product(4, 0.65, "Schweppes");
            product[5] = new Product(4, 0.65, "Mountain Dew");

            //initialising the change array
            change[0] = new MoneyType(0.01, 4);
            change[1] = new MoneyType(0.02, 4);
            change[2] = new MoneyType(0.05, 4);
            change[3] = new MoneyType(0.1, 4);
            change[4] = new MoneyType(0.2, 4);
            change[5] = new MoneyType(0.5, 4);
            change[6] = new MoneyType(1, 4);
            change[7] = new MoneyType(2, 4);
        }