Answer to Question #280107 in C# for Jay

Question #280107
  1. Create two (2) overloaded methods that display a greeting message and use first name and last name as its parameters.
  2. Write two (2) overloaded methods that will compute the total price of an item. Use the total item and price as parameters, which are both floating-point numbers.
1
Expert's answer
2021-12-16T11:52:07-0500
using System;
using System.Collections.Generic;


namespace App
{


    class Program
    {
        public static void Main()
        {
            Console.Write("Enter the first name: ");
            string firstName = Console.ReadLine();
            Console.Write("Enter the last name: ");
            string lastName = Console.ReadLine();


            displayGreetingMessage(firstName +" "+ lastName);
            displayGreetingMessage(firstName, lastName);




            Console.Write("Enter the total items: ");
            float totalItems = float.Parse(Console.ReadLine());
            Console.Write("Enter the price: ");
            float price = float.Parse(Console.ReadLine());




            Console.WriteLine("The total price of an item (price = 10): {0}", computeTotalPriceItem(totalItems));
            Console.WriteLine("The total price of an item (price = {0}): {1}", price, computeTotalPriceItem(totalItems, price));


            Console.ReadLine();
        }


        private static void displayGreetingMessage(string fullName)
        {
            Console.WriteLine("Welcome, {0}", fullName);
        }


        private static void displayGreetingMessage(string firstName, string lastName)
        {
            Console.WriteLine("Welcome, {0} {1}", firstName, lastName);
        }




        public static float computeTotalPriceItem(float totalItems)
        {
            return totalItems * 10.0f;
        }


        public static float computeTotalPriceItem(float totalItems, float price)
        {
            return totalItems * price;
        }




    }
}

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
APPROVED BY CLIENTS