-5
我有一個面向對象的通用編程問題。這是來自一項任務,我寫了我的答案,但我懷疑它的導師正在尋找什麼。我一直在尋找任何人對C#OOP技術用於正確實現類的建議和意見。在C中實現一個硬幣罐#
問題: 在C#中實現硬幣罐。硬幣罐只接受美國造幣,並且容量爲32液體盎司。另外,罐子有一個計數器,以收集資金總額的軌道並具有重置爲$ 0.00包裝
我的代碼計數的能力:
interface ICoinJar
{
int coinage
{
get;
set;
}
void resetcount();
}
static class USCoinTypes
{
//Might want to make this a static array.
public static readonly int US_CURRENCY_TYPE = 1;
public static readonly int CURRENCY_AMOUNT = 0;
public static readonly int CURRENCY_VOLUME = 1;
public static readonly int MAX_VOLUME = 32;
public enum CoinTypes
{
ONE_CENT = 0,
FIVE_CENT,
TEN_CENT,
TWENTY_FIVE_CENT
}
public static readonly int[,] CoinInfo =
{
//amount, volume
{1,5},
{5,6},
{10,3},
{25,8}
};
}
class USCoinJar : ICoinJar
{
// coinage in cents (NOT $)
public int coinage { get; set; }
public int volume { get; set; }
public USCoinJar()
{
}
//in Cents.
//Could also make this accept an array for inserting multiple coins.
public bool addcoins(int amount, int volume, USCoinTypes.CoinTypes currencytype)
{
if (this.volume + volume > USCoinTypes.MAX_VOLUME)
return false;
coinage = coinage + amount;
this.volume = this.volume + volume;
return true;
}
public void resetcount()
{
coinage = 0;
volume = 0;
}
}
只是供參考:您所擁有的價值的美國硬幣名稱是一分錢(一分),鎳(五分),一角(十分)和四分之一(二十五分),而您錯過了50分(半美元)和$ 1.00(美元)硬幣。 –
你的問題是什麼?它工作不正常嗎?你只是想讓別人查看你的代碼嗎?你可以嘗試[code review .SE](http://codereview.stackexchange.com/)。另外,我會把你的錢幣信息放在課堂上(ICoin,Penny,Nickel等),而不是一堆靜態的東西。失去陣列,這只是不必要的混亂。 –
你並不是真的在這裏問一個問題,你只是傾銷你的代碼,並要求我們修復它。我在下面提供了一些一般性說明,但是如果這是您能夠獲得的最遠的話,您真的應該向您的教授發表意見。 – Guvante