Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Lab 9/18 The purpose of todays lab is to work with classes. You will redo the 8/30 lab using a class to organize the data

Lab 9/18

The purpose of todays lab is to work with classes. You will redo the 8/30 lab using a class to organize the data about a loan and the methods concerning the loan.

image text in transcribedimage text in transcribedHERE IS MY CODE THUS FAR:

LOAN.CS -

using static System.Console; using System;

namespace LoanCalculator { class Loan // Represents compound interest loan { // Define properties with getters // Once object is created, property values cannot be changed public double annualInterestRate { get; } public double initialBalance { get; } public int numberOfYearsInTerm { get; }

public int CustomerID { get; }

// Constructor. Initialize three properties public Loan(double annualInterestRate, double initialBalance, double numberOfYearsInTerm) { annualInterestRate = 0.12; initialBalance = 1000.00; numberOfYearsInTerm = 25; }

// Return the monthly payment for the loan public double getMonthlyPayment() // Takes no parameters { // Compute monthly payment with property values double p = initialBalance; double r = annualInterestRate / 12; int n = numberOfYearsInTerm * 12; double c;

c = (p * r) / (1 - (Math.Pow((1 + r), -n)));

return c;

//double getMonthlyPayment = ((initialBalance * (annualInterestRate / 12)) / (1 - (Math.Pow((1 + (annualInterestRate / 12)), (numberOfYearsInTerm * 12))))); //return getMonthlyPayment; }

// Compute the balance on the loan at the end of month (monthNumber) after interest has been added and payment subtracted. Return the amount. // Call the method above to get the monthly payment and then use the class properties to compute the balance public double getBalanceAfterMonth() // Takes 1 parameter { //double monthlypayment = getMonthlyPayment(); //int monthnumber = getBalanceAfterMonth; double p = initialBalance; double r = annualInterestRate / 12; double c = getMonthlyPayment(); int i = numberOfYearsInTerm * 12; double d;

d = (p - (c / r)) * Math.Pow((r + 1), i) + (c / r); return d;

//return monthlypayment; } } }

PROGRAM.CS -

using static System.Console; using System;

namespace LoanCalculator { class Program { static void Main(string[] args)

//static void runExample(double annualInterestRate, double initialBalance, int numberOfYearsInTerm) { // Declare and initialize variables /*annualInterestRate = 0.12; initialBalance = 1000.00; numberOfYearsInTerm = 25; int monthNumber = numberOfYearsInTerm * 12; */

//construct p Loan p = new Loan(0.12, 1000.00, 2);

//call methods from p double o = p.getMonthlyPayment(); double d = p.getmonthNumber();

//double monthlyPayment = p.getMonthlyPayment(initialBalance, annualInterestRate, numberOfYearsInTerm); //double balanceAfterMonth = p.getBalanceAfterMonth(initialBalance, annualInterestRate, monthlyPayment, monthNumber);

// Display results WriteLine("The initial balance is " + "{0:C}" + p.initialBalance); WriteLine("The annual interest rate is " + "{0:P}" + p.annualInterestRate); WriteLine("The number of years to pay of the loan is " + p.numberOfYearsInTerm); WriteLine("The monthly payment is " + "{0:C}" + o /*monthlyPayment*/); WriteLine("Balance after the last month is " + "{0:C}" + d /* balanceAfterMonth */ + "This should be"); //Scientific notation // Value would be 0 if numberOfYears = 2 or 5

// Program won't stop until any key is pressed ReadKey();

//double run = runExample(); } } }

I'VE GOTTEN AS FAR AS I CAN MANAGE AND I'M STUCK. IT WON'T RUN. PLEASE, HELP.

Create a solution with one console application project. Name the project LoanCalculator and name the solution lab170918. Class Loan Add a class named Loan to the Loancalculator project. The class will represent a compound interest loan. It will contain these properties: AnnualInterestRate a double value InitialBalance a double value NumberOfYears Interm and integer value Define these as properties with getters but not setters. That is, once the object is created, the property values cannot be changed. A single constructor is provided, with this header: public Loan (double annualInterestRate, double initialBalance, double numberOfYearsInTerm) The constructor will initialize the three properties. Note that the parameters are spelled with lower case letters: this is to make your code a little easier to write. You may use other parameter names if you wish, but make them clear in meaning. Define a method getMonthlypayment with this header: public double getMonthlyPayment () This will return the monthly payment for the loan. Use the formula we used in an earlier lab. Add a comment just before the function header describing what the function computes. NOTE VERY IMPORTANTthe method takes no parameters. Use the property values to compute the monthly payment. Define another method getBalanceAfterMonth with this header: public double getBalanceAfterMonth(int monthNumber) This function will compute the balance on the loan at the end of month monthNumber, after interest has been added and payment subtracted, and return the amount. Add a comment just before the function header describing what the function computes

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Harness The Power Of Big Data The IBM Big Data Platform

Authors: Paul Zikopoulos, David Corrigan James Giles Thomas Deutsch Krishnan Parasuraman Dirk DeRoos Paul Zikopoulos

1st Edition

0071808183, 9780071808187

More Books

Students also viewed these Databases questions