Write a class called DataPoint. A datapoint should have the following two properties:   - name  - The name should always be exactly 5 characters long. If a name that is too short is given, the name should be padded with additional 'X' characters to make it exactly 5 characters long. If a name is given that is too long the extra characters should be removed. Thus is a user supply 'AB' as the name, it should be padded to become 'ABXXX' whilst if a user gives 'ABCDEFG' as a name, it should be truncated (shortened) to 'ABCDE'   - value - The value should always be between 0 and 100. You may assume a numeric value will be supplied. if the value that is given is less than 0, the value should be set to exactly 0 and a message should be printed stating 'The value must be greater than 0'. If a value of more than 100 is given, the value should be set to exactly 100 and a message should be printed stating 'The value must be less than 100' In addition to changing the properties given the above constraints, the user of the class should be able to read both of the properties described. In addition to the above properties, the class should have the following methods:   increment() - when this procedure is called the value property should be increased by 5. However, if this would raise the value to more than 100, it should be set to be exactly 100 instead. Note: This method will only change the value, no additional information will be printed. decrement() - when this procedure is called the value property should be decreased by 5. However, if this lowers the value to less than 0, it should be set to be exactly 0 instead. Note: This method will only change the value, no additional information will be printed.

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

Write a class called DataPoint. A datapoint should have the following two properties:

  - name  - The name should always be exactly 5 characters long. If a name that is too short is given, the name should be padded with additional 'X' characters to make it exactly 5 characters long. If a name is given that is too long the extra characters should be removed. Thus is a user supply 'AB' as the name, it should be padded to become 'ABXXX' whilst if a user gives 'ABCDEFG' as a name, it should be truncated (shortened) to 'ABCDE'

  - value - The value should always be between 0 and 100. You may assume a numeric value will be supplied. if the value that is given is less than 0, the value should be set to exactly 0 and a message should be printed stating 'The value must be greater than 0'. If a value of more than 100 is given, the value should be set to exactly 100 and a message should be printed stating 'The value must be less than 100'

In addition to changing the properties given the above constraints, the user of the class should be able to read both of the properties described.

In addition to the above properties, the class should have the following methods:

 

increment() - when this procedure is called the value property should be increased by 5. However, if this would raise the value to more than 100, it should be set to be exactly 100 instead. Note: This method will only change the value, no additional information will be printed.

decrement() - when this procedure is called the value property should be decreased by 5. However, if this lowers the value to less than 0, it should be set to be exactly 0 instead. Note: This method will only change the value, no additional information will be printed.

 

For example:

Test Result
x = DataPoint('ABCDE', 96) print(x.name) print(x.value) ABCDE 96
x = DataPoint('ABCDE', 96) print(x.name) print(x.value) x.decrement() print(x.value) ABCDE 96 91
x = DataPoint('ABCDE', -1) The value must be greater than 0
x = DataPoint('ABCDE', 80) print(x.value) x.value = 110 80 The value must be less than 100
x = DataPoint('ABC', 23) print(x.name) print(x.value) ABCXX 23
x = DataPoint('ABCDEFGHIJKLMNO', 83) print(x.name) print(x.value) ABCDE 83
x = DataPoint('ABCDE', 91) print(x.name) print(x.value) x.increment() print(x.value) x.increment() print(x.value) x.increment() print(x.value) ABCDE 91 96 100 100
Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY