Question

In: Computer Science

python Design a class named IP_address to represent IP address objects. The IP_addressclass contains the following...

python

Design a class named IP_address to represent IP address objects. The IP_addressclass contains the following

  • A number of instance variables/fields to store a table of data. You can design them by your own.
  • A constructor that creates a table with the following:
    • a list of data.
    • ip address
    • a integer to indicate the number of elements in the sum_list/freq_list/average_list
  • A get_ip_address() method that returns the ip address

For example, consider the following code fragment:

ip_key = '192.168.0.24'
data_list =[(0, 84), (1, 84), (2, 84), (3, 84), (4, 84), (5, 84), (6, 84), (7, 84), (8, 84), (9, 84), (10, 84), (11, 84), (12, 84), (13, 84), (14, 84), (15, 84), (16, 84), (17, 84), (18, 84), (19, 84), (20, 84)]
size = 3
ip = IP_address(key, data_list, size)

The data_list contains a list of tuple objects. Each tuple consists of the time-period value and the packet-size. You should summarize this list and create a frequency list, a sum of packet-size list and an average of packet-size list. There are a lot of data for each time-period value. We calculates the total number of bytes that the source host sent for each 10-second interval. For example: the above data_list will be divided into 3 groups, such as (0-9 second), (10-19 second) and (20-29 second)

  • (0, 84), (1, 84), (2, 84), (3, 84), (4, 84), (5, 84), (6, 84), (7, 84), (8, 84), (9, 84)
  • (10, 84), (11, 84), (12, 84), (13, 84), (14, 84), (15, 84), (16, 84), (17, 84), (18, 84), (19, 84)
  • (20, 84)

Therefore, the IP_address object should contain:

  • the ip address: '192.168.0.24'
  • a frequency list: [10, 10, 1] (i.e. there are 10 elements in the first group, 10 elements in the second group and 1 element in the third group)
  • a sum of packet-size list: [840, 840, 84] (i.e. the total number of bytes that the source host sent for each 10-second interval)
  • an average of packet-size list: [84.0, 84.0, 84.0]

We will set up the IP_address class step by step. You are required to set up the constructor and the get_ip_address() in this question. Continue from the previous question, modify the following in the IP_address class. :

  • modify the constructor and create the frequency list
  • add a method named get_freq_list(). The get_freq_list() method return a list of frequency lists (i.e. if the frequency list is [10, 10, 1], then the get_freq_list() should return [[0, 10], [1, 10], [2, 1]]

For example, consider the following code fragment:

ip_key = '192.168.0.24'
data_list =[(0, 84), (1, 84), (2, 84), (3, 84), (4, 84), (5, 84), (6, 84), (7, 84), (8, 84), (9, 84), (10, 84), (11, 84), (12, 84), (13, 84), (14, 84), (15, 84), (16, 84), (17, 84), (18, 84), (19, 84), (20, 84)]
size = 3
ip = IP_address(key, data_list, size)

The data_list contains a list of tuple objects.

  • (0, 84), (1, 84), (2, 84), (3, 84), (4, 84), (5, 84), (6, 84), (7, 84), (8, 84), (9, 84)
  • (10, 84), (11, 84), (12, 84), (13, 84), (14, 84), (15, 84), (16, 84), (17, 84), (18, 84), (19, 84)
  • (20, 84)

Therefore, the IP_address object should contain:

  • ip address: '192.168.0.24'
  • a frequency list: [10, 10, 1] (i.e. there are 10 elements in the first group, 10 elements in the second group and 1 element in the third group)

For example:

Test Result
ip_key = '192.168.0.24'
data_list =[(0, 84), (1, 84), (2, 84), (3, 84), (4, 84), (5, 84), (6, 84), (7, 84), (8, 84), (9, 84), (10, 84), (11, 84), (12, 84), (13, 84), (14, 84), (15, 84), (16, 84), (17, 84), (18, 84), (19, 84), (20, 84)]
size = 3
ip = IP_address(ip_key, data_list, size)
print(ip.get_freq_list())
print(ip.get_ip_address())
[[0, 10], [1, 10], [2,1] 
192.168.0.24

Solutions

Expert Solution

class IP_address():
def __init__(self,ip_add,data,size):#Construction of the Class
self.ip_add = ip_add
self.data = data
self.size = size #End of Assigning Parameters to Class Level Variables
self.l_list = [self.data[i:i+10] for i in range(0, len(self.data), 10)] #ReCreating the List of lists each of size 10
self.sum_list = [] #List of Sum of Packets
for i in self.l_list:
sum = 0
for j in range(len(i)):
sum+=i[j][1]
self.sum_list.append(sum)
self.avg_list = [] #Average of the Packets of Each list of 10 Tuples
for i in range(len(self.sum_list)):
l_size = len(self.l_list[i])
avg = self.sum_list[i]/l_size
self.avg_list.append(avg)
self.feq_list = []
for f_list in self.l_list:
self.feq_list.append(str(len(f_list)))
  
def get_feq_list(self): #Function for Freqency List and List of Frequencies for Each List of 10 Tuples
sent_list = []
for i in range(len(self.feq_list)):
sent_list.append([i,self.feq_list[i]])
return sent_list
def get_ip_address(self):#Function for Get IP
return self.ip_add
  

ip = "192.168.0.24"
data = [(0, 84), (1, 84), (2, 84), (3, 84), (4, 84), (5, 84), (6, 84), (7, 84), (8, 84), (9, 84),(10, 84), (11, 84), (12, 84), (13, 84), (14, 84), (15, 84), (16, 84), (17, 84),(18, 84), (19, 84),(20, 84)]
size = 3
print(type(data))
a = IP_address(ip,data,size)
print(a.feq_list)

''' If you want to Call the List you can Use a.avg_list, a.feq_list will Print the Data of those Lists..'''

Thank You... :)


Related Solutions

Python Design a class named IP_address to represent IP address objects. The IP_addressclass contains the following...
Python Design a class named IP_address to represent IP address objects. The IP_addressclass contains the following A number of instance variables/fields to store a table of data. You can design them on your own. A constructor that creates a table with the following: a list of data. IP address an integer to indicate the number of elements in the sum_list/freq_list/average_list A get_ip_address() method that returns the IP address For example, consider the following code fragment: ip_key = '192.168.0.24' data_list =[(0,...
Design a class named Fan to represent a fan. The class contains: ■ Three constants named...
Design a class named Fan to represent a fan. The class contains: ■ Three constants named SLOW, MEDIUM, and FAST with the values 1, 2, and 3 to denote the fan speed. ■ A private int data field named speed that specifies the speed of the fan (the default is SLOW). ■ A private boolean data field named on that specifies whether the fan is on (the default is false). ■ A private double data field named radius that specifies...
Python Please (The Fan class) Design a class named Fan to represent a fan. The class...
Python Please (The Fan class) Design a class named Fan to represent a fan. The class contains: ■ Three constants named SLOW, MEDIUM, and FAST with the values 1, 2, and 3 to denote the fan speed. ■ A private int data field named speed that specifies the speed of the fan. ■ A private bool data field named on that specifies whether the fan is on (the default is False). ■ A private float data field named radius that...
c++ E2b: Design a class named Rectangle to represent a rectangle. The class contains:
using c++E2b: Design a class named Rectangle to represent a rectangle. The class contains:(1) Two double data members named width and height which specifies the width and height of the rectangle .(2) A no-arg constructor that creates a rectangle with width 1 and height 1.(3) A constructor that creates a rectangle with the specified width and height .(4) A function named getArea() that returns the area of this rectangle .(5) A function named getPerimeter() that returns the perimeter of this...
Design a class named GeoPoint to represent a point with x- and y-coordinates. The class contains:  ...
Design a class named GeoPoint to represent a point with x- and y-coordinates. The class contains:   The data fields x and y that represent the coordinates with gette and setter methods. A no-arg constructor that creates a point (0, 0).   A constructor that constructs a point with specified coordinates. The method equals(GeoPoint p) that returns true if two GeoPoint objects have the same x- and y-coordinates. Write a test program that creates an array of GeoPoint objects. The size of...
Following the example of Circle class, design a class named Rectangle to represent a rectangle. The...
Following the example of Circle class, design a class named Rectangle to represent a rectangle. The class contains: Two double data fields named width and height that specify the width and height of the rectangle. The default values are 1 for both width and height. A no-arg constructor that creates a default rectangle. A constructor that creates a rectangle with specified width and height A method name getWidth() return the value of width A method named getHeight() returns value of...
Following the example of Circle class, design a class named Rectangle to represent a rectangle. The...
Following the example of Circle class, design a class named Rectangle to represent a rectangle. The class contains: Two double data fields named width and height that specify the width and height of the rectangle. The default values are 1 for both width and height. A no-arg constructor that creates a default rectangle. A constructor that creates a rectangle with specified width and height A method name getWidth() return the value of width A method named getHeight() returns value of...
PUT IN JAVA PROGRAMMING The StockB class: Design a class named StockB that contains the following...
PUT IN JAVA PROGRAMMING The StockB class: Design a class named StockB that contains the following properties: • Name of company • Number of shares owned • Value of each share • Total value of all shares and the following operations: • Acquire stock in a company • Buy more shares of the same stock • Sell stock • Update the per-share value of a stock • Display information about the holdings • The StockB class should have the proper...
In Java, design a class named MyInteger. The class contains: An int data field named value...
In Java, design a class named MyInteger. The class contains: An int data field named value that stores the int value represented by this object. A constructor that creates a MyInteger object for the specified int A get method that returns the int Methods isEven(), isOdd(), and isPrime() that return true if the value is even, odd, or prime, respectively. Static methods isEven(int), isOdd(int), and isPrime(int) that return true if the specified value is even, odd, or prime, respectively. Static...
Design a class named MyPoint to represent a point with x- and y-coordinates. The class should...
Design a class named MyPoint to represent a point with x- and y-coordinates. The class should contain: Two data fields x and y that represent the coordinates. A no-arg constructor that creates a point at (0, 0). A constructor that creates a point with specified coordinates. Get methods for data fields x and y respectively. A method named distance that returns the distance from this point to another point with specified x- and y-coordinates. Use the formula: root (x2-x1)2 +...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT