如何开发完善的OOAD应用程序. [英] how to develop perfect OOAD application.

查看:63
本文介绍了如何开发完善的OOAD应用程序.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

最近,我正在尝试一家"x"公司.他们向我发送了一些问题,并告诉我只能解决一个问题.

问题是这样的-

除免税的书籍,食品和医疗产品外,所有商品的基本营业税税率为10%.进口税是适用于所有进口商品的附加销售税,税率为5%,且无任何豁免.当我购买物品时,会收到一张收据,上面列出了所有物品的名称及其价格(含税),最后列出了这些物品的总成本以及所支付的营业税总额.营业税的四舍五入规则是,对于n%的税率,p的货架价格包含(np/100四舍五入至最接近的0.05)营业税额.

他们告诉我,他们对您的解决方案的设计方面感兴趣,并希望评估我的面向对象的编程技能."

因此,我提供了以下代码-您可以复制粘贴代码并在VS中运行.

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)
        {
            try
            {
                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)
            {
                Console.WriteLine(ex.Message);
            }
            Console.ReadLine();
        }

        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
    {
        ExemptedProduct=1,
        TaxPaidProduct=2,
        //ImportedProduct=3
    }

    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
                tax+=_productPrice*.05;
            switch (_typeOfProduct)
            {
                case ProductType.ExemptedProduct: break;
                case ProductType.TaxPaidProduct:
                    tax += _productPrice * .10;
                    break;
            }
            return Math.Round(tax, 2);
            //round result before returning
        }
    }


您可以取消注释输入并运行其他输入.

我提供了解决方案,但被拒绝了.

他们说,由于代码解决方案不令人满意,他们无法考虑我目前的空缺职位."

请指导我这里缺少什么.这个解决方案不是很好的OOAD解决方案吗?
如何提高我的OOAD技能.
我的前辈们还说,完美的OOAD应用程序实际上也行不通.

谢谢


you can uncomment 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.

Thanks

推荐答案

公平地说,这不是我所见过的最好的代码,但它似乎按要求执行.现在的困难是,当您为某人编写代码以评估您的水平时,我会用例如数据管理器,计算引擎以及更多可能需要的东西.我还要确保所有内容都经过正确的单元测试,并提供测试代码,该测试代码肯定具有100%的覆盖率.
在这种情况下,我们的目标不是要表明您可以满足最低要求,也不是要过度使用它.
一提示;使用设计模式并遵守命名约定.

我想这是我现在的两分钱.

希望对您有帮助,

干杯,AT
Being fair i''d say it''s not the nicest code i''ve seen an i but it seems to do as requested. Now the difficulty, when you are writing code for someone to evaluate what you''re level might be, i''d draw up a rather extensive model with e.g. a data manager, calculation engine and more stuff you might thing of. I would also make damn sure all was properly unit tested and provide the test code, the test code would certainly have 100% coverage.
The goal in this case is not to show that you can meet the minimal requirements but also not to overdo it to much either.
One hint; use design patterns and keep to the naming conventions.

I guess these are my two cents for now.

Hope it helps,

Cheers, AT


这篇关于如何开发完善的OOAD应用程序.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆