Question

In: Computer Science

Chapter 7, Problem 3PE from Introduction to Programming using Python by Y. Daniel Liang. Problem (The...

Chapter 7, Problem 3PE from Introduction to Programming using Python by Y. Daniel Liang.

Problem

(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 balance for the account.

■ A private float data field named annualInterestRate that stores the current interest rate.

■ A constructor 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 annualInterestRate.

■ A method named getMonthlyInterestRate() that returns the monthly interest rate.

■ A method named getMonthlyInterest() that returns the monthly interest.

■ A method named withdraw that withdraws a specified amount from the account.

■ A method named deposit that deposits a specified amount 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 annualInterestRate 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.

Solutions

Expert Solution

#CODE FOR THE PROBLEM

class Account:

    __id=None

    __balance=None

    __annualInterestRate=None

    def __init__(self, id=0, balance=100, interest=0):

        self.__id=id

        self.__balance=balance

        self.__annualInterestRate=interest

    def getID(self):

        return self.__id

    def setID(self, id):

        self.__id=id

    def getBalance(self):

        return self.__balance

    def setBalance(self, balance):

        self.__balance=balance

    def getAnnualInterestRate(self):

        return self.__annualInterestRate

    def setAnnualInterestRate(self, interest):

        self.__annualInterestRate=interest

    

    def getMonthlyInterestRate(self):

        return self.__annualInterestRate/12

    def getMonthlyInterest(self):

        return (self.__balance*self.__annualInterestRate)/1200

    def withdraw(self, amount):

        if(self.__balance>=amount):

            self.__balance-=amount

            print("Successfully Withdrawn")

        else:

            print("Insufficient Balance")

    def deposit(self, amount):

        self.__balance+=amount

    

#following codes are to test the working of the class

account = Account(1122, 20000, 4.5)

x = account.getID()

print("ID is "+str(x))

account.setID(1155)

x = account.getID()

print("Updated ID is "+ str(x))

x = account.getBalance()

print("Balance is $"+ str(x))

x = account.setBalance(15000)

x = account.getBalance()

print("Updated Balance is $"+ str(x))

x = account.getAnnualInterestRate()

print("Annual Interest Rate is "+ str(x))

x = account.setAnnualInterestRate(6)

x = account.getAnnualInterestRate()

print("Updated Annual Interest Rate is "+ str(x))

x = account.getMonthlyInterestRate()

print("Monthly Interest Rate is "+str(x))

x = account.getMonthlyInterest()

print("Monthly Interest is "+str(x))

account.withdraw(5000)

x=account.getBalance()

print("New balance after withdrawing 5000 is "+str(x))

account.deposit(2000)

x=account.getBalance()

print("New balance after depositing 2000 is "+str(x))

# IF YOU GET INDENTATION ERROR, CHECK THE ATTACHED IMAGE


Related Solutions

Introduction to Programming with C++ Third Edition. Y. Daniel Liang Phone Key Pads:Write a program for...
Introduction to Programming with C++ Third Edition. Y. Daniel Liang Phone Key Pads:Write a program for Programming Exercise 4.15 on p.152 in the textbook. Testing: Run the program for: o The first three letters in your last name (all lowercase) o The first three letters in your first name (all uppercase) o Three invalid characters use an old phone with 2 abc 3 def 4 ghi
Explanation of the problem chapter 3.12 problem 49 of the book introduction to the mathematical programming...
Explanation of the problem chapter 3.12 problem 49 of the book introduction to the mathematical programming 4th edition Solution: Step # 1 Let Xij be the amount of money invested at the beginning of month i, for a period of j month. Objective function: Step # 2 The objective is to maximize the available cash at the beginning of month 5. X14 = collect the money invested at the beginning of month 1 of 4 months. X23 = collect the...
Chapter 2, Problem 4E in An Introduction to Programming with C++ All of the employees at...
Chapter 2, Problem 4E in An Introduction to Programming with C++ All of the employees at Merks Sales are paid based on an annual salary rather than an hourly wage. However, some employees are paid weekly while others are paid every other week (biweekly). Weekly employees receive 52 paychecks; biweekly employees receive 26 paychecks. The payroll manager wants a program that displays two amounts: an employee’s weekly gross pay and his or her biweekly gross pay. Complete an IPO chart...
Case Problem 2 Chapter 7 Introduction to Linear Programming Production Strategy Production Strategy Better Fitness, Inc....
Case Problem 2 Chapter 7 Introduction to Linear Programming Production Strategy Production Strategy Better Fitness, Inc. (BFI) manufactures exercise equipment at its plant in Freeport, Long Island. It recently designed two universal weight machines for the home exercise market. Both machines use BFI-patented technology that provides the user with an extremely wide range of motion capability for each type of exercise performed. Until now, such capabilities have been available only on expensive weight machines used primarily by physical therapists. At...
I am working on exercise 5.48 from Introduction to Computing using python (Author: Perkovic). Problem Question:...
I am working on exercise 5.48 from Introduction to Computing using python (Author: Perkovic). Problem Question: Let list1 and list2 be two lists of integers. We say that list1 is a sublist of list2 if the elements in list1 appear in list 2 in the same order as they appear in list1, but not necessarily consecutively. For ex, if list1 is defined as [15,1,100] and list2 is defined as [20,15,30,50,1,100]. Then list 1 is a sublist of list 2 because...
1. INTRODUCTION The goal of this programming assignment is for students to write a Python program...
1. INTRODUCTION The goal of this programming assignment is for students to write a Python program that uses repetition (i.e. “loops”) and decision structures to solve a problem. 2. PROBLEM DEFINITION  Write a Python program that performs simple math operations. It will present the user with a menu and prompt the user for an option to be selected, such as: (1) addition (2) subtraction (3) multiplication (4) division (5) quit Please select an option (1 – 5) from the...
This problem is adapted from Exercise 37 of Langtangen’s “A Primer on Scientific Programming with Python”....
This problem is adapted from Exercise 37 of Langtangen’s “A Primer on Scientific Programming with Python”. Simulating gas particles in a closed space is something you can do with a Monte Carlo type simulation – simulate a period of time (using a loop) and “move” particles around (change values for (x,y) coordinates) for each unit of time. This kind of simulation is called a “random walk”. Download the file randomwalk.py(i posted it below). This implements a Monte Carlo simulation for...
Using Python Programming PROBLEM 3 - OLD MACDONALD: Write a program to print the lyrics of...
Using Python Programming PROBLEM 3 - OLD MACDONALD: Write a program to print the lyrics of the song ”Old MacDonald”. Your program should print the lyrics using five different animals (i.e., cow, sheep, dog, cat ,turkey) using the example verse below. For this problem you are required to write then make use of a function getVerse that takes two string parameters: (1) the name of an animal and (2) the sound that animal makes. The function should not print anything...
Implement the Producer-Consumer Problem programming assignment at the end of Chapter 5 in the textbook using...
Implement the Producer-Consumer Problem programming assignment at the end of Chapter 5 in the textbook using the programming language Java instead of the described C code. You must use Java with Threads instead of Pthreads.A brief overview is below. This program should work as follows: The user will enter on the command line the sleep time, number of producer threads, and the number of consumer threads. One example of the Java application from the command line could be “java ProducerConsumer...
Python programming problem! Suppose that there is a json file called data from the desktop. I...
Python programming problem! Suppose that there is a json file called data from the desktop. I want to print the value with the key of "year" and "country". Json file below: { "A":{ "year":11, "grade":A, "country":America}, "B":{ "year":18, "grade":C, "country":England}, "C":{ "year":19, "grade":B, "country":China},} I want a code that I can only replace the name of key from year to grade and the code could be work.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT