Question

In: Computer Science

Using python class: Design a class called Account CLASS NAME:    Account ATTRIBUTES: -nextAcctID: int    #NOTE-...

Using python class:

Design a class called Account

CLASS NAME:

   Account

ATTRIBUTES:

-nextAcctID: int    #NOTE- class-level attribute initialized to 1000

-acctID: int
-bank: String
-acctType: String (ex: checking, savings)
-balance: Float

METHODS:

<<Constructor>>Account(id:int, bank: String, type:String, bal:float)
+getAcctID(void): int                        NOTE: retrieving a CLASS-LEVEL attribute!
-setAcctID(newID: int): void           NOTE: PRIVATE method
+getBank(void): String
+setBank(newBank: String): void

+getBalance(void): float
+setBalance(newBal: float): void

+str(void): String

NOTE: Description: prints the information for the account one item per line. For example:
Account #:         100
Bank:                NorWest
Account Type:   Checking
Balance:           $150.98

+calcInterest(type):float
               NOTE: checking 1% get interest, savings get 2% interest. Updates balance!

Version 1 of the Account class: private data is a list that stores the account number, bank name, account type, and balance.

Version2 of the Account class: private data is stored as separate variables.

OPTIONAL BONUS + 5: Version 3 of the Account class: private data is stored as a tuple that stores the account number, bank name, account type, and balance.

Create a test program that works with all versions of the Account class, regardless of the way the private data was stored in the class.       LABEL all output, and be SURE to test EVERY method!

Suggestion:

Create separate modules for each of the different versions of the Account class.
Be sure that the class itself is always called Account in each of the modules – only the module name should change.Your testing should provide the SAME code for ALL versions, except that you’ll use a different import statement for each.

Solutions

Expert Solution

###### Account type-1 ####################
class Account:
nextAcctID=1000
def __init__(self, list,acctID, bank,acctType,balance):
self.list=list
self.list.append(acctID)
self.list.append(bank)
self.list.append(acctType)
self.list.append(balance)

def getAcctID(self):
return self.nextAcctID
def setAcctID(self,newID):
self.list[0]=newID
def getBank(self):
return self.list[1]
def setBank(self,newBank):
self.list[1]=newBank
def getBalance(self):
return self.list[3]
def setBalance(self,newBal):
self.list[3]=newBal
def str(self):
print("Account#: %d" %(self.list[0]))
print("Bank: %s" %(self.list[1]))
print("Account type: %s" %(self.list[2]))
print("Balance: $%.2f" %(self.list[3]))
def calcInterest(self):
if(self.list[2]=="checking"):
interest=self.list[3]*0.01
self.list[3]=self.list[3]+interest
if(self.list[2]=="savings"):
interest=self.list[3]*0.02
self.list[3]=self.list[3]+interest

list=[]
a1 = Account(list,100,"UTI","savings",300.5)
a1.str()
a1.calcInterest()
a1.str()
###### enf of Account type-1 ####################
  

###### Account type-2 ####################
class Account:
nextAcctID=1000
def __init__(self, acctID, bank,acctType,balance):
self.acctID=acctID
self.bank=bank
self.acctType=acctType
self.balance=balance
def getAcctID(self):
return self.nextAcctID
def setAcctID(self,newID):
self.acctID=newID
def getBank(self):
return self.bank
def setBank(self,newBank):
self.bank=newBank
def getBalance(self):
return self.balance
def setBalance(self,newBal):
self.balance=newBal
def str(self):
print("Account#: %d" %(self.acctID))
print("Bank: %s" %(self.bank))
print("Account type: %s" %(self.acctType))
print("Balance: $%.2f" %(self.balance))
def calcInterest(self):
if(self.acctType=="checking"):
interest=self.balance*0.01
self.balance=self.balance+interest
if(self.acctType=="savings"):
interest=self.balance*0.02
self.balance=self.balance+interest
  
a1 = Account(100,"UTI","savings",300.5)
a1.str()
a1.calcInterest()
a1.str()
###### end of Account type-2 ####################

###### Account type-3 ####################
class Account:
nextAcctID=1000
def __init__(self, record,acctID, bank,acctType,balance):
self.record=record
recordList=list(self.record)
recordList.append(acctID)
recordList.append(bank)
recordList.append(acctType)
recordList.append(balance)
self.record=tuple(recordList)

def getAcctID(self):
return self.nextAcctID
def setAcctID(self,newID):
recordList=list(self.record)
recordList[0]=newID
self.record=tuple(recordList)
def getBank(self):
return self.record[1]
def setBank(self,newBank):
recordList=list(self.record)
recordList[1]=newBank
self.record=tuple(recordList)
def getBalance(self):
return self.record[3]
def setBalance(self,newBal):
recordList=list(self.record)
recordList[3]=newBal
self.record=tuple(recordList)
def str(self):
print("Account#: %d" %(self.record[0]))
print("Bank: %s" %(self.record[1]))
print("Account type: %s" %(self.record[2]))
print("Balance: $%.2f" %(self.record[3]))
def calcInterest(self):
if(self.record[2]=="checking"):
interest=self.record[3]*0.01
recordList=list(self.record)
recordList[3]=recordList[3]+interest
self.record=tuple(recordList)
if(self.record[2]=="savings"):
interest=self.record[3]*0.02
recordList=list(self.record)
recordList[3]=recordList[3]+interest
self.record=tuple(recordList)

record=()
a1 = Account(record,100,"UTI","savings",3000.5)
a1.str()
a1.calcInterest()
a1.str()
## end of Account type-3 #####################
  


Related Solutions

Write a Python class to represent a Salik account. The account has three attributes, a name,...
Write a Python class to represent a Salik account. The account has three attributes, a name, id, and the balance. The balance is a private attribute. The class has extra functions to add to the balance and reduce the balance. Both, these functions should return the current balance and if the balance is below AED 50.0 print the message “Note: Balance Below 50”. Your class must work for the code given below. #Test myCar = SalikAccount() myCar.setName("John") myCar.setID("190300300333") myCar.setBal(20.0) yourCar...
1.   Design a class called BankAccount. The member fields of the class are: Account Name, Account...
1.   Design a class called BankAccount. The member fields of the class are: Account Name, Account Number and Account Balance. There are also other variables called MIN_BALANCE=9.99, REWARDS_AMOUNT=1000.00, REWARDS_RATE=0.04. They look like constants, but for now, they are variables of type double Here is the UML for the class:                                                         BankAccount -string accountName // First and Last name of Account holder -int accountNumber // integer -double accountBalance // current balance amount + BankAccount()                     //default constructor that sets name to “”,...
using Java Implement a class called Binomial_Coefficient o Your class has 2 int attributes, namely K...
using Java Implement a class called Binomial_Coefficient o Your class has 2 int attributes, namely K and n o Create an overloaded constructor to initialize the variables into any positive integers such that n > k > 0o Create a method that calculates the value of binomial coefficient, C(n,k) , using the following rule: ▪ For an array of size (n+1) X (k+1) ▪ Array [n][k] = Array[n-1][ k-1]+ Array[n-1] [k]▪ Array[n][0]= Array[n][n] = 1 ▪ Hence, C(n,k) = array...
7.3 (The Account class) Design a class named Account that contains: ■ A private int data...
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 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...
Please Code Using Java Create a class called SoccerPlayer Create 4 private attributes: First Name, Last...
Please Code Using Java Create a class called SoccerPlayer Create 4 private attributes: First Name, Last Name, Games, and Goals Have two constructors Constructor 1 – default constructor; all values to "NONE" or zero Constructor 2 – accepts input of first name, last name, games and goals. Create get and set methods for each of the four attributes Create a method the returns a double that calculates the average goals per game This method checks for zero games played: If...
Design and develop a class named Person in Python that contains two data attributes that stores...
Design and develop a class named Person in Python that contains two data attributes that stores the first name and last name of a person and appropriate accessor and mutator methods. Implement a method named __repr__ that outputs the details of a person. Then Design and develop a class named Student that is derived from Person, the __init__ for which should receive first name and last name from the class Person and also assigns values to student id, course, and...
Using Python Define a Student class. A Student class needs to have two attributes, the student_name...
Using Python Define a Student class. A Student class needs to have two attributes, the student_name and strudent_grade . It also has three methods as follows: set_grade(grade) that sets the grade of the student. get_grade returns the grade of the student. print_student_info that print the name and grade of student in a formatted string. In the math_utils.py file define a function called average_grade(roster) . This method accepts as input a list of Student Objects and returns the average of the...
Write a Class called Module with the following attributes: module code, module name, list of lecturers...
Write a Class called Module with the following attributes: module code, module name, list of lecturers for the module (some modules may have more than one lecturer – we only want to store their names), number of lecture hours, and module description. Create a parameterised (with parameters for all of the class attributes) and a non-parameterised constructor, and have the accessor and mutator methods for each attribute including a toString method. Write a class Student with the following attributes: student...
Java Create an abstract Product Class Add the following private attributes: name sku (int) price (double)...
Java Create an abstract Product Class Add the following private attributes: name sku (int) price (double) Create getter/setter methods for all attributes Create a constructor that takes in all attributes and sets them Remove the default constructor Override the toString() method and return a String that represents the building object that is formatted nicely and contains all information (attributes) Create a FoodProduct Class that extends Product Add the following private attributes: expDate (java.util.Date) for expiration date refrigerationTemp (int) if 70...
JAVA Program Create a class called SoccerPlayer Create 4 private attributes: First Name, Last Name, Games,...
JAVA Program Create a class called SoccerPlayer Create 4 private attributes: First Name, Last Name, Games, and Goals Have two constructors Constructor 1 – default constructor; all values to "NONE" or zero Constructor 2 – accepts input of first name, last name, games and goals. Create get and set methods for each of the four attributes Create a method the returns a double that calculates the average goals per game This method checks for zero games played: If there are...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT