Question

Using Phyton. Design a class Country with the use of constructor, mutator, accessor methods and implement...

Using Phyton. Design a class Country with the use of constructor, mutator, accessor methods and implement that class to store the name of the countries, their population, their areas and regions they are located. Then write a program that reads 5 instances (US, China, Russia, Germany, India) of country class and display the name of the country, the population, the area and the region they are located.

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

    # Constructor to initialize instance members
    def __init__(self, name, population, area, region):
        self.__name = name
        self.__population = population
        self.__area = area
        self.__region = region

    # Setter and getter methods for instance members
    def setName(self, name):
        self.__name = name

    def getName(self):
        return self.__name

    def setPopulation(self, population):
        self.__population = population

    def getPopulation(self):
        return self.__population

    def setArea(self, area):
        self.__area = area

    def getArea(self):
        return self.__area

    def setRegion(self, region):
        self.__region = region

    def getRegion(self):
        return self.__region

    # This method returns country details in string format
    def __str__(self):
        return "Name: %s\nPopulation: %.2f crores\nArea: %.2f km^2\nRegion: %s\n" % (
            self.__name, self.__population, self.__area, self.__region)


if __name__ == '__main__':
    # Create 5 object and print them
    US = Country('US', 32.72, 9833520, 'North America')
    China = Country('China', 138.64, 9596960, 'Asia')
    Russia = Country('Russia', 14.45, 17125191, 'Europe')
    Germany = Country('Germany', 8.28, 357021, 'Europe')
    India = Country('India', 133.92, 3287263, 'Asia')

    print(US)
    print(China)
    print(Russia)
    print(Germany)
    print(India)

SCREENSHOT


OUTPUT

Add a comment
Know the answer?
Add Answer to:
Using Phyton. Design a class Country with the use of constructor, mutator, accessor methods and implement...
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
  • Create a super class called Store which will have below member variables, constructor, and methods Member...

    Create a super class called Store which will have below member variables, constructor, and methods Member variables: - a final variable - SALES_TAX_RATE = 0.06 - String name; /** * Constructor:<BR> * Allows client to set beginning value for name * This constructor takes one parameter<BR> * Calls mutator method setName to set the name of the store * @param name the name of the store */ /** getName method * @return a String, the name of the store */...

  • In C++, Step 1: Implement the Student Class and write a simple main() driver program to...

    In C++, Step 1: Implement the Student Class and write a simple main() driver program to instantiate several objects of this class, populate each object, and display the information for each object. The defintion of the student class should be written in an individual header (i.e. student.h) file and the implementation of the methods of the student class should be written in a corresponding source (i.e. student.cpp) file. Student class - The name of the class should be Student. -...

  • using python to Design a class that holds the following personal data: name, address, age, and...

    using python to Design a class that holds the following personal data: name, address, age, and phone number. Write appropriate accessor and mutator methods. Also, write a program that creates three instances of the class. One instance should hold your information, and the other two should hold your friends’ or family members’ information.

  • Using the Die class defined in this chapter, design and implement a class called PairOfDice, composed...

    Using the Die class defined in this chapter, design and implement a class called PairOfDice, composed of two Die objects. Include methods to set and get the individual die values, a method to roll the dice, and a method that returns the current sum of the two die values. Create a driver class called RollingDice2 to instantiate and use a PairOfDice object. I need the main method or test class public class Die { private final int MAX = 6;...

  • Language is JAVA. Clarification for the Shape class (highlighted): The following requirements specify what fields you...

    Language is JAVA. Clarification for the Shape class (highlighted): The following requirements specify what fields you are expected to implement in your Shape class; - A private String color that specifies the color of the shape - A private boolean filled that specifies whether the shape is filled - A private date (java.util.date) field dateCreated that specifies the date the shape was created Your Shape class will provide the following constructors; - A two-arg constructor that creates a shape with...

  • PLEASE DO BOTH OF THESE IN PYTHON 1) Exercise #1: Design and implement class Rectangle to...

    PLEASE DO BOTH OF THESE IN PYTHON 1) Exercise #1: Design and implement class Rectangle to represent a rectangle object. The class defines the following attributes (variables) and methods: Two Class variables of type double named height and width to represent the height and width of the rectangle. Set their default values to 1.0 in the default constructor. A non-argument constructor method to create a default rectangle. Another constructor method to create a rectangle with user-specified height and width. Python...

  • JAVA :The following are descriptions of classes that you will create. Think of these as service...

    JAVA :The following are descriptions of classes that you will create. Think of these as service providers. They provide a service to who ever want to use them. You will also write a TestClass with a main() method that fully exercises the classes that you create. To exercise a class, make some instances of the class, and call the methods of the class using these objects. Paste in the output from the test program that demonstrates your classes’ functionality. Testing...

  • Using JAVA* Design a class named Person with fields for holding a person’s name, address, and...

    Using JAVA* Design a class named Person with fields for holding a person’s name, address, and telephone number. Write one or more constructors and the appropriate mutator and accessor methods for the class’s fields. Next, design a class named Customer, which extends the Person class. The Customer class should have a field for a customer number and a boolean field indicating whether the customer wishes to be on a mailing list. Write one or more constructors and the appropriate mutator...

  • java This lab is intended to give you practice creating a class with a constructor method,...

    java This lab is intended to give you practice creating a class with a constructor method, accessor methods, mutator methods, equals method , toString method and a equals method. In this lab you need to create two separate classes, one Student class and other Lab10 class. You need to define your instance variables, accessor methods, mutator methods, constructor, toString method and equals method in Student class. You need to create objects in Lab10 class which will have your main method...

  • Write a Gui programming by using JavaFx menus, stage and screen concepts to the RetailItem class,...

    Write a Gui programming by using JavaFx menus, stage and screen concepts to the RetailItem class, Write a class named Retailltem that holds data about an item in a retail store. The class should have the following fields description: The description field is a String object that holds a brief description of the item . unitsOnHand: The unitsOnHand field is an int variable that holds the number of units currently in inventory Price: The price field is a double that...

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