问题描述
通过设计墙壁绘画报价程序,学习和使用其他人的代码(如最后给出的代码例子),read和modify方法,尤其是formalparameters,passarguments以及返回值;理解并且熟练使用out和ref关键字;使用try和catch去refactor代码。1)修改已经存在的方法参数:Adaptthe“CalSquare”methodsoyoupassasanargument“WallLength”and“WallWidth”ratherthanreturnthe“width”or“length”fromthemethod.Namely“WallLength”declaredinMainistobemodifiedin“CalSquare”.2)Modifyanexistingmethodandthelogicofmethodcalls目的:Changeanexistingstaticmethodtoremoveareturntypeandinsteadpassareferenceparameter.Hintusethe“try”and“catch"keywords.Adapt"CalSquare"sothatitreturnsTrueorFalsedependingonwhethertheuserhasenteredavalidnumberasastring.3)SimplifyandRefactor目的:Learnthemeaningof“ref”actoringcode.Learnthatmethodsthatreturnvaluescanbepassedthemselvesasargumenttoothermethods.Refactor(findoutwhatthiswordmeansifyoudon’tknow)thefollowingcodetoeliminatetheuseofthetwoidentifiersMoneyEveryMeterandTotalOfSquareMeters.Don’tforgettodeletetheidentifier:MoneyEveryMeter=CalMoney();TotalOfSquareMeters=DetermSquareMeter(WallWidth,WallLength);FinalResult(TotalOfSquareMeters,MoneyEveryMeter);4)ChangeformalparametersintheMainmethodheader目的:AddtheappropriateformalparameterstotheMainmethodsothatanargument(s)canbepassedfromtheDOScommandline.ModifytheargumentstoMainsothattheyournamecanbepassedtoprogramviathecommandlineargumentinDOS。5)LearntopassargumentsfromDOSandTestthecode目的:Passargumentsfromthecommandlineanduseitinternaltotheconsoleapplication.ModifytheDisplayInstructionsmethodsothattheargumentpassedtotheprogramviaMaincanbepassedtoDisplayInstructionstocreateapersonalisedgreetingmessage。给出的例子如下:==============================================================================================usingSystem;namespaceCarpetExampleWithClassMethods{classPaintingPrice{staticvoidMain(){doubleWallWidth;doubleWallLength;doubleMoneyEveryMeter;doubleTotalOfSquareMeters;GreetingInfo();WallLength=CalSquare("Length");WallWidth=CalSquare("Width");MoneyEveryMeter=CalMoney();TotalOfSquareMeters=DetermSquareMeter(WallWidth,WallLength);FinalResult(TotalOfSquareMeters,MoneyEveryMeter);}publicstaticvoidGreetingInfo(){Console.WriteLine("Thisprogramisdesignedto"+"determinehowmuchmoney"+"youwillpaidforawallpainting.");Console.WriteLine();Console.WriteLine("Youneedtoinput"+"thesizeofthewall");Console.WriteLine("andthepriceforpaintingworks,"+"inpriceeverysquaremeter");Console.WriteLine();}publicstaticdoubleCalSquare(stringside){stringsideValue;doublemeter;Console.Write("HowLongisthe{0}inMeters:",side);sideValue=Console.ReadLine();meter=double.Parse(sideValue);return(meter);}publicstaticdoubleCalMoney(){stringsideValue;doublemoney;Console.Write("Howmuchforeverysquare"+"Meter:");sideValue=Console.ReadLine();money=double.Parse(sideValue);returnmoney;}publicstaticdoubleDetermSquareMeter(doublewidth,doublelength){doubleTotalOfSquareMeters;TotalOfSquareMeters=length*width;returnTotalOfSquareMeters;}publicstaticdoubleDetermMoney(doubleSquareMeter,doubleMoneyEverySquareMeter){return(MoneyEverySquareMeter*SquareMeter);}publicstaticvoidFinalResult(doubleSquareMeter,doubleMoneyEverySquareMeter){Console.WriteLine();Console.Write("Totalsquareis:");Console.WriteLine("{0:N2}",SquareMeter);Console.Write("Payrateis:{0:C}",MoneyEverySquareMeter);Console.WriteLine("Youneedtopay:{0:C}",DetermMoney(SquareMeter,MoneyEverySquareMeter));}}}==============================================================================================
解决方案
解决方案二:
问题一共是上面5个,请哪位大虾能够指点指点,不胜感激
解决方案三:
作业吧?