当前位置: 代码迷 >> J2SE >> 一道小难题,Java的class该如何写
  详细解决方案

一道小难题,Java的class该如何写

热度:59   发布时间:2016-04-24 02:04:07.0
一道小难题,Java的class该怎么写?
Java code
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;}

Assignment很难很吐血,上面是老师给出的Payment class要我自己修改和补完空白部分,变量名对应有国外钱币的数值,若fiveDollars = 5,就代表5张5块纸币.. 麻烦给点建议T_____________T
还有,void main已经写好,但不会call这个class,请教高手!

------解决方案--------------------
Java code
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(数值);
.
.
.

}

至于其他的,就看你要实现什么样的逻辑功能才好写。
  相关解决方案