C# 4.0 银行应用程序的交易模块-已应答
我需要事务类中的帮助: 具有的事务类包含以下数据: 跟踪交易数量的计数器。每次存款或存款的增量 撤回。一个客户最多可以在一次登录中进行5次交易。 o 5项可能交易的历史记录。这将是一个美元金额数组,其中 负数表示取款,正数表示存款。清除历史 每次客户登录时 事务对象将执行以下操作: o更新历史记录以反映用户登录时进行的任何交易。跟上…的进展 如上所述在“交易数据”部分中生成的每个交易值。之后 每个事务,递增事务计数器。 o清除所有存储金额的历史记录并重置交易计数 菜单类C# 4.0 银行应用程序的交易模块-已应答,c#-4.0,visual-studio-2012,C# 4.0,Visual Studio 2012,我需要事务类中的帮助: 具有的事务类包含以下数据: 跟踪交易数量的计数器。每次存款或存款的增量 撤回。一个客户最多可以在一次登录中进行5次交易。 o 5项可能交易的历史记录。这将是一个美元金额数组,其中 负数表示取款,正数表示存款。清除历史 每次客户登录时 事务对象将执行以下操作: o更新历史记录以反映用户登录时进行的任何交易。跟上…的进展 如上所述在“交易数据”部分中生成的每个交易值。之后 每个事务,递增事务计数器。 o清除所有存储金额的历史记录并重置交易计数 菜单类 Account[] my
Account[] myCustAcc = new Account[10];
Transaction myCustTrans = new Transaction();
string adminInput = "" adminName = "adm1";
int pinInput = 0, adminChoice = 0,adminPin = 9999,user = 0, input, custCount = 0;
Boolean adminQuit = false;
Boolean appQuit = false;
myCustAcc[0] = new Account();
myCustAcc[0].setCustomerFirstName("Sneha");
myCustAcc[0].setCustomerLastName("Dadhania");
myCustAcc[0].setCustomerAddress("2323 S Dobson Rd");
myCustAcc[0].setCustomerState("AZ");
myCustAcc[0].setCustomerZip(85001);
myCustAcc[0].setCustomerUserName("SMD28");
myCustAcc[0].setCustomerPin(3333);
myCustAcc[0].setCustomerBalance(87000);
custCount++;
myCustAcc[1] = new Account();
myCustAcc[1].setCustomerFirstName("Justine");
myCustAcc[1].setCustomerLastName("Timberlake");
myCustAcc[1].setCustomerAddress("TriBeca, New York. ");
myCustAcc[1].setCustomerState("NY");
myCustAcc[1].setCustomerZip(11013);
myCustAcc[1].setCustomerUserName("JTL00");
myCustAcc[1].setCustomerPin(8989);
myCustAcc[1].setCustomerBalance(34);
custCount++;
myCustAcc[2] = new Account();
myCustAcc[2].setCustomerFirstName("Guest");
myCustAcc[2].setCustomerLastName("Ghost");
myCustAcc[2].setCustomerAddress("Ghost Street");
myCustAcc[2].setCustomerState("CO");
myCustAcc[2].setCustomerZip(87655);
myCustAcc[2].setCustomerUserName("GG111");
myCustAcc[2].setCustomerPin(1111);
myCustAcc[2].setCustomerBalance(0);
custCount++;
do
{
appQuit = false;
Console.Clear();
Console.Write("Enter UserName");
adminInput = Console.ReadLine();
if (adminInput == adminName)
{
Console.Write("Enter Admin Pin");
pinInput = Convert.ToInt32(Console.ReadLine());
if (pinInput != adminPin)
{
Console.WriteLine("You Have Entered Wrong Password");
Console.ReadKey();
continue;
}
else
{
do
{
Console.Clear();
adminQuit = false;
Console.WriteLine("\t\tPlease Select from the Menu");
Console.WriteLine("\t1. Add Customer to Application");
Console.WriteLine("\t2. Return Back to Login Screen");
Console.WriteLine("\t3. Exit the Application");
adminChoice = Convert.ToInt32(Console.ReadLine());
switch (adminChoice)
{
case 1:
//Add customer
break;
case 2:
adminQuit = true;
break;
case 3:
appQuit = true;
break;
default:
Console.WriteLine("Invalid Menu Selection");
return;
}} while (adminQuit == false && appQuit == false);
}}
else {
user = -1;
for (int i = 0; i < custCount; i++)
{
if (adminInput == myCustAcc[i].getCustomerUserName())
{
user = i;
break;} }
if (user == -1)
{
Console.WriteLine("User Does Not Exit !!! Please Try Again");
Console.ReadKey();
continue;
}
Console.Write("Enter User Pin");
if (Convert.ToInt32(Console.ReadLine()) != myCustAcc[user].getCustomerPin() )
{
Console.WriteLine("Invalid Pin");
Console.ReadKey();
continue;
}
do
{
Console.WriteLine("\t\t Welcome to Super Fast Banking Application");
Console.WriteLine("\n<<<Please Select Following Menus>>>");
Console.WriteLine("\t1> GetBalance");
Console.WriteLine("\t2> Deposit");
Console.WriteLine("\t3> Withdraw");
Console.WriteLine("\t4> Modify");
Console.WriteLine("\t5> Display");
Console.WriteLine("\t6> Exit");
input = Convert.ToInt32(Console.ReadLine());
switch (input)
{
case 1:
double balance;
balance = myCustAcc[user].getBalance();
Console.Write("Your Current Balance is {0:C} ",balance);
break;
case 2:
Console.Write("\nPlease enter Numbers to Deposit balance :");
myCustAcc[user].Customerdeposit();
Console.WriteLine("New Balance after Deposit is {0:C}", myCustAcc[user].getBalance());
break;
case 3:
Console.Write("\n Please enter Dollar Amount to Withdraw:");
myCustAcc[user].customerWithdraw();
Console.WriteLine("New Balance after Withdraw is {0:C}",myCustAcc[user].getBalance());
break;
case 4:
//modify
break;
case 5:
double newDisplay;
newDisplay = myCustAcc[user].getBalance();
Console.WriteLine("The Balance in your Account is {0:C}",newDisplay);
break;
case 6:
break;
default: Console.WriteLine("Exit the Application!!!");
break;
}
} while (appQuit == false);
}
Console.ReadKey();
} while (appQuit != true);
}}}
您已经指定了从属性到函数的所有内容,只需编写代码即可 现在这将是一匙羹,但同样,您的更改是错误的 帐户类别:
public double getBalance()
{
return customerBalance;
}
public bool Customerdeposit()
{
double deposit = Convert.ToDouble(Console.ReadLine());
if (deposit <= 0)
{
return false;
}
customerBalance = customerBalance + deposit;
return true;
}
public bool customerWithdraw()
{
double withdraw = Convert.ToDouble(Console.ReadLine());
{
if (withdraw <= 0 || customerBalance < withdraw )
{
return false;
}
customerBalance = customerBalance - withdraw;
return true;
}
}
}
将为每笔交易拨打电话:
Transaction trans= new Transaction();
trans.credit(myCustAcc[user],500);
你的问题是?如何在一个银行应用程序中跟踪5笔交易我可以通过电子邮件给你我的代码bcz很难在这里粘贴代码你可以发布逻辑吗。(区块码)好的,我将发布logicI更新了存款和取款方法的一些代码,在调用它们的情况下进行切换,但我在那里遇到了一些问题,例如,如果客户有0美元余额,它应该不允许他们取款,但我的允许取款我们在编程中没有使用try-and-catch。我知道我们可以写if-else语句而不是try-and-catch。但我不确定是否用if-else语句编写代码。你能帮我吗?我用if-else代码更新了代码,用了事务类的代码。你的代码写错了(错误地使用了返回语句),试着理解代码,然后在纸上进行试运行。
public double getBalance()
{
return customerBalance;
}
public bool Customerdeposit()
{
double deposit = Convert.ToDouble(Console.ReadLine());
if (deposit <= 0)
{
return false;
}
customerBalance = customerBalance + deposit;
return true;
}
public bool customerWithdraw()
{
double withdraw = Convert.ToDouble(Console.ReadLine());
{
if (withdraw <= 0 || customerBalance < withdraw )
{
return false;
}
customerBalance = customerBalance - withdraw;
return true;
}
}
}
class Transaction
{
private int[] arr;
private int cntr;
Transaction()
{
arr = new int[5];
cntr = 0;
}
private void update(int amount)
{
arr[cntr]=amount;
cntr++;
}
public void credit(Account obj, int amount)
{
if(cntr!=5)
{
if(obj.CustomerDeposit(amount))
Update(amount); //works only when true returned from above.
else
//print message
}
else
Console.WriteLine("Transaction limit exceeded");
}
public void debit(Account obj, int amount)
{
if(cntr!=5)
{
if(obj.CustomerWithdraw(amount))
Update(-amount);
else
//print any message
}
else
Console.WriteLine("Transaction limit exceeded");
}
}
Transaction trans= new Transaction();
trans.credit(myCustAcc[user],500);