Exemplo n.º 1
0
        private void displayButton_Click(object sender, EventArgs e)
        {
            //instantiates objects
            Invoice        Company1 = new Invoice();
            Invoice        Company2 = new Invoice();
            OverdueInvoice Company3 = new OverdueInvoice();

            //if else statements
            if (inputTextBox.Text == "ELECTRIC COMPANY")
            {
                // Company1 name
                Company1.Name = "ELECTRIC COMPANY";
                // Amount due
                Company1.Amount = 125.25;
                // Display to user
                displayLabel.Text = Company1.ToString();
            }
            else if (inputTextBox.Text == "MORTGAGE COMPANY")
            {
                // Company2 name
                Company2.Name = "MORTGAGE COMPANY";
                // Amount due
                Company2.Amount = 750.50;
                // Display to user
                displayLabel.Text = Company2.ToString();
            }
            else if (inputTextBox.Text == "WATER COMPANY")
            {
                // Company3 name
                Company3.Name = "WATER COMPANY";
                // Amount due
                Company3.Amount = 175.75;
                // Days overdue
                Company3.DaysOverdue = 60;
                // Display info
                displayLabel.Text = Company3.ToString() + "         Days Overdue:" + Company3.DaysOverdue;
            }
            else
            {
                //declare string variable
                String userInput = inputTextBox.Text;
                //display incorrect input
                displayLabel.Text = "\n" + userInput + " \nINVALID ENTRY - Please Try Again.";
            }
        }
Exemplo n.º 2
0
        private void dspButton_Click(object sender, EventArgs e)
        {
            // delcare constants
            const int SIZE = 4;

            // declear variables
            string companyName = invoiceTextBox.Text;
            int    index       = -1;

            // declare arrays and initilize them
            string[] companyNames = new string[SIZE] {
                "ENERGY ELECTRIC CO-OP", "TEARDROP WATER SUPPLY", "RIVAL MORTGAGE ASSOCIATES", "PRO-TEC INSURANCE GROUP"
            };
            double[] amountsDue = new double[SIZE] {
                175.75, 125.25, 750.50, 400.00
            };
            int[] overdueDays = new int[SIZE] {
                0, 30, 0, 60
            };

            // instantiate objects
            Invoice        invoice        = new Invoice();
            OverdueInvoice overdueInvoice = new OverdueInvoice();

            // find index of user entered company
            for (int i = 0; i < SIZE; i++)
            {
                if (companyName == companyNames[i])
                {
                    index = i;
                    i     = SIZE;
                }
            }

            // deterimine if company is a valid company name
            if (index >= 0)
            {
                // valid company name found
                if (overdueDays[index] > 0)
                {
                    // is overdue
                    // set daysOverdue, amountDue and CompanyName
                    overdueInvoice.AmountDue   = amountsDue[index];
                    overdueInvoice.CompanyName = companyNames[index];
                    overdueInvoice.DaysOverdue = overdueDays[index];

                    // display results and set alignmnet
                    displayLabel.TextAlign = ContentAlignment.TopLeft;
                    displayLabel.Text      = overdueInvoice.ToString();
                }
                else
                {
                    // not over due
                    // set amountDue and CompanyName
                    invoice.AmountDue   = amountsDue[index];
                    invoice.CompanyName = companyNames[index];

                    // display results
                    displayLabel.TextAlign = ContentAlignment.TopLeft;
                    displayLabel.Text      = invoice.ToString();
                }
            }
            else
            {
                // not a valid company
                displayLabel.TextAlign = ContentAlignment.MiddleCenter;
                displayLabel.Text      = "INVALID ENTRY\nPlease Try Again!";
            }

            // select all and set focus
            invoiceTextBox.SelectAll();
            invoiceTextBox.Focus();
        }