【发布时间】:2017-08-19 05:09:10
【问题描述】:
我的程序有问题。我的问题是我不能从我的存款价值中减去我的提款。
代码如下:
public static void main(String[] args) {
double cash;
boolean more = true;
Deposite dep = new Deposite();
Withdraw with = new Withdraw();
while (more) {
cash = Double.parseDouble(JOptionPane.showInputDialog("Cash Deposite"));
dep.Deposite(cash);
dep.print();
int con = JOptionPane.YES_NO_OPTION;
int con1 = JOptionPane.showConfirmDialog(null, "Do you want more Deposites?","DEPOSITORY",con);
if (con1 == 1) {
int con3 = JOptionPane.showConfirmDialog(null, "Withdraw now?","WITHDRAWAL",con);
if (con3 == 0) {
cash = Double.parseDouble(JOptionPane.showInputDialog("Cash Withdraw"));
with.Withdraw(cash);
with.print();
System.out.println("Thanks");
}
}
}
}
这是我为其功能创建的子类
public class Deposite {
private double depcash;
public double Deposite(double cash){
depcash += cash;
return this.depcash;
}
void print(){
System.out.printf("Your deposite is $%5.2f",depcash);
System.out.println(" ");
}
}
这是给我的退学课的。我继承它。但我仍然不知道它是如何工作的。
代码如下:
public class Withdraw extends Deposite {
double cash;
public double Withdraw(double withdraw){
super.Deposite(withdraw);
cash -=withdraw;
return cash;
}
void print (){
System.out.printf("You Cash Balance now is $%5.2f",cash);
System.out.println(" ");
}
}
【问题讨论】:
-
你有两个不同的班级。你在哪里存款和从哪里取款?
-
所以只能由一个班级完成?