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

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...
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...
This is python #Create a class called Rectangle. Rectangle should #have two attributes (instance variables): length...
This is python #Create a class called Rectangle. Rectangle should #have two attributes (instance variables): length and #width. Make sure the variable names match those words. #Both will be floats. # #Rectangle should have a constructor with two required #parameters, one for each of those attributes (length and #width, in that order). # #Rectangle should also have a method called #find_perimeter. find_perimeter should calculate the #perimeter of the rectangle based on the current values for #length and width. # #perimeter...
Design a class named Account that contains: A private int data field named id for the...
Design a class named Account that contains: A private int data field named id for the account. A private double data field named balance for the account. A private 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 annualInterestRate 0. The accessor and mutator methods for id, balance, and annualInterestRate. A method named getMonthlyInterestRate() that returns the monthly interest rate. A method named withdraw(amount)...
Write a class called Account that contains: • Three privateinstance variables: name (String), account (String),...
Write a class called Account that contains: • Three private instance variables: name (String), account (String), account balance (double). • One constructor, which constructs all instances with the values given. • Getters and setters for all the instance variables. • Debit function that takes an amount from the user and subtract the balance (make sure the balance will not drop below zero after the operation, if this was the case, the function should return false else it should return true)...
In c++ Design a class named Account that contains: a.An int data field named id for...
In c++ Design a class named Account that contains: a.An int data field named id for the account. b.A double data field named balancefor the account. c.A double data field named annualInterestRate that stores the current interestrate. d.A no-arg constructor that creates a default account with id 0, balance 0, andannualInterestRate 0. e.The set and get functions for id,balance, and annualInterestRate. f.A functionearnedAmount()that calculates and returns the amount of dollars earned after one year. g.A function named printAccountInfo() that print...
Using Python 3, Write a class called GolfScore that keeps track of the score for a...
Using Python 3, Write a class called GolfScore that keeps track of the score for a person playing a round of golf. We will limit the round to 9 holes, just to make testing easier. As a reminder, the holes on the golf course are numbered 1 – 9. Create a class level variable named NUM_OF_HOLES set to 9. Methods to be written: The constructor – sets the score for all holes to -1 addScore (hole, score) – this method...
Consider the following class: class Person {         String name;         int age;        ...
Consider the following class: class Person {         String name;         int age;         Person(String name, int age){                this.name = name;                this.age = age;         } } Write a java program with two classes “Teacher” and “Student” that inherit the above class “Person”. Each class has three components: extra variable, constructor, and a method to print the student or the teacher info. The output may look like the following (Hint: you may need to use “super”...
In python- Create a class defined for Regression. Class attributes are data points for x, y,...
In python- Create a class defined for Regression. Class attributes are data points for x, y, the slope and the intercept for the regression line. Define an instance method to find the regression line parameters (slope and intercept). Plot all data points on the graph. Plot the regression line on the same plot.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT