Reference no: EM132309263
Assignment
Write a first program that loops, prompting the user to enter their last name, first name, meter number, previous reading and current reading, and then writes that data out to file called 'customers.txt'. The program should check inputs for validity according to the following rules:
First and last names must be alphabetic. No spaces or special characters. Names must be less than 20 characters long.
Meter number must be an eight-digit number between 26000000 and 79999999
Meter readings must be positive floating-point numbers with a six-digit integer part and a single-digit decimal part (e.g. 123456.7)
Current reading must be greater than or equal to the previous reading
The file should record each customers information on a single line and the output file should have the following appearance (last name appears first):
Luigi,Mario,26112233,123456.7,234567.8
Vader,Darth,37223344,567890.1,678901.2
A typical example of the display of your program can be as follows. Your program MUST follow the same display style.
------------------------------------------------
Superstar Energy Australia (SEA) Billing System
------------------------------------------------
Enter last name : Luigi
Enter first name : Mario
Enter meter number : 26112233
Enter previous reading: 123456.7
Enter current reading : 234567.8
------------------------------------------------
Do you want to enter another customer? (y/n): y
------------------------------------------------
Enter last name : Vader
Enter first name : Darth
Enter meter number : 37223344
Enter previous reading: 567890.1
Enter current reading : 678901.2
------------------------------------------------
Do you want to enter another customer? (y/n): n
------------------------------------------------
Goodbye.
In case of an invalid input, the display can be as follows.
...
Enter last name : L000
Invalid input! Last name must be an alphabetic string.
Enter last name : Luigi
Write a second program that opens the 'customers.txt' file for reading and then reads each record, splitting it into its component fields and checking each field for validity. The rules for validity are as in your first program, with the addition of a rule that specifies that each record must contain exactly five fields. Your program should print out each valid record it reads. Your program should terminate when it reads an invalid record, printing out on which line number the error occurred, and what the error was.
A typical example of the display of your program can be as follows. Your program MUST follow the same display style.
------------------------------------------------
Superstar Energy Australia (SEA) Billing System
------------------------------------------------
Customer Data - Record (1)
------------------------------------------------
Last name : Luigi
First name : Mario
Meter number : 26112233
Previous reading: 123456.7
Current reading : 234567.8
------------------------------------------------
Customer Data - Record (2)
------------------------------------------------
Last name : Vader
First name : Darth
Meter number : 37223344
Previous reading: 567890.1
Current reading : 678901.2
------------------------------------------------
End of Customer Data
------------------------------------------------
In case there is a record with an invalid data, for example
Luigi,Mario,26112233,123456.7,234567.8
Vader,Darth,17223344,567890.1,678901.2
The output can be as follows.
------------------------------------------------
Superstar Energy Australia (SEA) Billing System
------------------------------------------------
Customer Data - Record (1)
------------------------------------------------
Last name : Luigi
First name : Mario
Meter number : 26112233
Previous reading: 123456.7
Current reading : 234567.8
------------------------------------------------
Invalid record in line (2)!
------------------------------------------------
Meter number is outside the valid range.
You need to develop the system by completing the following three tasks:
Task 1
Draw flowchart/s that present the steps of the algorithm required to perform the tasks specified.
Task 2
Select at least six sets of test data that will demonstrate the 'normal' operation of your program; that is, test data that will demonstrate what happens when a VALID input is entered.
Note: for this program, valid normal input INCLUDES data that does NOT conform to the rules specified. This is because it is the function of your program to DETECT such erroneous data.
Select at least three sets of test data that will demonstrate the 'abnormal' operation of your program. For these programs, this might include the inability to write to the output file, or in the case of the second program the inability to open the file.
Set your test results out in a tabular form as follows: test data type, test data, the reason it was selected, the output expected due to using the test data, and finally the output actually observed when the test data is used. It is important that the output listings (i.e., screenshots) are not edited in any way.
Task 3
Implement your algorithm in Python. Comment on your code as necessary to explain it clearly.
In addition, for this exercise, use multiple functions, instead of using a single function to do everything. Create a good design of the functions to make the best use of the code and avoid duplication.
You also need to design your program so that it has components that can be reused in another program if needed. Handle exceptions appropriately and use appropriate data structures.
Run your program using the test data you have selected and complete the test data table.