Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C# PROGRAMMING: The images contain the question and, This is the code I have written so far, and I would like the full answer as

C# PROGRAMMING:

image text in transcribedimage text in transcribed

The images contain the question and,

This is the code I have written so far, and I would like the full answer as I'm stuck:

using System;

namespace COMP123_19_2 { class Date { int year; int month; int day;

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

public override string ToString() { return $"Date: {year}/{month}/{day}"; }

public void Add(int days) { this.day += days; } public void Add(int days,int months) { this.day += days; //same as saying day = day + days this.month += months; } public void Add(Date other) { this.year += other.year; this.month += other.month; this.day += other.day; } private void Normalize() {

}

static void Main(string[] args) { Date date=new Date() } } }

Description of field members (attributes): 1. year: this private member represents the year value for this object 2. month: this private member represents the month value for this object. You may interpret the months numerically, as you normally would: i.e. 1==January1= February etc. January, 2 = February, etc. 3. day: this private member represents the day value for this object Description of constructor: 1. public Date(int day, int month, int year): this is the constructor of this class. It takes three integer arguments and assigns them to the appropriate fields. You will assume that all the arguments will be in the correct range. Description of action members (methods): 1. public override string ToString(): this method overrides the same method in the base or parent class. It does not take any argument but it returns a string representing this object. 2. public void Add(int days): this method takes a single integer argument representing the amount to increase the day field by and adds it to the appropriate field. 3. public void Add(int days, int months): this method takes two integer arguments representing the amount to increase the month field and the day field. It adds the argument to the appropriate fields. 4. public void Add(Date other): this method takes a single argument representing a Date. The is actually three integer values packed into a single Date object. You will have to separate each packed value and increase the year, month and day fields by the appropriate amount. 5. private void Normalize(): this method does not take any argument nor does it return a value. It does the following: a. If the days field is more than the number of days in a month, then it subtracts the number of days in the month from the day field and increases the month field by one. b. If the month field is more than 12 then, 12 is subtracted from the month field and the year field is increased by 1. This method should be called at the end of the constructor, and each Add method. In your main method write the code to do the following: 1. Create a Date object. You decide on the arguments. 2. Display the above object reference on the console. 3. Call the Add( ) method of the object reference to verify that the method works correctly. You will need to invoke this method three times with different numbers and types of argument because this method is overloaded three times. (How would you display the modified object?). 4. What would you add to the class to make the display more sensible? i.e. the day and month value should be in range Enhancements: 1. Display the text for the month i.e. Jan or January for the month 1. 2. Handle the different month length properly "30 days has September, April, June, and November. All the rest have 31. Save February, with 28 days clear, and 29 each leap year

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

6. Explain the power of labels.

Answered: 1 week ago

Question

5. Give examples of variations in contextual rules.

Answered: 1 week ago

Question

f. What stereotypes were reinforced in the commercials?

Answered: 1 week ago