我想找到一个类的示例,它扩展了java中的一个抽象类,它旨在执行基于单选按钮和单击按钮的操作。按钮点击扩展抽象类操作的Java类
说明:
创建交易表格来管理帐户余额。
创建事务选项:
存款增加平衡 检查从平衡 减去如果余额>检查然后从余额减去平衡 其他显示资金不足的消息 检查和减服务费($ 10) 服务费($ 10)从余额中扣除
使用抽象类交易创建类:
类存款 类ServiceCharge 类检查 重写抽象函数calculateBalance()每班上平衡 进行相应的计算扔在类Check.calculateBalance)异常(
我是使用下面的抽象类:
public abstract class Transaction {
/**
The Transaction class simulates a bank account.
*/
static final double SERVICE_CHARGE = 10.0;
double transactionamount = 0.0;
static double balance = 0.0; // Account balance
static double totalDeposits = 0.0;
static double totalChecks = 0.0;
static double totalServiceCharges = 0.0;
static int numberDeposits = 0;
static int numberChecks = 0;
static int numberServiceCharges = 0;
public Transaction() {
transactionamount = 0.0;
}
public Transaction(double amount) {
this.transactionamount = amount;
}
public Transaction(String str) {
transactionamount = Double.parseDouble(str);
}
public void deposit(double amount) {
balance += amount;
}
public void deposit(String str) {
balance += Double.parseDouble(str);
}
static public double getBalance() {
return balance;
}
abstract void calculateBalance() throws Exception;
}
下面是我想要的工作:
扩展Transaction类的类首先列出,我的例子是Check类。我试图设置我的计算按钮和交易菜单选项,以根据单选按钮选择和文本字段数据传递信息。
package Assignment5;
public class Check extends Transaction {
\t public double checksBalance(double check) // makes alterations to Transaction variables once information is passed from text field.
\t {
\t \t check = transactionamount;
\t \t totalChecks = check + totalChecks; // increases total amount in checks.
\t \t balance = check + totalDeposits - totalChecks - totalServiceCharges;
\t \t return check;
\t \t
\t \t
\t }
\t public int checks() {
\t \t return numberChecks++; // increases number of checks written.
\t \t }
\t
\t
\t @Override
\t void calculateBalance() throws Exception {
\t \t // TODO Auto-generated method stub
\t \t
\t }
\t
}
public class TypePanel extends JPanel
\t \t {
\t \t public String deposit, check, service;
\t \t
\t \t \t JRadioButton depositButton;
\t \t \t JRadioButton checkButton;
\t \t \t JRadioButton serviceButton;
\t ButtonGroup radioButtonGroup;
\t \t \t public TypePanel() //
\t \t \t {
\t \t \t \t setLayout(new GridLayout(3, 1)); // Panel Layout
\t \t \t \t depositButton = new JRadioButton("Deposit", true); // Radiobuttons listed here.
\t \t checkButton = new JRadioButton("Check");
\t \t serviceButton = new JRadioButton("Service Charge");
\t \t
\t \t radioButtonGroup = new ButtonGroup();
\t \t \t \t radioButtonGroup.add(depositButton);
\t \t radioButtonGroup.add(checkButton);
\t \t radioButtonGroup.add(serviceButton);
\t \t
\t \t add(depositButton);
\t \t \t \t add(checkButton);
\t \t \t \t add(serviceButton);
\t \t \t }
\t \t \t
\t \t \t public void GetTotals()
\t \t \t {
\t \t \t \t
\t \t \t if (checkButton.isSelected())
\t \t \t \t {
\t \t \t \t
\t \t \t \t Transaction.transactionamount = AmountPanel.amountEntered;
\t \t \t \t }
\t \t \t \t
\t \t \t
\t \t }
public class AmountPanel extends JPanel {
\t \t \t public static Object amountEntered;
\t \t \t public String amountInput;
\t \t \t private JLabel amountLabel;
\t \t private String defaultText;
\t \t private JTextField amountTextField;
\t \t
\t \t \t public AmountPanel()
\t \t {
\t \t \t setLayout(new GridLayout(2, 1)); // Panel Layout.
\t \t \t amountLabel = new JLabel("Enter Amount");
\t \t \t amountTextField = new JTextField(6);
\t \t \t defaultText = "0"; // Default value placed in textfields within this panel.
\t \t \t amountTextField.setText(defaultText);
\t \t \t add(amountLabel);
\t \t \t add(amountTextField);
\t }
\t public double GetAmount()
\t {
\t \t \t double amountEntered;
\t \t \t amountInput = amountTextField.getText();
\t \t \t amountEntered = Double.parseDouble(amountInput);
\t \t \t return amountEntered;
\t \t }
\t }
我不包括我所有的代码,但我想从文本字段中输入到位于检查类的量的方法,使他们在随后转而影响Transaction类中的变量。尽管如此,我认为我不是以最好的方式做到这一点。
为什么不先尝试这样做自己,看看你能想出?你没有任何失败的尝试和所有获得。如果你成功了 - 很好,你也做得很好,也可以自己做,如果你失败了,那么没有什么大问题,因为你可以回到这里,问一个新问题,一个更加具体和可回答的问题**,并可能会得到一个伟大的和迅速的答案。 –
此外,您的指示非常明确地说明您必须执行的操作。有了这些说明和Java书籍或抽象类教程的几乎任何介绍,您至少应该可以自行开始。再次,我敦促你请这样做。 –