Java 课堂上的具体任务。我不是要回答,而是要解释主要目的
我是Java的初学者,希望能更多地了解这种语言。我知道这需要实践,我希望尽我最大的能力去探索这个问题,但是我需要更多地理解这个问题。我已经完成了我的一些代码,但是不能发布,因为我班上的其他人可以看到并复制代码 以下是问题:Java 课堂上的具体任务。我不是要回答,而是要解释主要目的,java,bluej,Java,Bluej,我是Java的初学者,希望能更多地了解这种语言。我知道这需要实践,我希望尽我最大的能力去探索这个问题,但是我需要更多地理解这个问题。我已经完成了我的一些代码,但是不能发布,因为我班上的其他人可以看到并复制代码 以下是问题: 假设您正在为自动柜员机设计一个程序。ATM生成的交易被发送到银行中央计算机进行处理 在本作业中,您将创建两个类,“Account”和“Transaction”。Account对象应该具有唯一的帐号(可以用整数表示)和余额。最初,余额为零。交易对象应具有正在交易的金额和对与交
假设您正在为自动柜员机设计一个程序。ATM生成的交易被发送到银行中央计算机进行处理 在本作业中,您将创建两个类,“Account”和“Transaction”。Account对象应该具有唯一的帐号(可以用整数表示)和余额。最初,余额为零。交易对象应具有正在交易的金额和对与交易关联的帐户类的引用 下面是调用的两个类的示例:
/**
* This class contains a main method that calls methods in the classes you will write.
*
* @author (your name)
* @version (a version number or a date)
*/
public class RunTransactions
{
static void main()
{
// Create two new accounts with the given account numbers
Account fred = new Account(1234);
Account jim = new Account(6778);
// Provide accessor methods for account information.
int accountNumber = fred.getAccountNumber();
float balance = fred.getBalance();
// Transactions consist of an account reference and an amount
Transaction t1 = new Transaction(fred, 20);
Transaction t2 = new Transaction(jim, 10);
Transaction t3 = new Transaction(jim, -20);
// Transactions must contain a "process" method that is called to
// actually perform the transaction.
// A transaction should not be allowed if it results in a negative balance.
t1.process();
t2.process();
t3.process();
// Print out a report of the account balance.
// The format should be like this: Account 6778 has balance $20.0
fred.report();
jim.report();
}
}
下载此文件。它包含一个只包含RunTransactions类的BlueJ项目。您必须创建自己的帐户和交易类。您可以创建任何您认为合适的字段和方法,但必须提供完全可以如上所述调用的方法
报告方法应该打印出一条简单的消息,给出帐号和余额。格式应该是
Account <account number> has balance $<account balance>
在以后的课程中,您将学习主要方法和静态限定符。现在,您只需要知道,当右键单击RunTransactions类时,您将在菜单void main()中看到一项。单击此按钮将运行main方法,该方法将调用您的代码
您可以更改main方法,以使用不同的帐户和事务组合测试代码。请记住,类和方法的名称必须完全相同,参数的类型必须相同,返回值必须相同
当您提交作业时,我们使用不同的主方法测试您的代码。他们要求您编写两个类——Account和Transaction,这样当提供的RunTransactions中的代码执行时(主方法运行),应用程序将产生预期的输出。祝你好运 那你的问题是什么?
Account 1234 has balance $20.0
Account 6778 has balance $10.0