如何实现两个类的结合啊..一个类调用另一类....
请问大家:比如我设计一个类
public class CashRegister
{
public CashRegister()
{
purchase = 0;
payment = 0;
}
public void recordpurchase(double amout)
{
double newtotal = purchase + amout;
purchase = newtotal;
}
public void enterpayment(double dollar,double quarter,double dime,double nickel)
{
payment = dollar*DOLLARVALUE + quarter*QUARTERVALUE + dime*DIMEVALUE + nickel*NICKELVALUE ;
}
public double givechange()
{
double change = payment - purchase;
purchase = 0;
payment =0;
return change;
}
public static final double DOLLARVALUE = 1;
public static final double QUARTERVALUE = 0.25;
public static final double DIMEVALUE = 0.1;
public static final double NICKELVALUE = 0.05;
private double purchase;
private double payment;
private double change;
}
又设计一类
public class CashRegisterTester
{
public static void main(String[] arg)
{
CashRegister register = new Cashregister();
register.recordpurchase(0.75);
register.recordpurchase(1.6);
register.enterpayment(1,2,3,4);
System.out.println(register.givechange());
}
如何实现他们的合并啊,前面有老帖有关这个内容但是讲的不是很清楚,而且编译的也没讲清楚.大家帮帮我啊...
我是相当的积极的java初学者...谢谢