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
What is the difference between a manufacturing engineer and a materials engineer?
lyudmila [28]
<span> a </span>manufacturing<span> or industrial </span>engineer<span> are mechanical </span>engineers<span> with ... Process </span>Engineers<span> specialise in processes where raw </span>materials<span> are converted using chemical processes resulting in significantly </span>different<span> ...</span>
7 0
3 years ago
Read 2 more answers
Each type of text has a purpose for the reader if you were looking to research penguins what type of text would u utilize
dlinn [17]
1. ughhhh not entirely sure but B, 2. again not entirely sure should be B as well and finally 3.is D remember these are not always the answer just most likely what one person thinks
3 0
3 years ago
Which of these graphic elements combine text, illustrations, and color?
Likurg_2 [28]

Answer:

Send the picture.

Explanation:

8 0
3 years ago
Read 2 more answers
Peter is a data analyst in a financial firm. He maintains a spreadsheet that contains all employee details. Peter wants to analy
alukav5142 [94]

Answer: filter the data of employees with more than five years of experience

Explanation:

The technique that Peter can use to perform this analysis is to filter the data of employees with more than five years of experience.

Filter in spreadsheets allows one to see the data that is required based on the input that was given. In this case, since Peter wants to analyze the data of all employees that have experience of more than five years, this can be filtered and the employees who have experience of more than 5 years will be shown.

The workers who have experience of less than five years will not b shown in this case.

3 0
2 years ago
Which Windows feature allows secure printing over the Internet?​
ludmilkaskok [199]

Answer:

You need to install Windows 7 over an existing version of Windows.

Explanation:

Brainiest??

3 0
3 years ago
Other questions:
  • A Pool charges $4 each visit,or you can buy a membership. Write and solve an inequality to find how many times a person should u
    5·1 answer
  • What are language standards? At this point in your study of programming, what do they mean to
    5·1 answer
  • It is important for a writter to include voice and point of view in writting because _______
    11·1 answer
  • What is the difference between a fragment shader and vertex shader? How do they relate?
    8·1 answer
  • 9. What is the difference between a hand-drawn sketch, a working drawing, and a 3D model?
    14·1 answer
  • What is a seismogram?
    9·1 answer
  • Which sentence uses a pair of synonyms? Because there was so much shouting, many of the protestors began screaming in order to b
    6·2 answers
  • You are a database administrator. Chantelle comes to you asking for help on how to access all the data in one row of the databas
    11·1 answer
  • John’s grandparents make wine for special occasions. They add a pinch of yeast to crushed grapes. Over time, this action release
    15·2 answers
  • We have studied machine cycle in class. Suppose that each of the four modules of machine cycle is taking 2 seconds. If there are
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!