. NET Study notes----2015-06-30 (supermarket cashier system 02)

Source: Internet
Author: User
Tags acer

Hit the course with the code: actually there are a lot of pits, and then study

Supermarket Category:

    classSuppermarket {//Create a Warehouse objectCangku ck =NewCangku ();  PublicSuppermarket () {ck. Jinpros ("Acer", +); Ck. Jinpros ("SamSung", +); Ck. Jinpros ("jiangyou", +); Ck. Jinpros ("Banana", +); }        /// <summary>        ///the process of interacting with the user/// </summary>         Public voidaskbuying () {Console.WriteLine ("Welcome, may I ask what you need? "); Console.WriteLine ("we have Acer, SamSung, jiangyou, Banana"); stringStrtype =Console.ReadLine (); Console.WriteLine ("How much do you need? "); intCount =Convert.ToInt32 (Console.ReadLine ()); //go to the warehouse to collect goodsProductfather[] Pros =ck.            Qupros (Strtype, Count); //Calculate the price            DoubleRealmoney =Getmoney (Pros); Console.WriteLine ("you are dealing with {0} dollars in total", Realmoney); Console.WriteLine ("Please select the discount method 2--dozen 90 percent 3--dozen 85 percent 4--buy 300 get 50 5--buy 500 send"); stringinput =Console.ReadLine (); //get a discounted object based on the user's input through a simple factory design patternCalfather cal =getcal (input); DoubleTotalmoney =Cal.            Gettotalmoney (Realmoney); Console.WriteLine ("you deal with {0} dollars after you finish the break", Totalmoney); Console.WriteLine ("Here is your shopping list"); foreach(varIteminchpros) {Console.WriteLine ("name of goods:"+ Item. Name +","+"\ t"+"Price of Goods:"+ Item. Price +","+"\ t"+"Cargo Code:"+item.id); }        }                       /// <summary>        ///returns a discounted object based on a user-selected discount method/// </summary>        /// <param name= "Input" >User's Choice</param>        /// <returns>returned parent class object But it contains a subclass object.</returns>         PublicCalfather getcal (stringinput) {Calfather cal=NULL; Switch(input) { Case "1": Cal =NewCalnormal ();  Break;  Case "2": Cal =NewCalrate (0.9);  Break;  Case "3": Cal =NewCalrate (0.85);  Break;  Case "4": Cal =NewCALMN ( -, -);  Break;  Case "5": Cal =NewCALMN ( -, -);  Break; }            returnCal; }        /// <summary>        ///calculate the total price according to the goods purchased by the user/// </summary>        /// <param name= "Pros" ></param>        /// <returns></returns>         Public DoubleGetmoney (productfather[] pros) {DoubleRealmoney =0;  for(inti =0; I < Pros. Length; i++) {Realmoney+=Pros[i].            Price; }            returnRealmoney; }         Public voidShwopros () {ck.        Showpros (); }    }

The parent class of the discounted class: abstract class

    /// <summary>    ///Discounted Parent Class/// </summary>    Abstract classCalfather {/// <summary>        ///calculate how much money to deal with after discounting/// </summary>        /// <param name= "Realmoney" >the price payable before the discount</param>        /// <returns>money to deal with after discounting</returns>         Public Abstract DoubleGettotalmoney (DoubleRealmoney); }

No discount:

    classCalnormal:calfather {/// <summary>        ///No discount/// </summary>        /// <param name= "Realmoney" ></param>        /// <returns></returns>         Public Override DoubleGettotalmoney (DoubleRealmoney) {            returnRealmoney; }    }

Discount: Algorithm for discount

    /// <summary>    ///rate discount, discounted at discount rate/// </summary>    classCalrate:calfather {/// <summary>        ///Discount rate attribute/// </summary>         Public DoubleRate {Get; Set; }         PublicCalrate (DoubleRate ) {             This. Rate =Rate ; }         Public Override DoubleGettotalmoney (DoubleRealmoney) {            returnRealmoney * This.        rate; }    }

Discount method of M minus N

    /// <summary>    ///buy m yuan send n yuan/// </summary>    classCalmn:calfather {//buy 500 Send//buy 300 Get off        /// <summary>        ///Buy the number/// </summary>         Public DoubleM {Get; Set; }        /// <summary>        ///number of sent/// </summary>         Public DoubleN {Get; Set; }         PublicCALMN (DoubleMDoubleN) { This. M =m;  This. N =N; }         Public Override DoubleGettotalmoney (DoubleRealmoney) {            if(Realmoney >= This. M) {returnRealmoney-(int) (Realmoney/ This. M) * This.            N }            Else            {                returnRealmoney; }        }    }

Main function

    class program    {        staticvoid Main (string[] args)        {            //  Create a Supermarket object            new  suppermarket ()                        ; // Show Goods             SM. Shwopros ();             // Interacting with users             SM. Askbuying ();            Console.readkey ();        }    }

. NET Study notes----2015-06-30 (supermarket cashier system 02)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.