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
If every company is now a technology company, then what does this mean for every student attending a business college
timofeeve [1]

Answer:

Explanation:

There are all sorts of possibilities for, say, inserting new technologies into existing processes. But most of these improvements are incremental. They are worth doing; in fact, they may be necessary for survival. No self-respecting airline, for instance, could do without an application that lets you download your boarding pass to your mobile telephone. It saves paper, can't get lost and customers want it.

But while it's essential to offer applications like the electronic boarding pass, those will not distinguish a company. Electronic boarding passes have already been replicated by nearly every airline. In fact, we've already forgotten who was first.

5 0
3 years ago
A smart refrigerator can use what to detect when you are running low on milk, and then send a reminder to you on a wireless.
Olegator [25]

Answer:

RFID scanning or Barcode reader

Explanation

Smart refrigerators have inbuilt RFID scanning technology that help monitor the stock that is inside your fridge. Once you pass your items through the inbuilt RFID scanner in the fridge, the barcode of your items is cross-referenced with a database and given a unique tag for identification. This technology helps detect and track the stock that is inside your fridge and when you start running low, the RFID can be triggered to send a reminder as a notification on your email or a text message.

3 0
3 years ago
How computer can affect the life of people?
SCORPION-xisa [38]
<h2>Answer These are the negative effects</h2><h2>Low grades In school: others use the computer not for studying but something else. Which makes them unfocused in school.</h2><h2 /><h2>Waist and wrist pains: Due to long sitting ppl experience pains all over the body. </h2>

<h2>Addiction: People get addicted to the computer and makes them forget they have something important doing.</h2>
4 0
3 years ago
G The method of mapping where each memory locationis mapped to exactly one location in the cache is
Otrada [13]

Answer:

Direct Mapped Cache

Explanation:

Given that a Direct Mapped Cache is a form of mapping whereby each main memory address is mapped into precisely one cache block.

It is considered cheaper compared to the associative method of cache mapping, and it is faster when searching through it. This is because it utilizes a tag field only.

Hence, The method of mapping where each memory location is mapped to exactly one location in the cache is "Direct Mapped Cache"

4 0
2 years ago
What's the answer to this​
yarga [219]

Answer:

S

Explanation:

The index operator will address individual characters in the string.

5 0
3 years ago
Other questions:
  • Design the below using an array// Sunrise Freight charges standard// per-pound shipping prices to the five states they serve// –
    6·1 answer
  • Create a dictionary named letter_counts that contains each letter and the number of times it occurs in string1. Challenge: Lette
    14·1 answer
  • An online service provider provides its users with hosted computers, an operating system, and a database management system (DBMS
    12·1 answer
  • What is really meant by SSDs
    9·1 answer
  • Why would it be beneficial to preview a page before printing?
    8·1 answer
  • In a system using the relocatable dynamic partitions scheme, given the following situation (and using decimal form): Job Q is lo
    5·1 answer
  • When you perform an in-place upgrade to windows 8.1 from windows 7, what will be names of the “windows” folders in windows 7 and
    5·1 answer
  • 7.
    15·1 answer
  • 1. A cell is identified by its ........
    8·1 answer
  • What is a file and where can we make use of a file?​
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!