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
Whos really watching this guys bruh​
Ivahew [28]

Answer:

Me no

Explanation:

4 0
3 years ago
Read 2 more answers
The AutoRecovery feature would be useful for which situations? Check all that apply.
Aliun [14]

Answer:

All of the above but I'm not 100% sure.

5 0
3 years ago
What are the benefits of using LinkedIn Sales Navigator?
lutik1710 [3]

Answer:

Well, there are a number of advantages that come with this advanced LinkedIn automation tool. Here are some of the top benefits of a Sales Navigator:

1. Can find and export up to 5000 prospects at a time.

2. Enables you to send 30 InMails per month

3. Easy access Teamlink -enabling you to expand your network by pooling connections

4. Integrate with existing systems

4 0
3 years ago
What is software?<br>....​
serious [3.7K]

Answer:

Software, instructions that tell a computer what to do. Software comprises the entire set of programs, procedures, and routines associated with the operation of a computer system. The term was coined to differentiate these instructions from hardware — i.e., the physical components of a computer system.

Explanation:

PA BRAINLIEST

HOPE ITS HELP

GOD BLESS

7 0
3 years ago
Read 2 more answers
Complete the statement below with the correct term.
dangina [55]

Answer

Explanation:

mode

6 0
3 years ago
Other questions:
  • Which of the following is an external hard drive
    11·1 answer
  • The following algorithm adds all the entries in a square n × n array A. Analyze this algorithm where the work unit is the additi
    7·1 answer
  • Janice, who is 15, posts a picture of herself drinking alcohol and making an obscene gesture on her social networking page. Whic
    11·2 answers
  • Which of the following are valid values for a boolean value in programming? (Select all that apply)
    8·1 answer
  • Respecting yourself and others, educating yourself and connecting with others, and protecting yourself and others are all aspect
    11·1 answer
  • Do you think the current system of punishment in the United States works? Why? What would you change?
    13·1 answer
  • When you need to cut new external threads on a bolt, which of the following tools should you use?
    9·2 answers
  • What is project management? A. Brainstorming ways to plan a project B. Executing, completing, and revising a project C. Managing
    10·1 answer
  • Tasks you can perform online include which of the following?
    13·1 answer
  • Question #2
    15·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!