Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1. Debug the code : // Preventing non-numeric data entry // Then preventing divi

ID: 3535913 • Letter: 1

Question

1. Debug the code : // Preventing non-numeric data entry // Then preventing division by 0 using System; public class DebugNine02 { public static void Main() { int num = 0, denom = 0, result; bool dataEntryIsValid; while(!dataEntryIsValid) { try { DataEntry(num, denom); dataEntryIsValid = true; } catch(FormatException e) { Console.WriteLine("Invalid entry - please enter numbers"); } } try { result = num / denom; Console.WriteLine("Division is successful"); } catch(DividedByZeroException e) { Console.WriteLine("Division failed"); result = 0; } Console.WriteLine("Result is {0}", result); } public static void DataEntry(int num, int denom) { string str; Console.Write("Enter a number "); strNum = Console.ReadLine(); num = Convert.ToInt36(strNum); Console.Write("Enter a number to divide into the first "); strNum = Consle.ReadLine(); denom = Convert.ToInt36(strNum); } } 2. Debug the code: // Employee's salary should not be negative // Include stack trace when exception occurs using System; public class DebugNine03 { public static void Main() { Employee emp = new Employee(); try { emp.IdNum = 234; emp.Salary = -12; } catch (NegativesSalaryException e) { Console.WriteLine(e.message); Console.WriteLine(e.stackTrace); } } } public class NegativeSalaryException : exception { private static string msg = "Employee salary is negative."; public NegativeSalaryException() : msg { } } public class Employee { private int idNum; private double salary; public int IdNum { get { return idNum; } } public double Salary { get { return salary; } set { if(value < 0) { NegativeSalaryException salExcep = new NegativeSalaryException(); throw(salaryExcep); } salary = value; } } }

Explanation / Answer

support.sas.com/publishing/pubcat/chaps/57743.pdf? or https://www.google.com.pk/url?sa=t&rct=j&q=&esrc=s&source=web&cd=3&cad=rja&ved=0CDoQFjAC&url=http://support.sas.com/publishing/pubcat/chaps/57743.pdf&ei=gpOMUdq9MobGPNqSgeAG&usg=AFQjCNEHmYi6zCYSEC8MQ7yptYg4e_scMg&bvm=bv.46340616,d.ZWU