Question

Using C#, Create a date class with integer data members for year, month, and day. Also...

Using C#, 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 string as part of the date. Separate the day from the year with comma in the method. Include appropriate constructor, properties, and methods. Override the ToString() method to display the date formatted with slashes(/) separating the month, day, and year. Create a second class that instantiates test the Date class.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

DATE CLASS:

public class Date {
private int day;
private int month;
private int year;
private String monthName;
public Date(int day, int month, int year, String monthName) {
super();
this.day = day;
this.month = month;
this.year = year;
this.monthName = monthName;
}
public int getDay() {
return day;
}
public void setDay(int day) {
this.day = day;
}
public int getMonth() {
return month;
}
public void setMonth(int month) {
this.month = month;
}
public int getYear() {
return year;
}
public void setYear(int year) {
this.year = year;
}
public String getMonthName() {
return monthName;
}
public void setMonthName(String monthName) {
this.monthName = monthName;
}
public String dateWithName() {
return monthName+" "+day+","+year;
}
@Override
public String toString() {
return month + "/"+day+"/" + year;
}

}

TEST CLASS:

public class TestDate {

public static void main(String[] args) {
Date d=new Date(31, 10, 2016, "October");
System.out.println(d);
System.out.println(d.dateWithName());
}
}

OUTPUT:

10/31/2016
October 31,2016

Add a comment
Know the answer?
Add Answer to:
Using C#, Create a date class with integer data members for year, month, and day. Also...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Programming in C# Create a Money class that has as data members dollars and cents. Include...

    Programming in C# Create a Money class that has as data members dollars and cents. Include IncrementMoney and DecrementMoney instance methods. Include constructors that enable the Money class to be instantiated with a single value representing the full dollar/cent amount as well as a constructor that enables you to create an instance of the class by sending two separate integer values representing the dollar and cent amounts. Include an instance method that returns as a string the number of dollars,...

  • Create a class called Date212 to represent a date. It will store the year, month and...

    Create a class called Date212 to represent a date. It will store the year, month and day as integers (not as a String in the form yyyymmdd (such as 20161001 for October 1, 2016), so you will need three private instance variables. Two constructors should be provided, one that takes three integer parameters, and one that takes a String. The constructor with the String parameter and should validate the parameter. As you are reading the dates you should check that...

  • In JAVA 1. Create a class called Rectangle that has integer data members named - length...

    In JAVA 1. Create a class called Rectangle that has integer data members named - length and width. Your class should have a default constructor (no arg constructor) Rectangle() that initializes the two instance variables of the object Rect1. The second overloading constructor should initializes the value of the second object Rect2. The class should have a member function named GetWidth() and GetLength() that display rectangle's length and width. OUTPUT: Rectl width: 5 Rectl length: 10 Enter a width :...

  • Using C# Create an application class named LetterDemo that instantiates objects of two classes named Letter...

    Using C# Create an application class named LetterDemo that instantiates objects of two classes named Letter and CertifiedLetter and that demonstrates all their methods. The classes are used by a company to keep track of letters they mail to clients. The Letter class includes auto-implemented properties for the Name of the recipient and the Date mailed (stored as strings). Next, include a ToString() method that overrides the Object class’s ToString() method and returns a string that contains the name of...

  • Create a class named Date in C++ Class has 3 private data items (name the data...

    Create a class named Date in C++ Class has 3 private data items (name the data items month, day, year) int month int day int year Member functions ‘getters’   a getter for each data item Use ‘get’ and the data items name The data item name must be capitalized Return the data item Example: int getMonth()        {return month;} ‘setters’   a setter for each data item Use ‘set’ and the data items name The data item name must be capitalized Change...

  • 2. Define a class named “Holiday” that manages one holiday info such as month (integer), day...

    2. Define a class named “Holiday” that manages one holiday info such as month (integer), day (integer) and name (string). For example, 7, 4 and “Independence Day” • “toString” method to return holiday info as a string in the format: holiday name (month/day). For example, “Independence Day (7/4)” • “isLater” method that compares with another Holiday object and return true if the date of the holiday is later (month and day) and false otherwise. • “getMonth” method to return the...

  • QUESTION 5 (15 Marks) Inheritance and Polymorphism Design a Ship class that has the following members:...

    QUESTION 5 (15 Marks) Inheritance and Polymorphism Design a Ship class that has the following members: • A private String data field named name for the name of the ship. • A private String data field named yearBuilt for the year that the ship was built. • A constructor that creates a ship with the specified name and the specified year that the ship was built. • Appropriate getter and setter methods. A toString method that overrides the toString method...

  • Part I: (The Myate class) Design a class named MyDate. The class contains: • The data...

    Part I: (The Myate class) Design a class named MyDate. The class contains: • The data fields year, month, and day that represent a date. Month is 0-based, i.e., 0 is for January. • A no-arg constructor that creates a MyDate object for the current date. • A constructor that constructs a MyDate object with a specified elapsed time since midnight, January 1, 1970, in milliseconds. • A constructor hat constructs a MyDate object with the specified year, month, and...

  • Write a class Date with: Three instance variable : day, month and year all of type...

    Write a class Date with: Three instance variable : day, month and year all of type int. Define the following public methods for the class Date: A constructor Date() without parameter, make the date 1-1-2000   A constructor Date(int d, int m, int y) with parameters that provide the values attributes. Include accessor methods: getDay getMonth getYear Include mutator methods: setDay: make sure that day between 1 to 30 setMonth: make sure that month between 1 to 12 setYear A method...

  • C++ program Create a class Time having data members HH, MM, SS of type integer. Write...

    C++ program Create a class Time having data members HH, MM, SS of type integer. Write a C++ program to do the following: 1. Use a Constructor to initialize HH, MM, SS to 0. 2. Create two Objects of this class and read the values of HH, MM, SS from the user for both objects (Using proper member functions). 3. Use a binary + operator to add these two objects created (Store & display result using separate object). 4. Use...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT