Question

In: Computer Science

C#. Build a class that will be called “MyDate”. The class should have 3 properties: month,...

C#. Build a class that will be called “MyDate”. The class should have 3 properties: month, day and year. Make month, day and year integers. Write the get and set functions, a display function, and constructors, probably two constructors. (No Database access here.)

Solutions

Expert Solution

Application name :WorkingWithDate

Type of Application :Console Application

Language used :C#

MyDate.cs :

//namespace
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
//application namespace
namespace WorkingWithDate
{
class MyDate //C# class
{
//fields
private int month;
private int day;
private int year;
//default constructor
public MyDate()
{
month = 0;
year = 0;
day = 0;
}
//constructor with parameter
public MyDate(int d,int m,int y)
{
day = d;
month = m;
year = y;
}
//Properties/getter and setter methods
public int Day
{
set { day = value; }
get { return day; }
}
public int Month
{
set { month = value; }
get { return month; }
}
public int Year
{
set { year = value; }
get { return year; }
}
//method to display date
public String display()
{
//return day , month year in dd-mm-yyyy format
return Day + "-" + month + "-" + year;
}

}
}

**************************************************************

Program.cs :

//namespace
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
//application namesapce
namespace WorkingWithDate
{
class Program //C# class
{
//Main() method
static void Main(string[] args)
{
//Object of MyDate
MyDate d = new MyDate();
//asking user Day
Console.Write("Enter day : ");
//reading day
d.Day = int.Parse(Console.ReadLine());
//asking user month
Console.Write("Enter month : ");
//reading month
d.Month = int.Parse(Console.ReadLine());
//asking user year
Console.Write("Enter year : ");
//reading year
d.Year = int.Parse(Console.ReadLine());
//call function and display date
Console.WriteLine("Date in dd-mm-yyy format : "+d.display());
//to hold the screen
Console.ReadKey();
}
}
}

======================================

Output :


Related Solutions

Assignment 1: Build a simple class called DBTester.java. This class should have only one method, main...
Assignment 1: Build a simple class called DBTester.java. This class should have only one method, main method. In the main method you should read in all of the rows of data from the Instructors Table in the Registration Database, then print out this data. Follow the steps outlined in class. Remember to use try-catch blocks for all database access code. The example in the book does not use Try-catch blocks, but you should
In C++ Define a base class called Person. The class should have two data members to...
In C++ Define a base class called Person. The class should have two data members to hold the first name and last name of a person, both of type string. The Person class will have a default constructor to initialize both data members to empty strings, a constructor to accept two string parameters and use them to initialize the first and last name, and a copy constructor. Also include appropriate accessor and mutator member functions. Overload the operators == and...
C++ Define a base class called Person. The class should have two data members to hold...
C++ Define a base class called Person. The class should have two data members to hold the first name and last name of a person, both of type string. The Person class will have a default constructor to initialize both data members to empty strings, a constructor to accept two string parameters and use them to initialize the first and last name, and a copy constructor. Also include appropriate accessor and mutator member functions. Overload the operators == and !=...
ROCK, PAPER, SCISSORS Using C++, you will implement a class called Tool. It should have an...
ROCK, PAPER, SCISSORS Using C++, you will implement a class called Tool. It should have an int field called strength and a char field called type. You may make them either private or protected. The Tool class should also contain the function void setStrength(int), which sets the strength for the Tool. Create 3 more classes called Rock, Paper, and Scissors, which inherit from Tool. Each of these classes will need a default constructor that sets the strength to 1 and...
In C++ Create an abstract class called Shape Shape should have the following pure virtual functions:...
In C++ Create an abstract class called Shape Shape should have the following pure virtual functions: getArea() setArea() printArea() Create classes to inherit from the base class Circle Square Rectangle Both implement the functions derived from the abstract base class AND must have private variables and functions unique to them like double Radius double length calculateArea() Use the spreadsheet info.txt read in information about the circle, rectangle, or square text file: circle   3.5   square   3   rectangle   38   36 circle   23  ...
Part I – Build a Customer Business Object. This class will have 6 properties, custId, custPassword,...
Part I – Build a Customer Business Object. This class will have 6 properties, custId, custPassword, custFirstName, custLastName, custAddress and custEmail. Build an empty args Constructor in the Customer class that initializes all properties to 0 or “”. Also build a constructor that takes all 6 args and set the appropriate properties. Then build the following 3 methods:   selectDB(custID);   //to find a customer’s info in the DB             To Test the selectDB() method use this code in the main():          ...
Create a file called grocery.ts. It should have a definition of a class with the obvious...
Create a file called grocery.ts. It should have a definition of a class with the obvious name Grocery. The class should have some basic attributes such as name, quantity, etc. Feel free to add any other attributes you think will be necessary. Add few grocery items to an array of groceries, such as milk, bread, and eggs, along with some quantities (i.e. 3, 6, 11). Display these grocery items as HTML output. The output of this assignment will be grocery.ts...
C Programming build a function that is outside of main domain but can be called Build...
C Programming build a function that is outside of main domain but can be called Build a function that will : - Take 3 arrays and their lengths as input: Array 1 for even numbers, Array 2 for odd numbers. Both 1 and 2 have the same size - put all elements in array 3 elements from array 1 should be placed in the even indexes and elements of array 2 should be placed in the odd indexes, in increasing...
(java) Write a class called CoinFlip. The class should have two instance variables: an int named...
(java) Write a class called CoinFlip. The class should have two instance variables: an int named coin and an object of the class Random called r. Coin will have a value of 0 or 1 (corresponding to heads or tails respectively). The constructor should take a single parameter, an int that indicates whether the coin is currently heads (0) or tails (1). There is no need to error check the input. The constructor should initialize the coin instance variable to...
(In java language) Write an abstract class called House. The class should have type (mobile, multi-level,...
(In java language) Write an abstract class called House. The class should have type (mobile, multi-level, cottage, etc.) and size. Provide the following methods: A no-arg/default constructor. A constructor that accepts parameters. A constructor that accepts the type of the house and sets the size to 100. All other required methods. An abstract method for calculating heating cost. Come up with another abstract method of your own. Then write 2 subclasses, one for mobile house and one for cottage. Add...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT