Question

New to python if you can add screenshort also, i am using python 3

7.3 (The Account class) Design a class named Account that contains A private int data field named id for the account. A private float data field named annualInterestRate that stores the current A constructor that creates an account with the specified id (default 0), initial The accessor and mutator methods for id, balance, and annualInterestRate A private float data field named balance for the account. interest rate. balance (default 100), and annual interest rate (default 0) A method named getMonthlyInterestRateO that returns the monthly interest rate. A method named getMonthlyInterestO that returns the monthly interest. A method named withdraw that withdraws a specified amount from the account. ·A rnethod named deposit that deposits a specified annount to the account. Draw the UML diagram for the class, and then implement the class. (Hint: The method getMonthlyInterest is to return the monthly interest amount, not the interest rate. Use this formula to calculate the monthly interest: balance* monthlyInterestRate. monthlyInterestRate is annualInterestRate 12. Note that annual InterestRate is a percent (like 4.5%). You need to divide it by 100.) Write a test program that creates an Account object with an account id of 1122, a balance of $20,000, and an annual interest rate of 4.5%. Use the withdraw method to withdraw $2,500, use the deposit method to deposit $3,000, and print the id, balance, monthly interest rate, and monthly interest.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

UML Diagram:

Account -id: int balance: float -annualInterestRate: float init-. (id=0.bal-100.intRate = 0) +getId0: int +setId(int): void +

Python Program:

class Account:
   """ Account class """
  
   def __init__(self, id=0, bal=100, intRate=0):
       """ Default Constructor """
       self._id = id;
       self._bal = bal;
       self._intRate = intRate;
      
   def setId(self, id):
       """ Setter method for id """
       self._id = id;
  
   def getId(self):
       """ Getter method for id """
       return self._id;
      
   def setBal(self, bal):
       """ Setter method for balance """
       self._bal = bal;
  
   def getBal(self):
       """ Getter method for balance """
       return self._bal;
      
   def setIntRate(self, intRate):
       """ Setter method for interest rate """
       self._intRate = intRate;
  
   def getIntRate(self):
       """ Getter method for interest rate """
       return self._intRate;
      
   def getMonthlyInterestRate(self):
       """ Calculates monthly interest rate """
       return (self._intRate / 12)
      
   def getMonthlyInterest(self):
       """ Calculates monthly interest """
       return (self._bal * (self.getMonthlyInterestRate()/100))
  
   def withdraw(self, amt):
       """ Withdraw amount """
       if self._bal < amt:
           print("\n Insufficient funds.. \n");
       else:
           # Updating balance
           self._bal = self._bal - amt;
          
   def deposit(self, amt):
       """ Deposit amount """
       # Updating balance
       self._bal = self._bal + amt;
          
  

""" Test Program """  
# Testing account class
acc = Account(1122, 20000, 4.5)
acc.withdraw(2500)
acc.deposit(3000)

#Printing results
print("\n\n ID: " + str(acc.getId()))
print("\n Balance: $" + str(acc.getBal()))
print("\n Monthly Interest Rate: $" + str(acc.getMonthlyInterestRate()))
print("\n Monthly Interest: $" + str(acc.getMonthlyInterest()) + " \n")

______________________________________________________________________________________________

Code Screenshot:

AccountFile.py-DAPythonAccountFile ·(3.5 File Edit Format Run Options Window Help lass Account: Account class def -init--(sel

def withdraw (self, amt): Withdraw amount if self ..bal < amt: print(n Insufficient funds.. n) else: # Updating balance s

__________________________________________________________________________________________

Sample Run:

Python 35.2 Shell File Edit Shell Debug Options Window Help Python 3.5.2 (v3.5.2:4def2a2901a5, Jun 25 2016, 22:18:55) [MSC v.

Add a comment
Know the answer?
Add Answer to:
New to python if you can add screenshort also, i am using python 3 7.3 (The...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • 9.7 (The Account class) Design a class named Account that contains: • A private int data...

    9.7 (The Account class) Design a class named Account that contains: • A private int data field named id for the account (default o). • A private double data field named balance for the account (default o). • A private double data field named annualInterestRate that stores the current interest rate (default o). Assume that all accounts have the same interest rate. • A private Date data field named dateCreated that stores the date when the account was created. •...

  • PYTHON PROGRAMMING LANGUAGE Design a class named Savings Account that contains: A private int data field...

    PYTHON PROGRAMMING LANGUAGE Design a class named Savings Account that contains: A private int data field named id for the savings account. A private float data field named balance for the savings account. A private float data field named annuallnterestRate that stores the current interest rate. A_init_ that creates an account with the specified id (default 0), initial balance (default 100), and annual interest rate (default 0). . The accessor and mutator methods for id, balance, and annuallnterestRate. A method...

  • (The Account class) Design a class named Account that contains: A private int data field named...

    (The Account class) Design a class named Account that contains: A private int data field named id for the account (default 0). A private double data field named balance for the account (default 0). A private double data field named annualInterestRate that stores the current interest rate (default 0). Assume all accounts have the same interest rate. A private Date data field named dateCreated that stores the date when the account was created. A no-arg constructor that creates a default...

  • Design a class that contains: we have to make 3 files header file , one .cpp...

    Design a class that contains: we have to make 3 files header file , one .cpp file for function and one more main cpp file 9.3 (The Account class) Design a class named Account that contains: An int data field named id for the account. A double data field named balance for the account. A double data field named annualInterestRate that stores the current interest rate. A no-arg constructor that creates a default account with id 0, balance 0, and...

  • Design a class named BankAccount that contains: 1. A private int data field named accountId for...

    Design a class named BankAccount that contains: 1. A private int data field named accountId for the account. 2. A private double data field named accountBalance for the account (default 0). 3. A private double data field named annualInterestRate that stores the current interest rate (default 0). Assume all accounts have the same interest rate. 4. A private Date data field named dateCreated that stores the date when the account was created. 5. A private int data field named numberOfDeposits...

  • Consider the following Account class and main function: class Account: acct_num=1000 #Constructor for Account class (default...

    Consider the following Account class and main function: class Account: acct_num=1000 #Constructor for Account class (default values for balance #and annual interest rate are 100 and e, respectively). #INITIALIZER METHOD HEADER GOES HERE #MISSING CODE def getId(self): return self._id def getBalance(self): #MISSING CODE def getAnnualInterestRate(self): return self.___annualInterestRate def setBalance(self, balance): self. balance - balance def setAnnualInterestRate(self,rate): #MISSING CODE def getMonthlyInterestRate(self): return self. annualInterestRate/12 def getMonthlyInterest (self): #MISSING CODE def withdraw(self, amount): #MISSING CODE det getAnnualInterestRate(self): return self. annualInterestRate def setBalance(self,...

  • Unable to find out why am I getting: Account.java:85: error: reached end of file while parsing...

    Unable to find out why am I getting: Account.java:85: error: reached end of file while parsing import java.util.*; class Account{ private int id; private double balance; private double annualInterestRate; private Date dateCreated; public Account() { id = 0; balance = 0; annualInterestRate = 0; dateCreated = new Date(); } public Account(int id1, double balance1) { id =id1; balance = balance1; dateCreated = new Date(); } public void setId(int id1) { id=id1; } public void setBalance(double balance1) { balance = balance1;...

  • The code is attached below has the Account class that was designed to model a bank account.

    IN JAVAThe code is attached below has the Account class that was designed to model a bank account. An account has the properties account number, balance, annual interest rate, and date created, and methods to deposit and withdraw funds. I need creat program using the 2 java programs.Create two subclasses for checking and savings accounts. A checking account has an overdraft limit, but a savings account cannot be overdrawn.I need to write a test program that creates objects of Account,...

  • Hello, I'm very new to programming and I'm running into a problem with the system.out.println function...

    Hello, I'm very new to programming and I'm running into a problem with the system.out.println function in the TestAccount Class pasted below. Account Class: import java.util.Date; public class Account {    private int accountId;    private double accountBalance, annualInterestRate;    private Date dateCreated;    public Account(int id, double balance) { id = accountId;        balance = accountBalance; dateCreated = new Date();    }    public Account() { dateCreated = new Date();    }    public int getId() { return...

  • THE FOLLOWING PROGRAM IS NEEDED IN JAVA LANGUAGE Design a class torepresent account, include the following...

    THE FOLLOWING PROGRAM IS NEEDED IN JAVA LANGUAGE Design a class torepresent account, include the following members: -Data Members a)Name of depositor-Stringb)Account Number –intc)Type of account –Boolean d)Balance amount -doublee)AnnualInterestrate -double Methods: -(a)To assign initial values (use constructor)(b)To deposit an amount.(c)TO withdraw amount with the restriction the minimum balance is 50 rs. Ifyouwithdraw amount reduced the balance below 50 then print the error message.(d)Display the name and balance of the account.(e)Get_Monthly_intrestRate() -Return the monthly interestrate whichis nothing but Annualintrestrate/12. Annualinterestrate...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT