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
Features present in most GUIs include _____.
atroni [7]
Forms, Icons, Menus, Windows
3 0
4 years ago
Read 2 more answers
Security on a network not only means being able to prevent a hacker from breaking into your computer but also includes being abl
iVinArrow [24]

Security on a network not only means being able to prevent a hacker from breaking into your computer but also includes being able to recover from temporary service problems or from natural disasters is True.

a.True.

<u>Explanation:</u>

As network administrator he or she is responsible for both prevent from hacker and restore network from disaster with minimum down time. Network administrator has monitor network traffics and packets and do a period check on malware, spyware and ransom ware protection.

As network administrator should ready made tools or purchase to handle the network traffic to avoid network disaster.

Network administrator update firewall patches and upgrades virus signature files at period intervals. Network administrator also takes necessary advice from firewall hardware appliance from supplier and takes necessary steps o handle situation then and there.

7 0
4 years ago
What is the key benefit of using RAM in a computer?
Paul [167]
It allows commonly used instructions to be stored for easier access, but the ram gets deleted when ever you restart the computer.
3 0
3 years ago
Because __________ software can block suspicious software in real-time, it has an advantage over such established anti-virus det
shutvik [7]

Because dynamic analysis software can block suspicious software in real-time, it has an advantage over such established anti-virus detection techniques as fingerprinting or heuristics.

<h3>What is dynamic program analysis?</h3>
  • The examination of computer software by means of the execution of programs on a physical or virtual processor is known as dynamic program analysis.
  • Effective dynamic program analysis requires running the target program with enough test inputs to account for almost all potential outputs.
  • Utilizing software testing tools like code coverage increases the likelihood that a sufficient sampling of the program's potential behaviors has been seen.
  • Additionally, it is important to take precautions to reduce the impact that instrumentation has on the target program's execution, especially its temporal characteristics.
  • Static program analysis contrasts with dynamic analysis. Dynamic testing is used in unit tests, integration tests, system tests, and acceptance tests.

To learn more about the topic, refer to the following link:

brainly.com/question/17209742

#SPJ4

8 0
2 years ago
consider a system for temperature measurement consisting of an integrated temperature sensor (electronic component sensitive to
Paladinen [302]

Answer:

ZOO WEE MAMA

Explanation:

ZOO WEE MAMA

5 0
3 years ago
Other questions:
  • Which VPN protocol does not support using Password Authentication Protocol (PAP), Challenge Handshake Authentication Protocol (C
    14·1 answer
  • Which one of the following items would you be most likely to keep in a database? A. Payroll records B. Address book C. Financial
    7·1 answer
  • Write a function shampoo_instructions() with parameter num_cycles. If num_cycles is less than 1, print "Too few.". If more than
    14·1 answer
  • The ______ is the information center that drivers need to refer to when they're NOT scanning the road.
    14·1 answer
  • An object contains data and the instructions that manipulate the data (Points : 2) True
    8·1 answer
  • In a singing competition, there are 34 more men than women
    5·2 answers
  • POINT AND BRAINLIEIST GIVE AWAY!!!
    11·2 answers
  • Describe four features of a well designed input screen
    10·2 answers
  • Place a check next to each of the choices that describe an example of proper ergonomics. (more than 1 answer)
    7·2 answers
  • each data mining technique has its advantages and limitations. which data mining technique mimics the neural structure of the br
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!