c# create perfect OOPS design RRS feed

  • Question

  • Hi Everyone,

    Recently I was trying for a company ‘x’. They send me some set of questions and told me to solve only one.

    The problem is like this -

    Basic sales tax is applicable at a rate of 10% on all goods, except books, food, and medical products that are exempt. Import duty is an additional sales tax applicable on all imported goods at a rate of 5%, with no exemptions. When I purchase items I receive a receipt which lists the name of all the items and their price (including tax), finishing with the total cost of the items, and the total amounts of sales taxes paid. The rounding rules for sales tax are that for a tax rate of n%, a shelf price of p contains (np/100 rounded up to the nearest 0.05) amount of sales tax.

    “They told me, they are interested in the DESIGN ASPECT of your solution and would like to evaluate my OBJECT ORIENTED PROGRAMMING SKILLS.”

    So I provided below code – you can just copy paste code and run in VS.

    class Program
            static void Main(string[] args)
                    double totalBill = 0, salesTax = 0;
                    List<Product> productList = getProductList();
                    foreach (Product prod in productList)
                        double tax = prod.ComputeSalesTax();
                        salesTax += tax;
                        totalBill += tax + (prod.Quantity * prod.ProductPrice);
                        Console.WriteLine(string.Format("Item = {0} : Quantity = {1} : Price = {2} : Tax = {3}", prod.ProductName, prod.Quantity, prod.ProductPrice + tax, tax));
                    Console.WriteLine("Total Tax : " + salesTax);
                    Console.WriteLine("Total Bill : " + totalBill);              
                catch (Exception ex)

            private static List<Product> getProductList()
                List<Product> lstProducts = new List<Product>();
                //input 1
                lstProducts.Add(new Product("Book", 12.49, 1, ProductType.ExemptedProduct, false));
                lstProducts.Add(new Product("Music CD", 14.99, 1, ProductType.TaxPaidProduct, false));
                lstProducts.Add(new Product("Chocolate Bar", .85, 1, ProductType.ExemptedProduct, false));

                //input 2
                //lstProducts.Add(new Product("Imported Chocolate", 10, 1, ProductType.ExemptedProduct,true));
                //lstProducts.Add(new Product("Imported Perfume", 47.50, 1, ProductType.TaxPaidProduct,true));

                //input 3
                //lstProducts.Add(new Product("Imported Perfume", 27.99, 1, ProductType.TaxPaidProduct,true));
                //lstProducts.Add(new Product("Perfume", 18.99, 1, ProductType.TaxPaidProduct,false));
                //lstProducts.Add(new Product("Headache Pills", 9.75, 1, ProductType.ExemptedProduct,false));
                //lstProducts.Add(new Product("Imported Chocolate", 11.25, 1, ProductType.ExemptedProduct,true));
                return lstProducts;

        public enum ProductType

        class Product
            private ProductType _typeOfProduct = ProductType.TaxPaidProduct;
            private string _productName = string.Empty;
            private double _productPrice;
            private int _quantity;
            private bool _isImportedProduct = false;

            public string ProductName { get { return _productName; } }
            public double ProductPrice { get { return _productPrice; } }
            public int Quantity { get { return _quantity; } }

            public Product(string productName, double productPrice,int quantity, ProductType type, bool isImportedProduct)
                _productName = productName;
                _productPrice = productPrice;
                _quantity = quantity;
                _typeOfProduct = type;
                _isImportedProduct = isImportedProduct;

            public double ComputeSalesTax()
                double tax = 0;
                if(_isImportedProduct) //charge 5% tax directly
                switch (_typeOfProduct)
                    case ProductType.ExemptedProduct: break;
                    case ProductType.TaxPaidProduct:
                        tax += _productPrice * .10;
                return Math.Round(tax, 2);
                //round result before returning

    you can uncommnet input and run for different inputs.

    I provided the solution but I was rejected.

    "They said, they are unable to consider me for our current open positions because code solution is not satisfactory."

    Please guide me what is missing here. Is this solution is not a good OOAD solution.
    How can I improve my OOAD skills.
    My seniors also says perfect OOAD application will also not work practically.


    Monday, February 20, 2012 5:24 PM

All replies

  • this what they(their own words) said in mail when they asked this question -

    For the solution, we would want you use either Java, Ruby or C#.

    ·We are interested in the DESIGN ASPECT of your solution and would like to evaluate your


    ·You may use external libraries or tools for building or testing purposes. Specifically, you may use

    unit testing libraries or build tools available for your chosen language (e.g., JUnit, Ant, NUnit, NAnt,

    Test::Unit, Rake etc.)

    ·Optionally, you may also include a brief explanation of your design and assumptions along with

    your code.

    ·Kindly note that we are NOT expecting a web-based application or a comprehensive UI. Rather,

    we are expecting a simple, console based application and interested in your source code.
    Monday, February 20, 2012 5:25 PM
  • For reference, the original thread for this discussion is here.

    Check out My Blog. Now updated to actually work!

    Monday, February 20, 2012 5:56 PM