Skip to content
The Chat Archive
gpt-3.5-turbo-0613· OpenAIAi2 WildChat-4.8M (AI2)

The object of the class Account represents a bank account that has a balance (meaning…

  1. User

    The object of the class Account represents a bank account that has a balance (meaning some amount of money). The accounts are used as follows:

    Account bartosAccount = new Account("Barto's account",100.00); Account bartosSwissAccount = new Account("Barto's account in Switzerland",1000000.00);

    Console.WriteLine("Initial state"); Console.WriteLine(bartosAccount); Console.WriteLine(bartosSwissAccount);

    bartosAccount.withdrawal(20); Console.WriteLine("Barto's account balance is now: "+bartosAccount.balance()); bartosSwissAccount.deposit(200); Console.WriteLine("Barto's Swiss account balance is now: "+bartosSwissAccount.balance());

    Console.WriteLine("Final state"); Console.WriteLine(bartosAccount); Console.WriteLine(bartosSwissAccount); Your first account Create a program that creates an account with the balance of 100.0, deposits 20.0 and prints the account.

    Note! do all the steps described in the exercise exactly in the described order!

    Your first money transfer Create a program that:

    Creates an account named "Matt's account" with the balance of 1000 Creates an account named "My account" with the balance of 0 Withdraws 100.0 from Matt's account Deposits 100.0 to My account Prints both accounts Money transfers In the above program, you made a money transfer from one person to another. Let us next create a method that does the same!

    Create the method:

    public static void Transfer(Account from, Account to, double howMuch) The method transfers money from one account to another. You do not need to check that the from account has enough balance.

    After completing the above, make sure that your main method does the following:

    Creates an account "A" with the balance of 100.0 Creates an account "B" with the balance of 0.0 Creates an account "C" with the balance of 0.0 Transfers 50.0 from account A to account B Transfers 25.0 from account B to account C Please solve with C# code.

  2. Assistant

    using System;

    class Account { private string name; private double balance;

    public Account(string name, double balance)
    {
        this.name = name;
        this.balance = balance;
    }
    
    public void withdrawal(double amount)
    {
        this.balance -= amount;
    }
    
    public void deposit(double amount)
    {
        this.balance += amount;
    }
    
    public double getBalance()
    {
        return this.balance;
    }
    
    public override string ToString()
    {
        return this.name + " balance: " + this.balance;
    }
    
    public static void Transfer(Account from, Account to, double howMuch)
    {
        from.withdrawal(howMuch);
        to.deposit(howMuch);
    }
    

    }

    class Program { static void Main(string[] args) { // Your first account Account account = new Account("A", 100.0); account.deposit(20.0); Console.WriteLine(account);

        // Your first money transfer
        Account mattsAccount = new Account("Matt's account", 1000);
        Account myAccount = new Account("My account", 0);
        mattsAccount.withdrawal(100);
        myAccount.deposit(100);
        Console.WriteLine(mattsAccount);
        Console.WriteLine(myAccount);
    
        // Money transfers
        Account accountA = new Account("A", 100);
        Account accountB = new Account("B", 0);
        Account accountC = new Account("C", 0);
    
        Account.Transfer(accountA, accountB, 50);
        Account.Transfer(accountB, accountC, 25);
    
        Console.WriteLine(accountA);
        Console.WriteLine(accountB);
        Console.WriteLine(accountC);
    }
    

    }