Answer to Question #332776 in C# for Princess

Question #332776

You will continue working on the application created in Part 1. Implement the feedback provided by your lecturer on Part 1 before continuing with Part 2. Marks will be awarded for this (10%).



The application must still perform all the functions from Part 1, with the following features added: 1.



The user shall be able to choose whether to buy a vehicle.



2.



If the user selects to buy a vehicle, the user shall be required to enter the following values



for vehicle financing:



a. Model and make. b. Purchase price.



c. Total deposit.



d. Interest rate (percentage).



e. Estimated insurance premium.



3.



The software shall calculate the total monthly cost of buying the car (insurance plus loan



repayment). Assume that all cars will be repaid over a period of five years.



4. The software shall notify the user when the total expenses exceed 75% of their income,



including loan repayments.



Display the expenses to the user in descending order by value.

1
Expert's answer
2022-04-23T18:13:41-0400
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;


class Program
{
    static void Main()
    {
        Dictionary<string, decimal> budget = new Dictionary<string, decimal>();


        decimal monthlyIncome = Read("Enter monthly income: ");
        decimal monthlyTax = Read("Enter estimated montly tax: ");
        decimal groceries = Read("Enter estimated monthly expenditures for groceries: ");
        decimal water = Read("Enter estimated monthly expenditures for water: ");
        decimal lights = Read("Enter estimated monthly expenditures for lights: ");
        decimal traveling = Read("Enter estimated monthly expenditures for traveling: ");
        decimal other = Read("Enter other expenses: ");


        decimal income = monthlyIncome - monthlyTax;
     
        budget.Add("Groceries", groceries);
        budget.Add("Water", water);
        budget.Add("Lights", lights);
        budget.Add("Traveling", traveling);
        budget.Add("Other", other);


        Console.WriteLine("Do you wanna buy a vehicle? Y/N");
        if (Console.ReadLine().ToLower() == "y")
        {
            decimal price = Read("Enter price of vehicle: ");
            decimal deposit = Read("Enter total deposit: ");
            decimal interestRate = Read("Enter interest rate(%): ");
            decimal insurance = Read("Enter price of insurance: ");


            decimal pricePerMonth = price * interestRate / 100 / (5 * 12) + (5 * insurance) + deposit;


            budget.Add("Car", pricePerMonth);
            Console.WriteLine($"Your income per months: {income}");
            Console.WriteLine(string.Join("\n", budget.OrderByDescending(x => x.Value).Select(x => $"{x.Key}: {x.Value}")));


            if (pricePerMonth > (income / 3 * 4))
            {
                Console.WriteLine("This car is too exspensive!");
            }
        }
    }


    private static decimal Read(string message)
    {
        Console.Write(message);
        return decimal.Parse(Console.ReadLine());
    }

}

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