Question
In C# Write a ZipCode class using Main. Your ZipCode class will encode and decode five digit bar codes used by the US Postal Service
In C#
Write a ZipCode class using Main. Your ZipCode class will encode and decode five digit bar codes used by the US Postal Service on envelopes. The class should have two constructors.
The first constructor should input the zip code as an integer o If it has less than 5 digits, just assume that any missing digits are leading 0s o If it has more than 5 digits display an error message.
The second constructor should input the zip code as a bar code string consisting of 0s and 1s as described above. o It should check for various errors and report them. The output sample illustrates several errors that must be reported.
Although you have two ways to input the zip code, internally the class must only store the zip code as an integer value. The bar-code representation can always be reconstructed from the integer value.
TheZipCode class should also have a public method, GetBarCode() to return the zip code as a properly constructed string of binary digits.Or else report a specific error.
This class should use a Property for zip similar to the treatment of balance in Account.cs (Please see Startup Notes 4). Notice in this implementation that it is easily possible to check that the zipcode value is no more than 5 digits. (The Property feature of C# avoids the need for extra methods such as GetZip and SetZip (And similar method names if there are additional member variables of classes.) This feature is not \ available in Java.
You also need a private method ParseBarCode()to decode the string of binary digits and return the bar code value as an int. This is the most complicated method of the assignment
Main
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks;
// ********************* MAIN METHOD ********************* public class ZipTest { public static void Main() { Console.WriteLine("Required Output for Zipcode Testing"); ZipCode zip1 = new ZipCode(995047), zip2 = new ZipCode("100101010011100001100110001"), zip3 = new ZipCode(12345), zip4 = new ZipCode(67890);
Console.WriteLine("{0}'s bar code is '{1}'", zip1.Zip, zip1.GetBarCode()); Console.WriteLine("{0}'s bar code is '{1}'", zip2.Zip, zip2.GetBarCode()); Console.WriteLine("{0}'s bar code is '{1}'", zip3.Zip, zip3.GetBarCode()); Console.WriteLine("{0}'s bar code is '{1}'", zip4.Zip, zip4.GetBarCode());
// Test a range of values by first constructing a zip code with // an integer, then retrieving the bar code and using that to // construct another ZipCode. int zip_int = 0; for (int i = 0; i
// Construct a next ZipCode from the current one's bar code String z1_code = z1.GetBarCode(); ZipCode z2 = new ZipCode(z1_code);
Console.Write(" {0:D2}: {1:D5} has code '{2}'", i + 1, z2.Zip, z1_code); if ((z1_code == z2.GetBarCode()) && (z1.Zip == z2.Zip)/* && (z2.Zip == five_digit_zip)*/) { Console.WriteLine(" [OK]"); } else { Console.WriteLine(" [ERR]"); }
// Increment the test value arbitrarily zip_int += (233 + zip_int % 7); } // end for
Console.WriteLine(); Console.ReadKey(); // Test some error conditions. This test assumes that // ZipCode will simply print an error message to Console // and will not exit the program. Console.WriteLine(" Initialize an array of bar codes with known errors:"); int BAD_ZIP_COUNT = 5; // Use 2-D array of strings for tests. String[,] badZips = { { "10010101001110000110011001", "bad length" }, { "000101010011100001100110001", "bad start/end character" }, { "100101010011100001100110000", "bad start/end character" }, { "100104010011100001100110021", "bad digit" }, { "100101010011100001100111001", "bad sequence" } }; for (int i = 0; i
} //************** END OF main() ************ } // end ZipTest class
Required Output for Zipcode Testing 995847 zip code more than S digits 95047"s bar code s 1101000181011e0001e01180011 24e60's bar code is "10e1e10180111e900116011eee1 2345's bar code is 10001100181ee11ee1ee1e1e1e1 7890s bar code s 1011ee1e9e11ee1e1e18011eee1 02: 54289 has code 101010010010010110010101001 * [OK 03: 19824 has code 1860111018011e6e6e1e1e1e011' [o] 4: 99849 has code 1101601818918e1e01e01101e01 [oK] es: 83660 has code 118018e011e011801106e118e01 [oK] 6: 80625 has code 1100101180001106001e1810101 [OK] 7:99396 has code '1101801818990110161ee11801 [oK] 08: 12609 has code 100011001010110011000101001' [OK) 09: 41924 has code 1010010081 11010000101010011' [OK] 10: 98641 has code "1101001e01e0116601801e00111 [OK] 11: 41316 has code 101001000110011000011011001' [OK] 12: 02921 has code 111800ee1e11e1e6e6161860111' [OK 13: 97584 has code 110100100010101010010010011' [OK] 14: 69721 has code #101100191001000100101009111* [OK] 15: 63616 has code 1011e00e1100116000011011001' [oK] 16 : 96225 has code 110100011000010100101010101 * [OK] 17:97824 has code "110100160011ee1eee1e1e10011' [OK] 18: 24009 has code 100101010011100011000101001' [OK] 19: 94564 has code "1101e0e1e01e10100116016011 OK] 20: 25625 has code 160101028100110000101016181"[oK] 21: 84100 has code "11801801e01e081111e6e11e001 [ok] 22: 92601 has code 110100001010110011000000111' [OK] 23:53124 has code "18101e0ee11e0e11e0101016011 [oK 24: 43889 has code 1818018ee11016e1e1e010181801 [oK] 25: 9e336 has code 11e1e011ee0ee11ee011e011001 [Ok]Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started