Answer to Question #289322 in C# for Kayla

Question #289322

Create a Date class with integer data members for year, month, and day. Also include a string data member for the name of the month. Include a method that returns the month name (as a string) as part of the date. Separate the day from the year with a comma in that method. Include appropriate constructors, properties, and methods. Override the ToString() method to display the date formatted with slashes (7) separating the month, day, and year. Create a second class that instantiates and test the Date class.

1
Expert's answer
2022-01-21T08:24:12-0500


using System;
using System.Collections.Generic;
using System.Globalization;


namespace App
{
    class Date
    {
        private int year;


        public int Year
        {
            get { return year; }
            set { year = value; }
        }
        private int month;


        public int Month
        {
            get { return month; }
            set { month = value; }
        }
        private int day;


        public int Day
        {
            get { return day; }
            set { day = value; }
        }




        public Date() { }


        public Date(int year, int month, int day)
        {
            this.year = year;
            this.month = month;
            this.day = day;
        }


        public override string ToString()
        {
            return month.ToString() + "/" + day.ToString() + "/" + year.ToString();
        }
        public string getNameOfMonth()
        {
            string monthName = new DateTime(year, month, day).ToString("MMM", CultureInfo.InvariantCulture);
            return day.ToString() + "," + year.ToString() + "," + monthName;
        }
    }




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


            Date newDate = new Date(2020,5,4);
            Console.WriteLine(newDate.ToString());
            Console.WriteLine(newDate.getNameOfMonth());


            
            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