Question

Please use python Programming Language: Select one of the following topics: Band Character Account Create a...

Please use python Programming Language:

Select one of the following topics:

  • Band
  • Character
  • Account

Create a class based on your chosen topic. Make sure to include at least four attributes of varying types, a constructor, getters/setters for each attribute w/input validation, a toString, a static attribute, and a static method.

Then, create a function (outside of your class) that connects to a text file which should contain the attributes of several objects. Read the data from the file, use the data to instantiate your objects, then return them in a list.  

In main(), call your function and demonstrate some methods of object from the returned list.

Note: Please use python Programming Language.

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

Python Program:

class Account:
   """ Account class """
   # Static variable
   bank = 'ABC Corporation'
   def __init__(self, id=0, name="", bal=100, intRate=0):
       """ Default Constructor """
       self._id = id;
       self._name = name;
       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 setName(self, name):
       """ Setter method for name """
       self._name = name;
  
   def getName(self):
       """ Getter method for name """
       return self._name;
  
   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 __str__(self):
       """ Overriding toString method """
       return ("ID: " + str(self._id) + "\nName: " + self._name + "\nBalance: " + str(self._bal) + "\nInterest Rate: " + str(self._intRate))
      
   @staticmethod
   def getBank():
       return Account.bank  
      
      
      
# Main function that creates objects from text file
def main():
   accObjs = []
   # Opening file for reading
   with open("d:\\Python\\acc.txt") as fp:
       # Iterating over line by line
       for line in fp:
           cols = line.strip().split()
           # Creating account object
           aObj = Account(int(cols[0]), cols[1], float(cols[2]), float(cols[3]))
           # Adding to list
           accObjs.append(aObj)
              
   print("\nBank Name: " + Account.getBank() + "\n\n")
   # Printing objects
   for aObj in accObjs:
       print(aObj)
       print("\n")


# Main function calling
main()      

________________________________________________________________________________________________

Sample Run:

Input File: acc.txt

8073 Nicholas 23750.0 6.2
245 Paul 1236.5 7.5
3381 Tom 1427.8 12.0
2813 Nate 1885.0 4.7

Add a comment
Know the answer?
Add Answer to:
Please use python Programming Language: Select one of the following topics: Band Character Account Create a...
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
  • can you please solve #2, 3 and 4 ? please by using Python 3 8:34 PM...

    can you please solve #2, 3 and 4 ? please by using Python 3 8:34 PM € Assignment Details 6202-COSC-2436-Programming Fundamentals i company TOITOWS: Ask the customer have his into G unter his own . If you SOLO u ld email. If Ask hinto anto TV unit l emname, .). Append the total Hoe to his 2. Create a class called person with name, phone and email as private attributes. Create a customer class as a sub class of person...

  • GUI programming

    Please use netBeans Exercise 4:A librarian needs to keep track of the books he has in his Library.1. Create a class Book that has the following attributes: ISBN, Title, Author, Subject, and Price. Choose anappropriate type for each attribute.2. Add a static member BookCount to the class Book and initialize it to zero.3. Add a default constructor for the class Book. Increment the BookCount static member variable and an initialization constructor for the class Book. Increment the BookCount in all constructors.4....

  • Python programming I need help with the following: Create a class Vehicle. The class should have...

    Python programming I need help with the following: Create a class Vehicle. The class should have name, weight, fuel, number of wheels and move attributes/methods. Create child class that are semi, car, sail boat and bicycle. Give the class the ability to have a constructor that sets the name. Have the other attributes hard coded to suit the vehicle. Give each a way of speaking their attributes as well as the type of animal. For example “Hi I am Lightening...

  • using CSCI300 java Given the following UML Class Diagram Club_Card # card_num : String # name...

    using CSCI300 java Given the following UML Class Diagram Club_Card # card_num : String # name : String # age: int # year: int + Club_Card (all parameters) + Setters & Getters + toString() : String + equals(x: Object): boolean [10 pts] Define the class Club_Card, which contains: 1. All arguments constructor which accepts all required arguments from the main and instantiate a Club_Card object. 2. Set & get method for each data attribute. 3. A toString() method which returns...

  • Project Lists and Object-oriented Programming Note: using c++ This project is an individual assignment that focuses...

    Project Lists and Object-oriented Programming Note: using c++ This project is an individual assignment that focuses on object-oriented programming and lists. The list will be a doubly-linked list and it will be implemented using nodes and pointers. The data contained in the list will be objects from a class. Project data: You will choose one of the following classes to define: Boat, Earthquake, Game, Sport, State, Website, House, Phone, Activist, Plant, Fish, Parrot, and Course. Your class code will include...

  • please use basic programming language and explain with comment lines .for Thonny(python) format. Duplicate elimination Create...

    please use basic programming language and explain with comment lines .for Thonny(python) format. Duplicate elimination Create a function named unique that receives a list and returns a (possibly shorter) list containing only the unique values in sorted order. Test your function with the list of numbers and list of strings that given in the sample output. Sample Output Original list of numbers [11, 11, 2, 2, 7, 7, 5, 5, 3, 3] New list after calling unique function [2, 3,...

  • Programming Assignment 6: A Python Class, Attributes, Methods, and Objects Obiectives .Be able to...

    I need some help with programming this assignment. Programming Assignment 6: A Python Class, Attributes, Methods, and Objects Obiectives .Be able to write a Python class Be able to define class attributes Be able to define class methods .Be able to process input from a text file .Be able to write an application using objects The goal of this programming assignment is to develop a simple image processing application. The application will import a class that creates image objects with...

  • C++ language Please help. Create a small hospital system, where patients can book appointments. The program...

    C++ language Please help. Create a small hospital system, where patients can book appointments. The program should be able to take a patient’s information and the appointment that they’d like to book. It should also be able to display the patients names in order of their appointments (ascendingly). Your program should consist of: Class Person: with private variables name, ID and age. A default and a copy constructor, setters and getters and a print function. Class Patient: inherits from Person....

  • A) Please implement a Python script to define a student class with the following attributes (instance...

    A) Please implement a Python script to define a student class with the following attributes (instance attributes): cwid: student’s CWID first_name : student’s first name last_name: student’s last name gender: student’s gender gpa: student’s gpa Please make these attributes as private ones so they have to be accessed via getter/setter methods or property. For this purpose, please define a getter/setter method and property for each of the attributes. Another thing you need to do is to define a constructor that...

  • *Python* INTRODUCTION: The goal of this programming assignment is to enable the student to practice object-oriented...

    *Python* INTRODUCTION: The goal of this programming assignment is to enable the student to practice object-oriented programming using classes to create objects. PROBLEM DEFINITION: Write a class named Employee that holds the following data about an employee in attributes: name, IDnumber, department, jobTitle The class should have 8 methods as follows:  For each attribute, there should be a method that takes a parameter to be assigned to the attribute. This is known as a mutator method.  For each...

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