日期:2014-05-20 浏览次数:20839 次
public class Payment {
//constructor
public Payment(int fiveC, int tenC, int twentyC, int fiftyC, int oneD, int twoD, int fiveD, int tenD, int twentyD, int fiftyD, int hundredD)
{
fiveCents = fiveC;
tenCents = tenC;
twentyCents = twentyC;
fiftyCents = fiftyC;
oneDollar = oneD;
twoDollars = twoD;
fiveDollars = fiveD;
tenDollars = tenD;
twentyDollars = twentyD;
fiftyDollars = fiftyD;
hundredDollars = hundredD;
}
public void setValues(int fiveC, int tenC, int twentyC, int fiftyC, int oneD, int twoD, int fiveD, int tenD, int twentyD, int fiftyD, int hundredD)
{
}
public void setFiveCents(int value)
{
fiveCents = value;
}
public void setTenCents(int value)
{
tenCents = value;
}
public void setTwentyCents(int value)
{
twentyCents = value;
}
public void setFiftyCents(int value)
{
fiftyCents = value;
}
public void setOneDollar(int value)
{
oneDollar = value;
}
public void setTwoDollars(int value)
{
twoDollars = value;
}
public void setFiveDollars(int value)
{
fiveDollars = value;
}
public void setTenDollars(int value)
{
tenDollars = value;
}
public void setTwentyDollars(int value)
{
twentyDollars = value;
}
public void setFiftyDollars(int value)
{
fiftyDollars = value;
}
public void setHundredDollars(int value)
{
hundredDollars = value;
}
public int getFiveCents(int value)
{
}
public int getTenCents(int value)
{
}
public int getTwentyCents(int value)
{
}
public int getFiftyCents(int value)
{
}
public int getOneDollar(int value)
{
}
public int getTwoDollars(int value)
{
}
public int getFiveDollars(int value)
{
}
public int getTenDollars(int value)
{
}
public int getTwentyDollars(int value)
{
}
public int getFiftyDollars(int value)
{
}
public int getHundredDollars(int value)
{
}
public int valueOfDollars()
{
}
public int valueOfCents()
{
}
public float valueOfPayment()
{
}
//11 types of notes in the system
private int fiveCents;
private int tenCents;
private int twentyCents;
private int fiftyCents;
private int oneDollar;
private int twoDollars;
private int fiveDollars;
private int tenDollars;
private int twentyDollars;
private int fiftyDollars;
private int hundredDollars;
}
Payment payment=new Payment(a,b,c,d,....);//创建对象payment,这里的abcd就是构造方法里的参数 payment.XXX;//这里的XXX就是你类里的方法 比如 payment.setFiveCents(int value)就调用了setFiveCents()这个方法
------解决方案--------------------
public void setValues(int fiveC, int tenC, int twentyC, int fiftyC, int oneD, int twoD, int fiveD, int tenD, int twentyD, int fiftyD, int hundredD)
{
//调用下面的setXXX()方法
setFiveCents(数值);
.
.
.
}
至于其他的,就看你要实现什么样的逻辑功能才好写。