问题描述
这是要求Createanewclass‘DiscreteStock’withthefollowingfeatures:InheritsfromtheStockclass;Aprivateintegerattributenamed‘_StoredStock’;Aprivateintegerattributenamed‘_ShelfStock’;Aprivatedoubleattributenamed‘_WeightPerItem’;Publicread-onlypropertiesencapsulatingtheaboveattributes;Apubliccustomconstructorwhichacceptsparametersforline(Line)andweightPerItem(double)thatpassesthelineparametertothebaseclass’constructorandinitialisestheaboveattributes(initialisebothstoredandshelfstocktozero);Implements/overridestheAdjustStock()method:oIfthequantityisadiscretequantity,addthespecifiedquantitytostoredstock;oIfthequantityisnotadiscretequantity,itisignored.Implements/overridesthePurchase()method:oDeterminethenumberofitemstobepurchased:Ifthequantityisadiscretequantity,thenumberofitemstobepurchasedwillbethequantityspecified;Ifnoquantityisspecified(nullvalue)orthequantityspecifiedisnotadiscretequantity,thenumberofitemstobepurchasedwillbeasingleitem(oneitem);Ifthenumberofitemstobepurchasedexceedsthenumberofitemsontheshelf(theshelfstock),thenthenumberofitemstobepurchasedisreducedtobeequaltotheshelfstock,i.e.,ifyouwantedtobuyfiveitemsbuttherewasonlythreeontheshelf,youcouldonlybuythreeitems;oIfthenumberofitemstobepurchasediszero,theitemoutputparameterissettonullandavalueoffalseisreturned;oOtherwisetheshelfstockisreducedbythenumberofitemstobepurchasedandtheitemsoutputparameterisassignedanItemobjectcreatedwithquantitysettotheamountpurchased,theline’sdescription,theweightsettothetotalweightofthoseitems(numberofitems*weightperitem),andavalueoftrueisreturned;Implements/overridestheRestock()method,whereanystoredstockisaddedto/movedtotheshelfstock;OverridestheToString()methodtoreturnastring:shelfstockorifthereisalsostoredstock:shelfstock(storedstockinstorage)然后这是前面要用的类1.usingSystem;namespaceproject1{classVolumeStockQuantity:StockQuantity{publicVolumeStockQuantity(doubleQuantity){Quantity=_quantity;}privatedouble_quantity;publicdoublequantity{get{return_quantity;}set{_quantity=value;}}}}2.usingSystem;namespaceproject1{abstractclassStockQuantity{}}3.usingSystem;namespaceproject1{classDiscreteStockQuantity:StockQuantity{publicDiscreteStockQuantity(intQuantity){_quantity=Quantity;}privateint_quantity;publicintquantity{get{return_quantity;}set{_quantity=value;}}}}4.usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text;usingSystem.Threading.Tasks;namespaceproject1{abstractclassStock{privateLine_lines;publicLinelines{get{return_lines;}set{_lines=value;}}publicabstractvoidAdjustStock(StockQuantityquantity);publicabstractboolPurchase(StockQuantityquantity,outItemitem);publicabstractvoidRestock();}}图片里面是我做好的类这是我写的代码usingSystem;namespaceproject1{classDiscreteStock:Stock{publicDiscreteStock(intStoredStock,intShelfStock,doubleWeightPerItem){_StoredStock=StoredStock;_ShelfStock=ShelfStock;_WeightPerItem=WeightPerItem;}privatedouble_WeightPerItem;publicdoubleWeightPerItem{get{return_WeightPerItem;}}privateint_ShelfStock;publicintShelfStock{get{return_ShelfStock;}}privateint_StoredStock;publicintStoredStock{get{return_StoredStock;}set{_StoredStock=value;}}privateLine_Lines;publicDiscreteStock(DoubleWeightPerItem,Line_lines){base(_lines);}publicoverridevoidAdjustStock(StockQuantityquantity){foreach(DiscreteStockdsin_StoredStock)if(dsisDiscreteStockQuantity)StoredStock+=Convert.ToInt32(DiscreteStockQuantity._quantity);}publicoverrideboolPurchase(StockQuantityquantity,outItemitem){returnfalse;}publicoverridevoidRestock(){}好难啊好难啊好难啊求论坛大神教我把这个类做完吧,我现在只学了多态和继承教我吧教我吧,尽情的调教我吧