Debugging and Running

Running to a Point

Introduction

When executing a program, you can specify a section or line where you want the execution to pause, for any reason you judge necessary. This approach is useful if you have checked code up to a certain point and it looked alright. If you are not sure about code starting at a certain point, this can be your starting point.

To execute code up to a certain point

Practical LearningPractical Learning: Running to a Point

  1. Start Microsoft Visual Studio
  2. On the main menu of Microsoft Visual Studio, click File -> New -> Project...
  3. In the middle list of the New Project dialog box, click Console App (.NET Framework)
  4. Change the project Name to GeorgetownDryCleaningServices7
  5. Click OK
  6. In the Solution Explorer, right-click Program.cs -> Rename
  7. Type CleaningOrder to get CleaningOrder.cs, and press Enter
  8. In the Solution Explorer, right-click ClearningOrder -> Open
  9. Change the document as follows:
    using System;
    
    namespace GeorgetownDryCleaningServices7
    {
        public class CleaningOrder
        {
            public static int Main(string[] args)
            {
                // Price of items
                const double PriceOneShirt = 1.25;
                const double PriceAPairOfPants = 2.15;
                const double PriceOtherItem = 3.45;
                const double TaxRate = 5.75;  // 5.75%
    
                // Basic information about an order
                string customerName, homePhone;
                DateTime orderDate = new DateTime();
                DateTime orderTime = new DateTime();
                // Unsigned numbers to represent cleaning items
                ushort numberOfShirts = 0, numberOfPants = 0, numberOfOtherItems = 0;
                // Each of these sub totals will be used for cleaning items
                double subTotalShirts, subTotalPants, subTotalOtherItems;
                // Values used to process an order
                double totalOrder, taxAmount, salesTotal;
                double amountTended = 0, moneyChange;
    
                Console.Title = "Georgetown Dry Cleaning Services";
    
                Console.WriteLine("===============================================");
                Console.WriteLine("-/-    Georgetown Dry Cleaning Services     -/-");
                Console.WriteLine("===============================================");
                // Request order information from the user
                Console.Write("Enter Customer Name:                ");
                customerName = Console.ReadLine();
                Console.Write("Enter Customer Phone:               ");
                homePhone = Console.ReadLine();
                Console.Write("Enter the order date (mm/dd/yyyy):  ");
                try
                {
                    orderDate = DateTime.Parse(Console.ReadLine());
                }
                catch (FormatException fexc)
                {
                    Console.BackgroundColor = ConsoleColor.DarkBlue;
                    Console.ForegroundColor = ConsoleColor.Cyan;
                    Console.WriteLine(fexc.Message);
                }
    
                Console.ResetColor();
    
                Console.Write("Enter the order time (HH:MM):       ");
                try
                {
                    orderTime = DateTime.Parse(Console.ReadLine());
                }
                catch (FormatException fexc)
                {
                    Console.BackgroundColor = ConsoleColor.DarkBlue;
                    Console.ForegroundColor = ConsoleColor.Cyan;
                    Console.WriteLine(fexc.Message);
                }
    
                Console.ResetColor();
    
                // Request the quantity of each category of items
                try
                {
                    Console.Write("Number of Shirts:                   ");
                    numberOfShirts = ushort.Parse(Console.ReadLine());
                }
                catch (FormatException)
                {
                    Console.WriteLine("The value you typed for the number of " +
                              "shirts is not a valid number.");
                }
    
                try
                {
                    Console.Write("Number of Pants:                    ");
                    numberOfPants = ushort.Parse(Console.ReadLine());
                }
                catch (FormatException)
                {
                    Console.WriteLine("The value you typed for the number of " +
                              "pants is not a valid number.");
                }
    
                try
                {
                    Console.Write("Number of Other Items:              ");
                    numberOfOtherItems = ushort.Parse(Console.ReadLine());
                }
                catch (FormatException)
                {
                    Console.WriteLine("The value you typed for the number of " +
                              "other types of items is not a valid number.");
                }
    
                // Perform the necessary calculations
                subTotalShirts = numberOfShirts * PriceOneShirt;
                subTotalPants = numberOfPants * PriceAPairOfPants;
                subTotalOtherItems = numberOfOtherItems * PriceOtherItem;
                // Calculate the "temporary" total of the order
                totalOrder = subTotalShirts + subTotalPants + subTotalOtherItems;
    
                // Calculate the tax amount using a constant rate
                taxAmount = totalOrder * TaxRate / 100.00;
                // Add the tax amount to the total order
                salesTotal = totalOrder + taxAmount;
    
                Console.WriteLine("----------------------------------------------");
                // Communicate the total to the user...
                Console.WriteLine("The Total order is:                 {0:C}", salesTotal);
                // and request money for the order
                try
                {
                    Console.Write("Amount Tended?                      ");
                    amountTended = double.Parse(Console.ReadLine());
                }
                catch (FormatException)
                {
                    Console.WriteLine("You were asked to enter an amount of money but something bad happened.");
                }
    
                // Calculate the difference owed to the customer
                // or that the customer still owes to the store
                moneyChange = amountTended - salesTotal;
    
                Console.Clear();
                Console.Title = "Georgetown Dry Cleaning Services";
    
                // Display the receipt
                Console.WriteLine("=========================================");
                Console.WriteLine("-/- Georgetown Dry Cleaning Services -/-");
                Console.WriteLine("=========================================");
                Console.WriteLine("Customer:   {0}", customerName);
                Console.WriteLine("Home Phone: {0}", homePhone);
                Console.WriteLine("Order Date: {0:D}", orderDate);
                Console.WriteLine("Order Time: {0}", orderTime.ToShortTimeString());
                Console.WriteLine("-----------------------------------------");
                Console.WriteLine("Item Type    Qty Unit/Price Sub-Total");
                Console.WriteLine("-----------------------------------------");
                Console.WriteLine("Shirts{0,9}     {1:C}     {2:C}",
                          numberOfShirts, PriceOneShirt, subTotalShirts);
                Console.WriteLine("Pants{0,10}     {1:C}     {2,6}",
                          numberOfPants, PriceAPairOfPants, subTotalPants.ToString("C"));
                Console.WriteLine("Other Items{0,4}     {1:C}     {2:C}",
                          numberOfOtherItems, PriceOtherItem, subTotalOtherItems);
                Console.WriteLine("-----------------------------------------");
                Console.WriteLine("Total Order:     {0:C}", totalOrder);
                Console.WriteLine("Tax Rate:        {0:P}", TaxRate / 100);
                Console.WriteLine("Tax Amount:      {0:C}", taxAmount);
                Console.WriteLine("Net Price:       {0:C}", salesTotal);
                Console.WriteLine("-----------------------------------------");
                Console.WriteLine("Amount Tended:   {0:C}", amountTended);
                Console.WriteLine("Difference:      {0:C}", moneyChange);
                Console.WriteLine("=========================================");
            
                Console.ReadKey();
                return 0;
            }
        }
    }
  10. In the code, right-click the salesTotal = totalOrder + taxAmount; line (Line #109) and click Run To Cursor

    Debugging - Run to Cursor

    Make sure you can see the Code Editor, the Locals window, and the DOS window

    Debugging - Run to Cursor

  11. If necessary, click the title bar of the DOS window, type the customer name as Steve Longley and press Enter
  12. Enter the following values. Press Enter after entering each value. While you are entering them, check the moving button in the Code Editor and observe the values in the Locals window:
     
    Customer Phone: 301-208-2333
    Order Date: 10/08/2019
    Order Time: 08:14 AM
    Number of Shirts: 5
    Number of Pants: 2
    Number of Other Items: 8

    The focus moves to Microsoft Visual Studio and the Locals window:

    Locals

  13. Press F5 to continue
  14. For the amount tended, type 60 and press Enter

    Locals

    =========================================
    -/- Georgetown Dry Cleaning Services -/-
    =========================================
    Customer:   Steve Longley
    Home Phone: 301-208-2333
    Order Date: Tuesday, October 08, 2019
    Order Time: 8:14 AM
    -----------------------------------------
    Item Type    Qty Unit/Price Sub-Total
    -----------------------------------------
    Shirts        5     $1.25     $6.25
    Pants         2     $2.15      $4.30
    Other Items   8     $3.45     $27.60
    -----------------------------------------
    Total Order:     $38.15
    Tax Rate:        5.75 %
    Tax Amount:      $2.19
    Net Price:       $40.34
    -----------------------------------------
    Amount Tended:   $60.00
    Difference:      $19.66
    =========================================
  15. Press Enter to close the window and return to the programming environment

Breakpoints

A breakpoint on a line is the code where you want the exection to suspend. You must explicitly specify that line by creating a breakpoint. You can as well create as many breakpoints as you want. Also, at any time, you can remove a breakpoint you don't need anymore.

To create a breakpoint, first identify the line of code where you want to add it. Then:

A breakpoint is represented by a red circular button. After creating a breakpoint, when code executes and reaches that line, it would pause and let you know by drawing a right-pointing yellow button Breakpoint.

After using a breakpoint, you can remove it. To delete a breakpoint:

Remember that you can create more than one breakpoint. If you have more than one breakpoint in your code, execution would pause at each one of them. At any time, you can remove one or all breakpoints. To delete all breakpoints, on the main menu, click Debug -> Delete all Breakpoints.

Practical LearningPractical Learning: Using Breakpoints

  1. In the Code Editor, click the margin on the left side of subTotalOtherItems = numberOfOtherItems * PriceOtherItem;

    Inserting a Breakpoint

  2. On the main menu, click Debug -> Start Debugging.
    Notice that the DOS window displays

    Inserting a Breakpoint

  3. When asked, enter the values as follows and press Enter after each
     
    Customer Name: Hermine Simms
    Customer Phone: 410-573-2031
    Order Date: 10/08/2019
    Order Time: 09:22 AM
    Number of Shirts: 3
    Number of Pants: 3
    Number of Other Items: 12

    The focus moves back to Microsoft Visual Studio

    Locals

  4. Press F5 to continue

    Locals

  5. For the amount tended, type 100 and press Enter

    Locals

  6. Press Enter to close the window and return to your programming enviromment
  7. In the code, click the Console.Write("Number of Shirts: "); line
  8. On the main menu, click Debug -> Toggle Breakpoint
  9. In the code, right-click the salesTotal = totalOrder + taxAmount; line, position the mouse on Breakpoint, and click Insert Breakpoint

    Inserting Breakpoints

  10. To start debugging, press F5
  11. When asked, enter the values as follows and press Enter after each
     
    Customer Name: Ginette Rhoads
    Customer Phone: 301-217-9494
    Order Date: 11/06/2019
    Order Time: 02:07 PM

    The focus moves back to Microsoft Visual Studio

    Inserting Breakpoints

  12. Press F5 to continue
  13. When asked, enter the values as follows and press Enter after each
     
    Number of Shirts: 0
    Number of Pants: 2
    Number of Other Items: 0

    The focus moves back to Microsoft Visual Studio

    Inserting Breakpoints

  14. Press F5 to continue
  15. For the amount tended, type 20 and press Enter

    Inserting Breakpoints

  16. Press Enter to close the windows and return to your programming environment

Stepping to Breakpoints

You can combine the Step Into and/or the Step Over features with breakpoints. That is, you can examine each code line after line until you get to a specific line. This allows you to monitor the values of variables and see their respective values up to a critical section. To do this, first create one or more breakpoints, then proceed with steps of your choice.

Practical LearningPractical Learning: Stepping to Breakpoints

  1. Make sure the previous two breakpoints are still selected.
    To start debugging, on the main menu, click Debug -> Step Into.
    Make sure you can see the Code Editor, the Locals window, and the DOS window

    Inserting Breakpoints

  2. Press F11 continually until the DOS window receives focus
  3. Press F11 continuously (3 times) until your are prompted for the customer name
  4. For the customer name, type James Sandt and press Enter

    Inserting Breakpoints

  5. Press F11 twice to continue
  6. For the customer phone, type 301-870-7454 and press Enter
    The focus moves back to Microsoft Visual Studio

    Inserting Breakpoints

  7. Press F11 3 times to continue
  8. For the order date, type 10/10/2019 and press Enter

    Inserting Breakpoints

  9. Press F11 continously. Check the movements in the Code Editor and the rows in the Locals window. Keep pressing F11 until you are asked to type the order time
  10. For the order time, type 18:02 and press Enter

    Inserting Breakpoints

  11. Press F11 continuously. Check the movements in the Code Editor and the rows in the Locals window. Keep pressing F11 until the next prompt in the DOS window
  12. For the number of shirts, enter 8 and press Enter

    Inserting Breakpoints

  13. Press F11 to continuously. Check the movements in the Code Editor and the rows in the Locals window. Keep pressing F11 until the next prompt in the DOS window
  14. For the number of pants, enter 2 and press Enter
  15. Press F11 to continue
  16. For the number of other items, enter 12 and press Enter
  17. Press F11 continuously until the DOS window receives focus
  18. For the amount tended, type 60 and press Enter
  19. Continue pressing F11 to the end

    Inserting Breakpoints

    =========================================
    -/- Georgetown Dry Cleaning Services -/-
    =========================================
    Customer:   James Sandt
    Home Phone: 301-870-7454
    Order Date: Thursday, October 10, 2019
    Order Time: 6:02 PM
    -----------------------------------------
    Item Type    Qty Unit/Price Sub-Total
    -----------------------------------------
    Shirts        8     $1.25     $10.00
    Pants         2     $2.15      $4.30
    Other Items  12     $3.45     $41.40
    -----------------------------------------
    Total Order:     $55.70
    Tax Rate:        5.75 %
    Tax Amount:      $3.20
    Net Price:       $58.90
    -----------------------------------------
    Amount Tended:   $60.00
    Difference:      $1.10
    =========================================
  20. Press F11 three times to close the window and retun to your programming environment
  21. Close your programming environment

Debugging and Separate Files

Introduction

As you know already, a program can use many files, some files come from the .NET Framework, some are created by Microsoft Visual Studio when you start a project, and you create the others as you judge them necessary for your project. As a result, when debugging, you can consider files that are linked at one time or another. The process of debugging is primarily the same. You just have to keep in mind that you are dealing with many classes and probably different files. This has some consequences on the results you see.

Practical LearningPractical Learning: Debugging With a Class

  1. Start Microsoft Visual C#
  2. To start a new project, on the main menu, click File -> New -> Project...
  3. In the middle list, click Empty Project (.NET Framework)
  4. Change the Name to Exercise3
  5. Click OK
  6. To create a class, in the Solution Explorer, right-click Exercise3 -> Add -> Class...
  7. In the middle list, make sure Class is selected.
    Type Exercise as the name of the class/file
  8. Click Add
  9. Change the class as follows:
    using System;
    
    namespace Exercise1
    {
        public class Exercise
        {
            public void Display()
            {
                Console.WriteLine("Welcome to the wonderfule world of C#!");
            }
        }
    }

Debugging and the Main Function of a Program

As you know already, the starting point of a C# application is the Main() method (in C#, that would be a class that contains a method named Main). If you start debugging an application that uses many code files (files that contain classes), the debugger must first identify the file that contains the Main() method. If you are debugging a regular console application but the debugger cannot find a file that contains the Main() method, you would receive an error, indicating that your project does not contain an entry point.

Practical LearningPractical Learning: Checking the Presence of a Main Method

  1. On the main menu, click Debug -> Start Without Debugging
  2. When you receive an error message box, click No and notice the message in the Error List window
    Severity	Code	Description	Project	File	Line	Suppression State
    Error	CS5001	Program does not contain a static 'Main' method suitable for an entry point	Exercise1	C:\Users\pkatts\Source\Repos\Consoles\Exercise1\Exercise1\CSC	1	Active
  3. On the main menu, click Debug -> Step Into
  4. Read the error message box and click No. Notice that you receive an error:
    Severity	Code	Description	Project	File	Line	Suppression State
    Error	CS5001	Program does not contain a static 'Main' method suitable for an entry point	Exercise1	C:\Users\pkatts\Source\Repos\Consoles\Exercise1\Exercise1\CSC	1	Active

Using Separate Files

Instead of just one class or one file, we have learned, and will continue learning, that, to organize your project, you can create the classes of your project in different files. When you debug a project that uses different classes or files that contain classes, the debugger is aware of the objects and where they are created. As we will learn later, there are various windows that assist you with identifying the objects of your project. As a result, the tools such as the Locals window display their contents accordingly.

When debugging a project that uses many code files or contains many classes, when the debugging focuses on a certain variable, if the variable is a structure or a class, an arrow icon appears to its left, indicating that it has members that are fields or properties. Here is an example:

Debugging

In this case, to show the variables, that is, to expand the node, click the arrow icon. This would show the fields under the variable name and the name of the class between curly brackets under the Value column:

Practical LearningPractical Learning: Introducing Class Debugging

  1. On the main menu, click File -> New -> Project...
  2. In the middle list, click Console App (.Net Framework)
  3. Change the Name to WattsALoan3
  4. Click OK
  5. To create a class, in the Solution Explorer, right-click WattsALoan3 -> Add -> Class...
  6. In the middle list, make sure Class is selected.
    Type Customer as the name of the class/file
  7. Click Add
  8. Change the class as follows:
    namespace WattsALoan3
    {
        public class Customer
        {
            public string FullName    { get; set; }
            public string PhoneNumber { get; set; }
    
            public Customer(string name = "John Doe", string phone = "000-000-0000")
            {
                FullName    = name;
                PhoneNumber = phone;
            }
        }
    }
  9. To create a new class, in the Solution Explorer, right-click WattsALoan3 -> Add -> Class...
  10. Type Employee as the name of the class
  11. Click Add
  12. Change the class as follows:
    namespace WattsALoan3
    {
        public class Employee
        {
            public long   EmployeeNumber { get; set; }
            public string FirstName      { get; set; }
            public string LastName       { get; set; }
            public string Title          { get; set; }
    
            public Employee(long emplNbr = 0,
                            string fName = "Unknown",
                            string lName = " Not Specified",
                            string position = "Loan Specialist")
            {
                LastName       = lName;
                FirstName      = fName;
                EmployeeNumber = emplNbr;
                Title          = position;
            }
    
            public string GetEmployeeName()
            {
                return LastName + ", " + FirstName;
            }
        }
    }
  13. On the main menu, click Project -> Add Class...
  14. Type LoanInformation
  15. Click Add
  16. Change the document ase follows:
    namespace WattsALoan3
    {
        public class LoanInformation
        {
            public double Principal      { get; set; }
            public double InterestRate   { get; set; }
            public double Period         { get; set; }
            public double InterestAmount { get; set; }
            public double FutureValue    { get; set; }
        }
    }
  17. In the Solution Explorer, right-click WattsALoan3 -> Add -> Class...
  18. Type LoanEvaluation as the name of the class
  19. Press Enter
  20. Change the class as follows:
    using static System.Console;
    
    namespace WattsALoan3
    {
        public class LoanEvaluation
        {
            private Employee clerk;
            private Customer client;
            private LoanInformation loan;
    
            public LoanEvaluation()
            {
                clerk = new Employee();
                client = new Customer();
                loan = new LoanInformation();
            }
    
            public void IdentifyEmployee()
            {
                WriteLine("Enter the following pieces of information " +
                                  "about the employee who prepared this loan.");
                Write("Employee #: ");
                clerk.EmployeeNumber = long.Parse(ReadLine());
                Write("First Name: ");
                clerk.FirstName = ReadLine();
                Write("Last Name:  ");
                clerk.LastName = ReadLine();
                Write("Title:      ");
                clerk.Title = ReadLine();
            }
    
            public void IdentifyCustomer()
            {
                WriteLine("Enter the following pieces of information " +
                                  "about the customer for whom this loan was prepared.");
                Write("Customer Name: ");
                client.FullName = ReadLine();
                Write("Phone Number:  ");
                client.PhoneNumber = ReadLine();
            }
    
            public void GetLoanValues()
            {
                WriteLine("Enter the following pieces of information " +
                                  "about the values used for the loan.");
    
                Write("Enter the principal: ");
                loan.Principal = double.Parse(ReadLine());
    
                Write("Enter the interest rate: ");
                loan.InterestRate = double.Parse(ReadLine()) / 100;
    
                Write("Enter the number of months: ");
                loan.Period = double.Parse(ReadLine()) / 12;
            }
    
            public void Show()
            {
                loan.InterestAmount = loan.Principal * loan.InterestRate * loan.Period;
                loan.FutureValue = loan.Principal + loan.InterestAmount;
    
                WriteLine("======================================");
                WriteLine("Loan Summary");
                WriteLine("=------------------------------------=");
                WriteLine("Prepared by:  {0} - {1}\n              {2}",
                                  clerk.EmployeeNumber,
                                 clerk.GetEmployeeName(), clerk.Title);
                WriteLine("=------------------------------------=");
                WriteLine("Prepared for: {0}\n              {1}",
                                  client.FullName, client.PhoneNumber);
                WriteLine("=------------------------------------=");
                WriteLine("Principal:       {0:F}", loan.Principal);
                WriteLine("Interest Rate:   {0:P}", loan.InterestRate);
                WriteLine("Period For:      {0} months", loan.Period * 12);
                WriteLine("Interest Amount: {0:F}", loan.InterestAmount);
                WriteLine("Future Value:    {0:F}", loan.FutureValue);
                WriteLine("======================================");
            }
        }
    }
  21. In the Solution Explorer, right-click Program.cs and click Rename
  22. Type WattsALoan to get WattsALoan.cs, and press Enter
  23. Read the text in the message box and click Yes
  24. Click the WattsALoan.cs tab to access it and change its document as follows:
    using static System.Console;
    
    namespace WattsALoan3
    {
        public class WattsALoan
        {
            public static int Main(string[] args)
            {
                LoanEvaluation evaluation = new LoanEvaluation();
    
                Title = "Watts A Loan?";
    
                WriteLine("This application allows you to evaluate a loan");
                evaluation.IdentifyEmployee();
                evaluation.IdentifyCustomer();
    
                Clear();
    
                evaluation.GetLoanValues();
    
                Clear();
    
                evaluation.Show();
                return 0;
            }
        }
    }
  25. To start debugging, press F11.
    If you don't see the Locals window, to display it, on the main menu, click Debug -> Window -> Locals
  26. Move the windows to make sure you can see the Code Editor, the Locals window, and the DOS window

    Debugging - Stepping Into

  27. Notice that the debugging yellow arrow indicator is positioned on the left of the opening curly bracket of the Main() method.
    Notice that at this time, the Locals window contains only the evaluation variable whose value is null.
    At this time, the DOS window shows a blinking caret
  28. To continue debugging, on the main menu, click Debug -> Step Into. Check what line is currently active in the WattsALoan.cs document
  29. Again, on the main menu, click Debug -> Step Into.
    Notice that the debugger is in the constructor of the LoanEvaluation class in the LoanEvaluation.cs file

    Debugging - Stepping Into

  30. In the Locals window, click the right-pointing arrow button of the this object to expand it. Notice that it show the global variables of the class

  31. To continue debugging, on the Standard toolbar, click the Step Into button Step Into three times.
    Notice that the excution switches to the constructor of the Employee class in the Employee.cs file

    Debugging - Stepping Into

  32. In the Locals window, click the right-point arrow button of the this object to expand it
    Tab Order
  33. To continue debugging, press F11 three times. Each time, observe the yellow arrow button the Code Editor, the rows in the Locals window, and the Diagnostics Tools window. You may receive a message box:

    Debugging - Stepping Into

    If you receive a message box, read it and click Yes. Check the current contents of the Locals window:

    Debugging - Stepping Into

  34. Keep pressing F11. If the message box comes up, read it and click Yes. Each time, observe the selection in the Code Editor. Observe the rows in the Locals window. Observe the evaluations in the Diagnostics Tools window. Continue until the debugging moves back to the LoanEvaluation class and on the clerk = new Employee(); line
  35. Press F11 and notice that the debugger moves to the client variable
  36. Press F11 and notice that the focus has moved to the Customer constructor of the Customer class in the Customer.cs file

    Debugging - Stepping Into

  37. Press F11 six times. Observe the different window, until the debugger moves back to the client variable in the LoanEvaluation constructor
  38. Press F11 three times.
    The debugging returns to the evaluation variable in the Main() method of the WattsALoan.cs document
  39. Press F11 two three times.
    Notice that the title bar of the DOS window has changed
  40. In the Locals window, click all the right-point arrow button of the evaluation variable to show the current values of the variables for the Employee, the Customer, and the LoanInformation variables
  41. Keep pressing F11 until the title bar of the DOS window indicates that it has focus and you are asked to enter an employee number
  42. When asked for an employee number, type 20584 and press Enter.
    If a message box comes up, read it and click Yes
  43. The focus moves back to the Code Editor. In the Locals window, expand the this object and the clerk node.
    Notice that the value of the employee number has changed in the Locals window

    Debugging - Stepping Into

    Press F11 twice.
    The focus moves back to the DOS window
  44. For the First Name, type Joshua and press Enter. If a message box comes up, read it and click Yes
  45. The focus moves back to the Code Editor.
    Press F11 twice.
    The focus moves back to the DOS window

    Debugging - Stepping Into

  46. For the Last Name, type Mahmouda and press Enter. If a message box comes up, read it and click Yes
  47. The focus moves back to the Code Editor.
    Press F11 twice.
    The focus moves back to the DOS window
  48. For the Title, type Accounts Representative and press Enter. If a message box comes up, read it and click Yes

    Debugging - Stepping Into

  49. The focus moves back to the Code Editor.
    Press F11 and notice that the debugger moves to the evaluation.IdentifyEmployee(); line
  50. Press F11 twice to move the debugger to the IdentifyCustomer() method
  51. Press F11 three times (observe the selections in the Code Editor and the evaluation in the Diagnostics Tools window) until the focus moves to the DOS window
  52. When asked to provide a customer name, type Lauren Sachs and press Enter. If a message box comes up, read it and click Yes
  53. The focus moves back to the Code Editor.
    In the Locals window, expand this and expand the client node
  54. Press F11 twice.
    The focus moves back to the DOS window
  55. For the Phone Number, type (301) 438-6243 and press Enter. If a message box comes up, read it and click Yes

    Debugging - Stepping Into

  56. The focus moves back to the Code Editor.
    Press F11 to move to the evaluation.IdentifyCustomer(); line
  57. Press F11 a few times (7) until the DOS window receives focus
  58. For the value of the principal, type 24750 and press Enter. If a message box comes up, read it and click Yes
  59. The focus moves to the Code Editor.
    In the Locals window, expand this and expand loan. Notice that the value of the principal has changed
  60. Press F11 to move the debugger to the loan.InterestRate = double.Parse(ReadLine()) / 100; line
  61. Press F11 again to move focus to the DOS window
  62. In the DOS window, when you are asked to provide the interest rate, type 11.35 and press Enter. If a message box comes up, read it and click Yes
  63. Press F11 to move focus to the loan.Period = double.Parse(ReadLine()) / 12; line
  64. Press F11 again to move the debugging to the DOS window
  65. In the DOS window, for the number of months, type 60 and press Enter. If a message box comes up, read it and click Yes
  66. Keep pressing F11. Every time a message box comes up, read it and click Yes.
    Observe the selected lines in the Code Editor and the values in the Locals window. Observe the new lines in the DOS window

    Debugging - The Locals window

  67. Continue pressing F11 until the summary has displayed:
    ======================================
    Loan Summary
    =------------------------------------=
    Prepared by:  20584 - Mahmouda, Joshua
                  Accounts Representative
    =------------------------------------=
    Prepared for: Lauren Sachs
                  (301) 438-6243
    =------------------------------------=
    Principal:       24750.00
    Interest Rate:   11.35 %
    Period For:      60 months
    Interest Amount: 14045.63
    Future Value:    38795.63
    ======================================
  68. Keep pressing F11 until the DOS window closes
  69. Cloee your programming environment

Previous Copyright © 2010-2019, FunctionX Next