Breakpoints and Objects
Breakpoints and Objects
Breakpoints with Objects and Files
Introduction
In the previous sections, we created all our breakpoints in one source file. 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.
Breakpoints and Classes
Practical Learning: Debugging With a Class
namespace WattsALoan02.Models
{
internal class Customer
{
public string fullName;
public string phoneNumber;
public Customer(string name = "John Doe", string phone = "000-000-0000")
{
fullName = name;
phoneNumber = phone;
}
}
}namespace WattsALoan02.Models
{
internal class Employee
{
public long employeeNumber;
public string firstName;
public string lastName;
public string title;
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;
}
}
}namespace WattsALoan02.Models
{
internal class LoanInformation
{
public double principal;
public double interestRate;
public double period;
public double interestAmount;
public double futureValue;
}
}using WattsALoan.Models;
using static System.Console;
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("======================================");
}
}|
|
|||
| Previous | Copyright © 2010-2026, FunctionX | Monday 10 November 2025, 10:56 | Next |
|
|
|||