Answer to Question #261324 in C# for Anino

Question #261324

Write a C# program to do help manage your credit card debt. The Main method is to repeatedly prompt the user to enter a transaction code (char) which could be ‘B’ or ‘b’ to buy an item using the credit card, ‘c’ or ‘C’ to make a cash withdrawal from the credit card, ‘p’ or ‘P’ to make a payment on the credit card, ‘D’ or ‘d’ to display the balance of the credit card, and ‘q’ or ‘Q’ to quit. the initial balance on card is $0.00.Using a switch statement in the do-while loop on Main, select the appropriate action and call (invoke) the appropriate user-defined method. The Main method should continue accepting

transactions until the user enters a ‘Q’ or ‘q’.(i) A method call ReadAmount which takes no formal parameters but returns a positive value of type double which is the cost of an item, the amount of cash withdrawn, or amount payment.ReadAmount is to be called by Main() when the user chooses to buy an item (B’ or‘b’),withdrawal cash (‘c’ or ‘C’), or make a payment (‘p’ or ‘P’).The ReadAmount should be positive


1
Expert's answer
2021-11-05T00:33:48-0400
using System;


namespace Questions
{
    class Program
    {
        static double ReadAmount()
        {
            double amount;
            do
            {
                Console.Write("amount = ");
                amount = double.Parse(Console.ReadLine());
            } while (amount <= 0);


            return amount;
        }
        static double BuyItem(double balance)
        {
            double amount = ReadAmount();
            if (balance >= amount)
                balance -= amount;
            else
                Console.WriteLine("You don't have enough money for buying");
            return balance;
        }
        static double CashWidthdrawal(double balance)
        {
            double amount = ReadAmount();
            if (balance >= amount)
                balance -= amount;
            else
                Console.WriteLine("You don't have enough money for cash widthdrawal");
            return balance;
        }
        static double MakePayment(double balance)
        {
            double amount = ReadAmount();
            balance += amount;
            return balance;
        }
        static void DisplayBalance(double balance)
        {
            Console.WriteLine("Balance: ${0}", balance.ToString("0.00"));
        }
        static void Main()
        {
            char transactionCode;
            double initialBalance = 0;
            do
            {
                Console.WriteLine("Select a transaction\n");
                Console.WriteLine("Buy an item (B/b)");
                Console.WriteLine("Make a cash widthdrawal (C/c)");
                Console.WriteLine("Make a payment (P/p)");
                Console.WriteLine("Display the balance (D/d)");


                Console.Write("\nYour choice: ");
                transactionCode = Console.ReadLine().ToLower()[0];


                switch(transactionCode)
                {
                    case 'b':
                        initialBalance = BuyItem(initialBalance);
                        break;


                    case 'c':
                        initialBalance = CashWidthdrawal(initialBalance);
                        break;


                    case 'p':
                        initialBalance = MakePayment(initialBalance);
                        break;


                    case 'd':
                        DisplayBalance(initialBalance);
                        break;
                }
                Console.WriteLine("\n");


            } while (!transactionCode.Equals('q'));


            Console.WriteLine();
            Console.ReadKey();
        }
    }


}

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