银行应用程序的交易模块 - 已回答

时间:2014-04-28 15:40:14

标签: c#-4.0 visual-studio-2012

我在交易类中需要帮助:

包含以下数据的事务类:

用于跟踪交易数量的计数器。每笔存款增加或 退出了。客户只需一次登录即可完成5笔交易。 o 5种可能的交易历史。这将是一个美元金额的数组,其中a 负数是提款,正数是存款。清除历史 每次客户登录时。

交易对象将执行以下操作: o更新历史记录以反映用户登录时所做的任何事务。跟踪 每个交易价值如上所述在交易数据部分中进行。后 每个事务,增加事务计数器。 o清除所有存储金额的历史记录并重置交易计数

菜单类

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 void  Customerdeposit()
 {
double deposit = Convert.ToDouble(Console.ReadLine());
if (deposit <= 0)
 {
Console.WriteLine("\nCannot Deposit");
}
else
 {
customerBalance = customerBalance + deposit;
}
}
public void customerWithdraw()
{
double withdraw = Convert.ToDouble(Console.ReadLine());
{
if (withdraw >= 0)
{
customerBalance = customerBalance - withdraw;
}
else
{
Console.WriteLine("There is not Sufficient fund in your account to withdraw");
} }}}

我尝试使用下面的代码为事务类编写代码 但obj.Customerdeposit(金额)有很多错误;如果条件和更新(金额);

     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)
    {
        obj.Customerdeposit(amount);
        return;
        Update(amount);

     }
    else
    {
    Console.WriteLine("Transaction limit exceeded");        
    }}
     public void debit(Account obj, int amount)
    {
    if(cntr!=5)
    {
    obj.customerWithdraw(amount);
    return;
    Update(-amount);
    }
    else
    {
    Console.WriteLine("Transaction limit exceeded");        
}    
}
}
}

1 个答案:

答案 0 :(得分:0)

您已经指定了从属性到函数的所有内容,只需编写代码即可。

现在这将是勺子喂食,但是,你的改变也是错误的。

帐户类:

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;
}
}
 }

现在您的TransactionClass可以是:(自己添加其他功能)

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);