1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Studentka2010 [4]
3 years ago
6

Design and implement a class Country that stores the name of the country, its population, its area, and the population density (

i.e., people per square kilometer (or mile). In other words, there are four major methods in this class (i.e., get country name, get area information, get population information, and get population density information). Then, write a test file that reads data.txt and prints the following three tasks by leveraging methods from the Country() class.  The country with the largest area. The country with the largest population.  The country with the largest population density You should turn in TWO Python files in this question. One is a Country class file and the other is the test program that leverages the methods from the Country()class and print the above three requests. You could leverage set() to store country information and do the operations.

Computers and Technology
1 answer:
melomori [17]3 years ago
4 0

Answer:

See explaination

Explanation:

Make use of Python programming language.

File: Country.py

class Country:

def __init__(self, n="", p=0, a=0):

""" Constructor """

self.name = n

self.population = p

self.area = a

self.pDensity = self.population / self.area

def getCountryName(self):

""" Getter method """

return self.name

def getPopulation(self):

""" Getter Method """

return self.population

def getArea(self):

""" Getter Method """

return self.area

def getPDensity(self):

""" Getter Method """

return self.pDensity

File: CountryInfo.py

from Country import *

# Opening file for reading

with open("d:\\Python\\data.txt", "r") as fp:

# List that hold countries

countryInfo = []

# Processing file line by line

for line in fp:

# Stripping spaces and new lines

line = line.strip()

# Splitting and creating object

cols = line.split('\t')

cols[1] = cols[1].replace(',', '')

cols[2] = cols[2].replace(',', '')

c = Country(cols[0], int(cols[1]), float(cols[2]))

countryInfo.append(c)

# Processing each countryInfo

largestPop = 0

largestArea = 0

largestPDensity = 0

# Iterating over list

for i in range(len(countryInfo)):

# Checking population

if countryInfo[i].getPopulation() > countryInfo[largestPop].getPopulation():

largestPop = i;

# Checking area

if countryInfo[i].getArea() > countryInfo[largestPop].getArea():

largestArea = i;

# Checking population density

if countryInfo[i].getPDensity() > countryInfo[largestPop].getPDensity():

largestPDensity = i;

print("\nLargest population: " + countryInfo[largestPop].getCountryName())

print("\nLargest area: " + countryInfo[largestArea].getCountryName())

print("\nLargest population density: " + countryInfo[largestPDensity].getCountryName() + "\n")

Please go to attachment for sample program run

You might be interested in
Which element is included in the shot breakdown storyboard? Which element is included in the shot breakdown storyboard?
VladimirAG [237]

Answer: jump out

Explanation:

Took the test and it was correct

5 0
2 years ago
Which of the following is the correct order of laws (from local to state to federal)
professor190 [17]

Answer:

That, Federal law > Constitutional Law > State law > Local ordinances

Explanation:

4 0
3 years ago
What is the best scenerio for
Stels [109]

Answer:

the teacher said a (dash) reads pages on website pls answer me now i have to write it now

5 0
2 years ago
Read 2 more answers
Which is a key component to participating in a school-to-work program?
Solnce55 [7]

The key component to participating in a school-to-work program is known as Job shadows.

<h3>What are job shadows?</h3>

Job shadowing is known to be a kind of on-the-job training that gives room for an interested employee to follow closely an see or analyze another employee carrying out the work.

Therefore, one can say that the key component to participating in a school-to-work program is known as Job shadows.

Learn more about School from

brainly.com/question/2474525

#SPJ1

4 0
2 years ago
A camera on a tripod shows the ground floor of a skyscraper and then moves upward to show its entire length. what camera movemen
scZoUnD [109]

Answer:

A pedestal. It involves moving the camera upwards or downwards in relation to a subject.

8 0
2 years ago
Other questions:
  • A word that has a specific, predefined meaning in a programming language is called
    8·1 answer
  • Microsoft ________ is a cloud storage and file sharing service
    12·1 answer
  • Which social media post indicates your home may be unattended?
    10·1 answer
  • A research team is studying parallel computing. They want to run parallel processes without having to use multiple processors. H
    15·2 answers
  • Deciding whether to explode a process further or determine that it is a functional primitive is a matter of experience, judgment
    8·1 answer
  • David owns a retail business that just implemented a web app to supplement sales. He needs to choose an attribution partner to i
    15·1 answer
  • The block of code below is supposed to display “multiple of 5” if the positive number value is in fact a multiple of 5
    8·1 answer
  • Give your own example of a nested conditional that can be modified to become a single conditional, and show the equivalent singl
    12·1 answer
  • A python program for the following output using for loop.
    13·1 answer
  • Abby has received a request for a data set of actual data for testing a new app that is being developed. She does not want the s
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!