Answer to Question #333713 in C# for DOHC 44

Question #333713

If the monthly home loan repayment is more than a third of the user’s gross monthly


income, the software shall alert the user that approval of the home loan is unlikely.


7. The software shall calculate the available monthly money after all the specified deductions


have been made.


8. The software shall not persist the user data between runs. The data shall only be stored in


memory while the software is running.


Non-functional requirements:


1. You are required to use internationally acceptable coding standards. Include


comprehensive comments explaining variable names, methods, and the logic of


programming code.


2. You are required to use classes and inheritance. Create an abstract class Expense, from


which HomeLoan, etc., can be derived.


3. Store the expenses in an array

1
Expert's answer
2022-04-25T16:59:16-0400
using System;
using System.Linq;


class Program
{
    static void Main()
    {
        Console.Write("Enter your payment ater the tax: ");
        decimal payment = decimal.Parse(Console.ReadLine());


        Expense[] expenses = new Expense[]
        {
            new HomeLoan("Home Loan", 2000),
            new WaterBill("Water Bill", 200),
            new ElectricBill("Electric Bill", 500)
        };


        decimal freeMoney = payment - expenses.Sum(x => x.Costs);


        Console.WriteLine($"Payment: {payment:C}");
        Console.WriteLine(string.Join("\n", expenses.Select(x => x.ToString())));
        Console.WriteLine($"Free money: {freeMoney:C}");
    }
}


abstract class Expense
{
    public string Name { get; private set; }
    public decimal Costs { get; private set; }


    public Expense(string name, decimal costs)
    {
        Name = name;
        Costs = costs;
    }


    public override string ToString()
    {
        return $"{Name}: {Costs:C}";
    }
}


internal class HomeLoan : Expense
{
    public HomeLoan(string name, decimal costs): base(name, costs)
    {


    }
}


class ElectricBill: Expense
{
    public ElectricBill(string name, decimal costs) : base(name, costs)
    {


    }
}


class WaterBill: Expense
{
    public WaterBill(string name, decimal costs) : base(name, costs)
    {


    }
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS