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...
IN JAVA: Build a class called ExamPractice from scratch. This class should include a main method...
IN JAVA: Build a class called ExamPractice from scratch. This class should include a main method that does the following: Prompt the user to enter a number of inches Read the number of inches entered from the console Convert the inches into an equivalent number of miles, yards, feet, and inches. Output the results to the console. For example, if a user entered 100000 inches, the program would output: 100000 inches is equivalent to: Miles: 1 Yards: 1017 Feet: 2...
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():          ...
Write a Java class called Person. The class should have the following fields: A field for...
Write a Java class called Person. The class should have the following fields: A field for the person’s name. A field for the person’s SSN. A field for the person’s taxable income. A (Boolean) field for the person’s marital status. The Person class should have a getter and setter for each field. The Person class should have a constructor that takes no parameters and sets the fields to the following values: The name field should be set to “unknown”. The...
JAVA Specify, design, and implement a class called PayCalculator. The class should have at least the...
JAVA Specify, design, and implement a class called PayCalculator. The class should have at least the following instance variables: employee’s name reportID: this should be unique. The first reportID must have a value of 1000 and for each new reportID you should increment by 10. hourly wage Include a suitable collection of constructors, mutator methods, accessor methods, and toString method. Also, add methods to perform the following tasks: Compute yearly salary - both the gross pay and net pay Increase...
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...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT