Question

In: Computer Science

NEED TO BE IN PYTHON!!! Make sure to put the main section of your code in...

NEED TO BE IN PYTHON!!!

Make sure to put the main section of your code in the following if block:

# Type code for classes here

if __name__ == "__main__":

# Type main section of code here

(1) Build the Account class with the following specifications:

Attributes

  • name (str)
  • account_number (int)
  • balance (float)

Create a constructor that has 3 parameters (in addition to self) that will be passed in from the user. (no default values)

Define a __str__() method to print an Account like the following

Account Name: Trish Duce

Account Number: 90453889

Account Balance: $100.00

Define a deposit() method that has 1 parameter (in addition to self) that will be passed in from the user. (no default values) The method deposits the specified amount in the account.

Define a withdraw() method that has 2 parameters (in addition to self) that will be passed in from the user. (no default values) The method withdraws the specified amount (1st parameter) and fee (2nd parameter) from the account.

(2) In the main section of your code, create 3 accounts.

  • Trish Duce 90453889 100
  • Donald Duck 83504837 100
  • Joe Smith 74773321 100

(3) Print the 3 accounts using print(acct1)…

(4) Deposit 25.85, 75.50 and 50 into accounts 1, 2 and 3.

(5) Print the 3 accounts.

(6) Withdraw 25.85 (2.50 fee), 75.50 (1.50 fee), 50.00 (2.00 fee).

(7) Print the 3 accounts.

Output should look like the following:

Account Name: Trish Duce

Account Number: 90453889

Account Balance: $100.00

Account Name: Donald Duck

Account Number: 83504837

Account Balance: $100.00

Account Name: Joe Smith

Account Number: 74773321

Account Balance: $100.00

Account Name: Trish Duce

Account Number: 90453889

Account Balance: $125.85

Account Name: Donald Duck

Account Number: 83504837

Account Balance: $175.50

Account Name: Joe Smith

Account Number: 74773321

Account Balance: $150.00

Account Name: Trish Duce

Account Number: 90453889

Account Balance: $97.50

Account Name: Donald Duck

Account Number: 83504837

Account Balance: $98.50

Account Name: Joe Smith

Account Number: 74773321

Account Balance: $98.00

Solutions

Expert Solution

Answer:

class BankAccount:
    #constructor with 3 parameters for account name,number and balance
    def __init__(self, name,number,balance):
        self.name = name
        self.number=number
        self.balance = balance

    #function to deposit an amount
    def deposit(self, amount):
        """make a deposit"""
        self.balance += amount

    #function to withdraw the amount with small fee deduction
    def withdraw(self, amount,fee):
        """make a withdraw"""
        if amount > self.balance:
            raise ValueError("Insufficient funds")
        self.balance -= amount
        self.balance -= fee

    def get_accname(self):
        return self.name

    def get_accnumber(self):
        return self.number

    def get_accbalance(self):
        """check the balance"""
        return self._balance


    #__str__ prints the statement to console a string
    def __str__(self):
        return 'Account Name: {} \nAccount Number: {} \nAccount Balance: ${:,.2f}'.format(self.name,self.number,self.balance)


if __name__ == "__main__":

    #create 3 accounts and print them
    acct1=BankAccount('Trish Duce', 90453889, 100)
    print(acct1)
    acct2 = BankAccount('Donald Duck', 83504837, 100)
    print(acct2)
    acct3 = BankAccount('Joe Smith', 74773321, 100)
    print(acct3)

    #deposit to 3 accounts
    acct1.deposit(25.85)
    acct2.deposit(75.50)
    acct3.deposit(50)

    #print the 3 accounts
    print(acct1)
    print(acct2)
    print(acct3)

    #withdraw from the 3 accounts
    acct1.withdraw(25.85,2.50)
    acct2.withdraw(75.50,1.50)
    acct3.withdraw(50,2.00)

    # print the 3 accounts
    print(acct1)
    print(acct2)
    print(acct3)

Output:


Related Solutions

****C++, put both of them in to one main method, make sure to start with main...
****C++, put both of them in to one main method, make sure to start with main class, if I get a screenshot of the output as well. thank you (1) A palindrome is a string that reads the same forwards as backwards. Using only a fixed number of stacks and queues, the stack and queue ADT functions, and a fixed number of int and char variables, write an algorithm to determine if a string is a palindrome. Assume that the...
****C++, put both of them in to one main method, make sure to start with main...
****C++, put both of them in to one main method, make sure to start with main class, if I get a screenshot of the output as well. thank you (3) Use singly linked lists to implement integers of unlimited size. Each node of the list should store one digit of the integer. You should implement addition, subtraction, multiplication, and exponentiation operations. Limit exponents to be positive integers. What is the asymptotic running time for each of your operations, expressed in...
* Make sure you turn in your code (take a screen shot of your code in...
* Make sure you turn in your code (take a screen shot of your code in R)and answers. Conduct the hypothesis and solve questions by using R. 2) A random sample of 12 graduates of a secretarial school averaged 73.2 words per minute with a standard deviation of 7.9 words per minute on a typing test. What can we conclude, at the .05 level, regarding the claim that secretaries at this school average less than 75 words per minute on...
convert this code to Python and make sure you use chained map and filter as well....
convert this code to Python and make sure you use chained map and filter as well. https://book.pythontips.com/en/latest/map_filter.html CODE BELOW IS IN JAVASCRIPT let people = [ {name: "Amy", pounds_weight: 152, inches_height: 63}, {name: "Joe", pounds_weight: 120, inches_height: 64}, {name: "Tom", pounds_weight: 210, inches_height: 78}, {name: "Jim", pounds_weight: 180, inches_height: 68}, {name: "Jen", pounds_weight: 120, inches_height: 62}, {name: "Ann", pounds_weight: 252, inches_height: 63}, {name: "Ben", pounds_weight: 240, inches_height: 72}, ]; //functions to convert pounds to kg and inches to meters let...
I need this Java code transform to Python Code PROGRAM: import java.util.Scanner; public class Main {...
I need this Java code transform to Python Code PROGRAM: import java.util.Scanner; public class Main { static int count=0; int calculate(int row, int column) { count++; if(row==1&&column==1) { return 0; } else if(column==1) { return ((200+calculate(row-1,column))/2); } else if(column==row) { return (200+calculate(row-1,column-1))/2; } else { return ((200+calculate(row-1,column-1))/2)+((200+calculate(row-1,column))/2); }    } public static void main(String[] args) { int row,column,weight; Main m=new Main(); System.out.println("Welcome to the Human pyramid. Select a row column combination and i will tell you how much weight the...
Complete the code to make the following main work public class Time { **put the solution...
Complete the code to make the following main work public class Time { **put the solution here** public static void main(String[] args){ Time a = new Time(15,10,30); Time b = new Time(); // default to 15:00:00(the start time of our class!) System.out.println(a); // should print out: 15:10:30 System.out.println(b); // should print out: System.out.println(a.dist(b)); // print the difference in seconds between the two timestamps } }
Make a menu for a restaurant using python. Make sure there are choices on the menu....
Make a menu for a restaurant using python. Make sure there are choices on the menu. Give me a little description of how you did it.
this is a python code that i need to covert to C++ code...is this possible? if...
this is a python code that i need to covert to C++ code...is this possible? if so, can you please convert this pythin code to C++? def main(): endProgram = 'no' print while endProgram == 'no': print # declare variables notGreenCost = [0] * 12 goneGreenCost = [0] * 12 savings = [0] * 12 months = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'] getNotGreen(notGreenCost, months) getGoneGreen(goneGreenCost, months) energySaved(notGreenCost, goneGreenCost, savings) displayInfo(notGreenCost, goneGreenCost, savings, months)...
Java Code - Please explain each step through comments. Also, make sure Main (P3_13) is separate...
Java Code - Please explain each step through comments. Also, make sure Main (P3_13) is separate from your class BetterRectangle. Lastly, post a picture of your code inside an IDE along with your output. My code is below, needs modification. E9.13The java.awt.Rectangle class of the standard Java library does not supply a method to compute the area or perimeter of a rectangle. Provide a subclass BetterRectangle ofthe Rectangle class that has getPerimeter and getArea methods. Do not add any instance...
In python make a simple code. You are writing a code for a program that converts...
In python make a simple code. You are writing a code for a program that converts Celsius and Fahrenheit degrees together. The program should first ask the user in which unit they are entering the temperature degree (c or C for Celcius, and f or F for Fahrenheit). Then it should ask for the temperature and call the proper function to do the conversion and display the result in another unit. It should display the result with a proper message....
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT