C# – Object Oriented Programming – Lab 5

You are required to develop an App, which acts as a fashion advisor. The program will have a form where you can type in the colour of your top, your pants and your shoes. The program will then give advice on whether the colours match. The program can use any feedback mechanism desirable.

The rules the program should implement are as follows:

The program only understands the colours black, red, blue, green, pink, brown or orange. The program should generate an error if any other colour is typed.

Black top, pants and shoes are fine
Brown shoes, blue pants and any coloured top is fine
Black shoes, blue pants and any coloured top is fine
Brown shoes, brown pants and blue top is fine
Brown shoes, black pants and red top is fine
Black shoes, brown pants and blue top is fine
Black shoes, black pants and blue top is fine
Any coloured shoes with orange pants are fine
Green shoes with any coloured pants and any coloured top, so long as its not red are fine.
All pink is fine.
Never have pink shoes with green pants, but pink shoes with red pants are fine.

Anything other combinations, the program should indicate that the particular combination of colours is not recommended.

Here’s my solution using a WPF app:

This is what the app looks like:

This is my code:


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace FashionAdviserApp
{
    ///
<summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>

    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, RoutedEventArgs e)
        {
            string black = "black";
            string blue = "blue";
            string brown = "brown";
            string green = "green";
            string orange = "orange";
            string pink = "pink";
            string red = "red";

            if ((shoeBox.Text != black || shoeBox.Text != blue || shoeBox.Text != brown || shoeBox.Text != green || shoeBox.Text != orange || shoeBox.Text != pink || shoeBox.Text != red)
                || (topBox.Text != black || topBox.Text != blue || topBox.Text != brown || topBox.Text != green || topBox.Text != orange || topBox.Text != pink || topBox.Text != red)
                || (pantsBox.Text != black || topBox.Text != blue || topBox.Text != brown || topBox.Text != green || topBox.Text != orange || topBox.Text != pink || topBox.Text != red))
            {
                answer.Text = "error. choose colours from the list above";
            }

            if (shoeBox.Text == black)
            {
                if (topBox.Text == blue)
                {
                    if (pantsBox.Text == brown || pantsBox.Text == black)
                    {
                        answer.Text = "great choice!";
                    }
                }

                if (topBox.Text == black && pantsBox.Text == black)
                {
                    answer.Text = "safe choice";
                }

                if (pantsBox.Text == blue && topBox.Text == black || topBox.Text == blue || topBox.Text == brown || topBox.Text == green || topBox.Text == orange || topBox.Text == pink || topBox.Text == red)
                {
                    answer.Text = "these work";
                }
            }
            else
            {
                answer.Text = "blehhh";
            }

            if (shoeBox.Text == brown)
            {
                if (pantsBox.Text == blue && topBox.Text == black || topBox.Text == blue || topBox.Text == brown || topBox.Text == green || topBox.Text == orange || topBox.Text == pink || topBox.Text == red)
                {
                    answer.Text = "these work";
                }

                if (pantsBox.Text == brown && topBox.Text == blue)
                {
                    answer.Text = "great choice!";
                }

                if (pantsBox.Text == black && topBox.Text == red)
                {
                    answer.Text = "great choice!";
                }
            }

            if (pantsBox.Text == orange)
            {
                if ((topBox.Text == black || topBox.Text == blue || topBox.Text == brown || topBox.Text == green || topBox.Text == orange || topBox.Text == pink || topBox.Text == red) && (shoeBox.Text == black || shoeBox.Text == blue || shoeBox.Text == brown || shoeBox.Text == green || shoeBox.Text == orange || shoeBox.Text == pink || shoeBox.Text == red))
                {
                    answer.Text = "these are ok";
                }
            }

            if (shoeBox.Text == green && (topBox.Text == red || pantsBox.Text == red))
            {
                answer.Text = "not cool!";

            }
            else if (shoeBox.Text == green )
            {
                answer.Text = "that works";
            }

            if (pantsBox.Text == pink && shoeBox.Text == pink && topBox.Text == pink)
            {
                answer.Text = "bit bright, but ok!";
            }

            if (shoeBox.Text == pink && pantsBox.Text == green)
            {
                answer.Text = "this is a mess";
            }
            else if (shoeBox.Text == pink && pantsBox.Text == red)
            {
                answer.Text = "are you a fashion advisor?";
            }

        }
    }
}
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s