Tuesday, November 10, 2009

An example of how objects can be used to program applications perfectly

Here i am going to write a program.I wrote it by my own
please do not copy.It shows that how applications can be
implemented easily with Objects-



# MridulFruitBusiness applications-

1.It will create a bucket owner with the owner name & the number
of flowers he/she can keep.
2.then he/she can keep in/keep out the flowers in the bucket by selecting
radiobuttons and entering the number of flowers to keep/keepout seperately.
3.if he/she clicks status button at the bottom the overall status will
be shown about how many flowers in the bucket and how many he/she can keep.

#here is the bucket class
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace MridulFruitsBusiness
{
    public class Bucket
    {
        private string ownerName;

        public string OwnerName
        {
            get { return ownerName; }
            set { ownerName = value; }
        }
        private int numberItems;
        public int NumberItems
        {
            get { return numberItems; }
            set { numberItems = value; }
        }
        public Bucket(string ownerName,int numberItems) {
            this.ownerName = ownerName;
            this.numberItems = numberItems;       
        }
    }
}

#the fruits keeper class
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace MridulFruitsBusiness
{
    public class FruitsKeeper
    {
       
        public string KeepFruits(int value, int keepValue,int keptValue, Bucket bucketObj)
        {
          
            if (value == 1)
            {
                if (bucketObj.NumberItems < keepValue)
                {
                    return "sorry u try to keep more fruits than the number of flowers";
                }
                else
                {                                                       
                    return "u kept " + keepValue.ToString() + " fruits\nu can keep more " + (bucketObj.NumberItems - keepValue).ToString() + " fruits";

                }
             }

            if (value == 2)
            {                                             
                return keepValue.ToString()+" fruits kept out of the bucket\n"+keptValue.ToString()+" fruits remaining";
            }
            else
            {
                return "no data";
            }
           
        }
    }
}

#starting point class of the program
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;

namespace MridulFruitsBusiness
{
    static class Program
    {
        ///


        /// The main entry point for the application.
        ///

        [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new MridulFormUi());
        }
    }
}
#here is the User interface class(the main part)
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace MridulFruitsBusiness
{
    public partial class MridulFormUi : Form
    {
        private Bucket bucketObj = null;
        private int keptValue=0;
        public MridulFormUi()
        {
            InitializeComponent();
        }

        private void gardenerForm_Load(object sender, EventArgs e)
        {

        }       
        private void submitButton_Click(object sender, EventArgs e)
        {
            bucketObj=new Bucket(ownerTextBox.Text,Convert.ToInt16(itemsTextBox.Text));
           
            MessageBox.Show(" bucket created");
        }
        ///
        /// for keeping
        ///

        ///

        ///
        private void keepButton_Click(object sender, EventArgs e)
        {
           
            FruitsKeeper keeperObj = new FruitsKeeper();
            int value=0;
            int keepValue = Convert.ToInt16(keepTextBox.Text);
            if (radioButton1.Checked == true)
            {              
                value = 1;
                keptValue = keepValue;
                MessageBox.Show(keeperObj.KeepFruits(value,keepValue,keptValue,bucketObj));
            }
            if (radioButton2.Checked == true)
            {
                value = 2;
                keptValue = keptValue - keepValue;
                MessageBox.Show(keeperObj.KeepFruits(value, keepValue,keptValue,bucketObj));
            }           
        }
        private void statusButton_Click(object sender, EventArgs e)
        {
            MessageBox.Show("you kept " + keptValue.ToString() + " fruits out of " + bucketObj.NumberItems.ToString());
        }
    }
}

if can't implement-comments are most welcome.good day...

0 comments:

Post a Comment

Twitter Delicious Facebook Digg Stumbleupon Favorites More

 
Powered by Blogger