Skip to content
TheChatArchiveThe Chat Archive
gpt-4-0314· OpenAIAi2 WildChat-4.8M (AI2)

Create a class 'Account' in which all the fields are declared private Attributes are as…

  1. User

    Create a class 'Account' in which all the fields are declared private

    Attributes are as follows:

    int accountnumber; int accountbalance;

    Get n user details and store them in the private variables. The account number which the deposit must be made is then read. If an account number already exists print the account balance; otherwise, display "Account Number Does Not Exist Note:

    Use public set and get to set and read the value of the attributes The initial value of account_balance is zero.

    Input format

    The first integer input represents n number of users. Each user's account number and initial deposit amount are represented by the nee

    n entries.

    The last integer input represents the account number for which the balance nee to be displayed.

    Output format

    Display the balance for the given account number. Refer sample output Output format

    Display the balance for the given account number. Refer sample output

    Sample testcases

    Input 1

    Output 1

    2

    40000

    1111

    40000

    1112

    45000

    1111 Input 2

    2

    Output 2

    Account Number does not e

    esc

    1111 40000 1112 45000 1113 code in c#

  2. Assistant
    using System;
    using System.Collections.Generic;
    
    class Account
    {
        private int accountNumber;
        private int accountBalance;
    
        public int AccountNumber
        {
            get { return accountNumber; }
            set { accountNumber = value; }
        }
    
        public int AccountBalance
        {
            get { return accountBalance; }
            set { accountBalance = value; }
        }
    }
    
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            List<Account> accounts = new List<Account>();
    
            for (int i = 0; i < n; i++)
            {
                Account account = new Account();
                account.AccountNumber = int.Parse(Console.ReadLine());
                account.AccountBalance = int.Parse(Console.ReadLine());
                accounts.Add(account);
            }
    
            int searchAccountNum = int.Parse(Console.ReadLine());
            bool accountExists = false;
    
            foreach (Account account in accounts)
            {
                if (account.AccountNumber == searchAccountNum)
                {
                    accountExists = true;
                    Console.WriteLine(account.AccountBalance);
                    break;
                }
            }
    
            if (!accountExists)
            {
                Console.WriteLine("Account Number Does Not Exist");
            }
        }
    }
    

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.