向每个Account对象添加随机生成的帐号 [英] adding randomly generated account number to each Account object

查看:109
本文介绍了向每个Account对象添加随机生成的帐号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿大家,



我是这些论坛的新手,我也只是在学习C#我正在努力学习这门语言。我只是试图通过项目来学习语言,但我遇到了一些问题。我是新来的,所以请不要通过煤炭耙我:(



我想创建一个创建随机帐号的银行帐户,使用面向对象的方法。



我正在尝试将随机生成的帐号添加到Account对象中,但我遇到了一些问题,我还没有''能够在网上找到任何解决方案。我知道那里有大量的资源,但是我仍然在尝试将所有资源拼凑在一起。



1)我想首先在我的班级中添加一个私有静态对象Random,我将其命名为Account - 从主程序中分离出类



2)然后我试图为我的帐户类创建一个随机数生成函数,您可以看到它被命名为random3digInt。它应该返回一个值,我不知道它是否需要参数。



3)在构造函数中,我想调用random3digInt函数,以便可以生成随机数并将其分配给帐号值 - 我猜测参数列表中的任何内容都是错误的





Hey everyone,

I''m new to these forums, and I''m also just learning C# I''m trying to learn the language. I''m just trying to learn the language by working on projects, but I''m running into some problems. I''m new here, so please don''t rake me through the coals :(

I want to make a bank account that creates random account numbers, using object oriented methods.

I''m trying to add randomly generated account numbers to Account objects, but I''m running into some problems, and I haven''t been able to find any solutions online. I know there''s tons of resources out there, but I''m still having issues trying to piece everything together.

1) I want to first add a private static object Random to my class, which I named "Account" - separate class from the main program

2) Then I tried to create a random number generating function to my "Account" class, which you can see is named "random3digInt". It should return a value, and I don''t really know if it needs parameters.

3) In the constructor, I want to call the random3digInt function so that random numbers can be generated and assigned to the account number value - I''m guessing whatever I have in the parameter list is wrong


class Account
  {
     const double DEFAULT_INTEREST = 2.5;
     private int accountNo; // accountNumber
     private double balance; // account balance
     private double interestRate; // percent annual interest rate
     private string message;
     private Random rg;





     public void random3digitInt() // add to the account class a random number generator function
         // that takes no parameters and returns and int value
     {
         int AccountNo;
         AccountNo = rg.Next(100, 999);
         return;
     }



      public Account(int acctNo, double bal, double ir)  // constructor

   {
     acctNo= Randorandom3digitInt();  // my attempt to call the random3digitInt() function


         message = ""; // empty message
        if (bal >= 0)
        {
           balance = bal;
        }
        else
        {







...没有复制所有代码





在我的主程序中,我有这个:(而且我知道这一切都非常错误)






... didn''t copy all the code


In my main program, I have this: (and I know it''s all very wrong)

static void Main(string[] args)


      {
         Account acct = new Account(acctNo,100,2.5); // account #1 with $100 and 2.5% annual rate

          acct.display();
         int choice;

         double bal, r, amt; // balance, annual rate, amount
         int y; // number of years
         double fut; // future value









谢谢!





Thanks!

推荐答案

年率100和2.5%

acct.display();
int choice;

double bal,r,amt; // 余额,年费率,金额
int y; // 年数
double fut; // 未来价值
100 and 2.5% annual rate acct.display(); int choice; double bal, r, amt; // balance, annual rate, amount int y; // number of years double fut; // future value









谢谢!





Thanks!


专注于随机...你没有把它变成静态的你没有初始化它。





当然还有很多东西可以在那里消失,但是从并告诉我们你想要纠正的错误或行为。
Concentrating on the Random... you didn''t make it static and you didn''t initialize it.


And of course there''s lots more to neaten up in there, but start with that and let us know what errors or behaviour you want to correct.








写下你的主要方法和构造函数如下:如果你想要AccountNo



hey


write yout main method and constructor like below: IF you want AccountNo

 public Account(int acctNo, double bal, double ir,out int accno)  // constructor

   {
       acctNo= Randorandom3digitInt();  // my attempt to call the random3digitInt() function

       accno=acctNo;    
      
   
         message = ""; // empty message
        if (bal >= 0)
        {
           balance = bal;
        }
        else
        {
}

//Main method

static void Main(string[] args)


      {
         int accno;  
         Account acct = new Account(acctNo,100,2.5,out accno); // account #1 with


这篇关于向每个Account对象添加随机生成的帐号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆