Question

Need help writing beginner C# program, I will make sure to provide feedback to whoever can help me figure it out!

No public or global variables should be used. You need to consider passing arguments between the methods according to the ways described in the lecture. i.e. all variables should be declared inside the methods and passed to other methods by value/ref/out as neededDescription: We want to design a Date class to represent a date using three integer numbers for day, month, and year. Our clac) Display the dates of the objects above using the showDate method with both date formats (US, and Europe). That is, call th

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

Solution:

TDate.cs:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp2
{
class TDate
{
private static string earliestDate = "1/1/1900";
private static string latestDate = "12/31/2100";
private int day, month, year;
TDate(string date)
{
string[] objectDate = date.Split('/');
string[] earliest = earliestDate.Split('/');
if (int.Parse(objectDate[0]) > 0 && int.Parse(objectDate[0]) <= 31)
{
day = int.Parse(objectDate[0]);
} else
{
day = int.Parse(earliest[0]);
}
if (int.Parse(objectDate[1]) > 0 && int.Parse(objectDate[1]) <= 12)
{
month = int.Parse(objectDate[1]);

} else
{
month = int.Parse(earliest[1]);
}
if (int.Parse(objectDate[2]) > 0)
{
year = int.Parse(objectDate[2]);
} else
{
year = int.Parse(earliest[2]);
}
}

public void showDate(Char c)
{
if(c == 'U')
{
Console.WriteLine("US Date: " + day + "/" + month + "/" + year);
} else
{
Console.WriteLine("European Date: " + month + "/" + day + "/" + year);
}
}
static void Main(string[] args)
{
TDate d1 = new TDate("12/15/1990");
d1.showDate('U');
d1.showDate('E');
TDate d2 = new TDate("15/12/1990");
d2.showDate('U');
d2.showDate('E');
TDate d3 = new TDate("11/11/1811");
d3.showDate('U');
d3.showDate('E');
Console.ReadLine();
}
}
}
Output:

- 0 X C:\Users\Pramod source repos ConsoleApp2\ConsoleApp2\bin\Debug\ConsoleApp2.exe US Date: 12/1/1990 European Date: 1/12/1

Add a comment
Know the answer?
Add Answer to:
Need help writing beginner C# program, I will make sure to provide feedback to whoever can...
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
  • I need help writing this program in C. (not C++) Armor Games CrazyMonkeyGames Max Games Palomar...

    I need help writing this program in C. (not C++) Armor Games CrazyMonkeyGames Max Games Palomar College堯Wolfram|Alpha M Gmail EaXGen Studios How About a Date? Dinner and Dancing with your Computer The purpose of this assignment is to acquaint you with the capability of a computer program to systematically explore a set of possibilities and deter mine the validity of input to the program. HPal-CSC112Spring 2017/ Lab Solutions 12-How about a datelcheckDatelnC Debuglche... elcome to my Date Checker Project Enter...

  • public class Date { private int month; private int day; private int year; /** default constructor...

    public class Date { private int month; private int day; private int year; /** default constructor * sets month to 1, day to 1 and year to 2000 */ public Date( ) { setDate( 1, 1, 2000 ); } /** overloaded constructor * @param mm initial value for month * @param dd initial value for day * @param yyyy initial value for year * * passes parameters to setDate method */ public Date( int mm, int dd, int yyyy )...

  • Create class Date with the following capabilities: a) Output the date in multiple formats, such as...

    Create class Date with the following capabilities: a) Output the date in multiple formats, such as MM/DD/YYYY June 14, 1992 DDD YYYY b) Use overloaded constructors to create Date objects initialized with dates of the formats in part (a). In the first case the constructor should receive three integer values. In the second case it should receive a String and two integer values. In the third case it should receive two integer values, the first of which represents the day...

  • JAVA programing Question 1 (Date Class):                                   &nbsp

    JAVA programing Question 1 (Date Class):                                                                                                     5 Points Create a class Date with the day, month and year fields (attributes). Provide constructors that: A constructor that takes three input arguments to initialize the day, month and year fields. Note 1: Make sure that the initialization values for the day, month and year fields are valid where the day must be between 1 and 31 inclusive, the month between 1 and 12 inclusive and the year a positive number. Note 2:...

  • Please write the program in C++ Problem Description: Design a class called Date. The class should...

    Please write the program in C++ Problem Description: Design a class called Date. The class should store a date in three integers: month, day, and year.     Create the necessary set and get methods.       Design member functions to return the date as a string in the following formats:                                     12/25/2012                                     December 25, 2012                                     25 December 2012 Input Validation: Do not accept values for day greater than 30 or less than 1. Do not accept values for month...

  • C Programming Quesition (Structs in C): Write a C program that prompts the user for a...

    C Programming Quesition (Structs in C): Write a C program that prompts the user for a date (mm/dd/yyyy). The program should then take that date and use the formula on page 190 (see problem 2 in the textbook) to convert the date entered into a very large number representing a particular date. Here is the formula from Problem 2 in the textbook: A formula can be used to calculate the number of days between two dates. This is affected by...

  • In Java please Project 14-1: Reservation Calculator Create an application that gets arrival and departure dates...

    In Java please Project 14-1: Reservation Calculator Create an application that gets arrival and departure dates for a reservation and calculates the total amount for the stay. Console Reservation Calculator Enter the arrival month (1-12): 5 Enter the arrival day (1-31): 16 Enter the arrival year: 2018 Enter the departure month (1-12): 5 Enter the departure day (1-31) : 18 Enter the departure year: 2018 Arrival Date: May 16, 2018 Departure Date: May 18, 2018 Price: $145.00 per night Total...

  • I need help in this please, in the c# language. Objects As Parameters The goal for...

    I need help in this please, in the c# language. Objects As Parameters The goal for this exercise is to define the Television object, which you will be using in several, subsequent exercises. For all the methods that you implement (in this course (not just this exercise, but in this course, as you go forwards)), you should remember that since method is public, anyone, anywhere can call the method. Even people whom you never thought would call this method. Therefore,...

  • Hello. I need help writing the following Java Program. Thank you Develop a class encapsulating the...

    Hello. I need help writing the following Java Program. Thank you Develop a class encapsulating the concept of a college course, assuming that a course has following attributers: code (for instance COSC1337), a description, and a number of credits (for instance 3). Include a constructor, the accessors, mutators and methods ‘toString’, ‘equals’, and ‘finalize’. Write a client class to test the behavior of the class and its methods. The outline of the class is given as follows: public class Course...

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
ADVERTISEMENT