Question: Using Visual Studio Console App (.NET framework) Modify the following code which validates product codes and illustrates the use of try-catch and substrings in Visual

Using Visual Studio Console App (.NET framework) Modify the following code which validates product codes and illustrates the use of try-catch and substrings in Visual C #. The first two numeric digits of the code represent the month, followed by four digits that represent the year and end with three capital letters representing the town.Complete the code validation by validating the entry for the months (01-12).

Code :

using System;

namespace ValidCodes { class Program { //------------------------------------------------------------------------------------------------------------------------ // It counts the number of code of products that are from the town of Ponce (PON) and that were produced after the year 2010. //------------------------------------------------------------------------------------------------------------------------- public static void Main(string[] args) { string code, town; int year, valid = 0, Count = 0;

Console.Out.Write("Enter the product code(XXX to exit): "); code = Console.In.ReadLine();

while (code != "XXX") { try { town = code.Substring(6, 3); year = int.Parse(code.Substring(2, 4)); valid++; if (town == "PON" && year > 2010) Count++; } catch (ArgumentOutOfRangeException exception) { Console.Out.WriteLine("Wrong code size: " + exception); } catch (IndexOutOfRangeException exception) { Console.Out.WriteLine("Wrong code size: " + exception); } catch (FormatException exception) { FormatException e = exception; Console.Out.WriteLine("year is not numeric: "); } Console.Out.Write("Enter the product code (XXX to exit): "); code = Console.In.ReadLine(); } Console.Out.WriteLine("# of valid codes entered: " + valid); Console.Out.WriteLine("# of valid Ponce codes: " + Count);

Console.WriteLine("Press any key to exit"); Console.ReadKey(); } } }

Using Visual Studio Console App (.NET framework) Modify the following code which

$ 1 Program.cs + X C# ValidCodes ValidCodes.Program - Main(string[] args) using System; 2 3 namespace ValidCodes 4 { O references 5 class Program 6 { 7 8 // It counts the number of code of products that are from the town of Ponce (PON) and that were produced after the year 2010. 9 //------ O references 10 public static void Main(string[] args) 11 { 12 string code, town; 13 int year, valid = 0, Count = 0; 14 15 Console.Out.Write("Enter the product code(xxx to exit): "); 16 10 code = Console.In.ReadLine(); 17 18 while (code != "XXX") 19 { 20 try 21 { 22 town = code. Substring(6, 3); 23 year = int.Parse(code. Substring(2, 4)); 24 valid++; 25 if (town == "PON" && year > 2010) Count++; 27 } 28 catch (ArgumentoutofrangeException exception) 29 { 30 Console.Out.WriteLine("Wrong code size: " + exception); - 26, 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 100 % catch (IndexOutOfRangeException exception) { Console.Out.WriteLine("Wrong code size: " + exception); } catch (FormatException exception) { FormatException e. = exception; Console.Out.WriteLine("year is not numeric: "); } Console.Out.Write("Enter the product code (XXX to exit): "); code = Console.In.ReadLine(); } Console.Out.WriteLine("# of valid codes entered: + valid); Console.Out.WriteLine("# of valid Ponce codes: " + Count); Console.WriteLine("Press any key to exit"); Console.ReadKey(); No issues found Ln: 26 Ch: 33 SPC CRLF

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!