Click here to Skip to main content
15,918,808 members
Home / Discussions / C#
   

C#

 
AnswerRe: Change the process priority. Pin
PIEBALDconsult17-Aug-09 18:34
mvePIEBALDconsult17-Aug-09 18:34 
GeneralRe: Change the process priority. Pin
JollyMansArt17-Aug-09 19:36
JollyMansArt17-Aug-09 19:36 
QuestionC# .NET - Export total windows form to word Pin
rizchi17-Aug-09 17:17
rizchi17-Aug-09 17:17 
AnswerRe: C# .NET - Export total windows form to word Pin
Christian Graus17-Aug-09 17:25
protectorChristian Graus17-Aug-09 17:25 
GeneralRe: C# .NET - Export total windows form to word [modified] Pin
Hristo-Bojilov17-Aug-09 20:59
Hristo-Bojilov17-Aug-09 20:59 
QuestionHow to access the label control on a user control Pin
codeslingerCA17-Aug-09 16:04
codeslingerCA17-Aug-09 16:04 
AnswerRe: How to access the label control on a user control Pin
Christian Graus17-Aug-09 16:23
protectorChristian Graus17-Aug-09 16:23 
Questionincrementing to the next day and next year Pin
lopatko17-Aug-09 15:56
lopatko17-Aug-09 15:56 
Hi,

Here is my task to accomplish so far: Modify the date class of (provided) to perform error checking on the initializer values for instance variables month, date, and year. Also provide a method NextDay to increment the day by one. The Date object should always remain in a consistent state. Write a program that tests the NextDay method in a loop that prints the date during each iteration of the loop to illustrate that the NextDay method works correctly. I have to be careful that I make sure my program increments into the next month and into the next year.

I did created classes and intiliaze values, and created next day. I tried different method but,could not get it right.Can you point me in the right direction. Thanks, and here is my code:

Date.cs
using System;
using System.Collections.Generic;
using System.Text;

public class Date
{
public static void Main(string[] args)
{

}

private int month, day, year, nextday;
public Date(int theMonth, int theDay, int theYear, int nextDay)
{
Month = theMonth;
Year = theYear;
Day = theDay;
Nextday = theNextDay;
Console.WriteLine( "Date object for date {0}", this );
}
public int Year
{
get
{
return Year;
}
private set{
if (value > 0 && value <= 3000)
year = value;
else
{
Console.WriteLine("Invalid Year ({0}) set to 1.", value);
year = 1;
}
}
}
public int Month
{
get
{
return Month;
}
private set
{
if (value > 0 && value <=12)
month = value;
else
{
Console.WriteLine( "Invalid Month ({0}) set to 1.", value );
month = 1;
}
}
}
public int Day
{
get
{
return day;
}
private set
{
int[] daysPerMonth = { 0, 31, 28, 31, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
if (value > 0 && value <= daysPerMonth[Month])
day = value;
else if (Month == 2 && value == 29 && (Year % 400 == 0 || (Year % 4 == 0 && Year % 100 != 0)))
day = value;
else
{
Console.WriteLine("Invalid day {0} set to 1.", value);
day = 1;
}
}
}

public override String ToString()
{
return String.Format("{0}/{1}/{2}", Month, Day, Year);
}
public string ToDateString()
{
return month + "/" + day + "/" + year;
}




public int getnextDay()

{
//int nextDay = 1;


{

if (day.equals("Sun"))

return "Mon";

else if (day.equals("Mon"))

return "Tue";

else if (day.equals("Tue"))

return "Wed";

else if (day.equals("Wed"))

return "Thu";

else if (day.equals("Thu"))

return "Fri";

else if (day.equals("Fri"))

return "Sat";

else

return "Sun";

for (nextDay=0;nextDay<30;nextDay++)
{
nextDay = 33; // This line will ERROR!
Console.WriteLine("Loop: {0}", nextDay);


}
}
}
//end of file






DateTest.cs
using System;
using System.Collections.Generic;
using System.Text;

namespace Date
{
public class DateTest
{
public static void Main(string[] args)
{
Date myDate = new Date();


myDate.nextDate(); // display date
}
}
}
AnswerRe: incrementing to the next day and next year Pin
Christian Graus17-Aug-09 16:26
protectorChristian Graus17-Aug-09 16:26 
GeneralRe: incrementing to the next day and next year Pin
Thomas Krojer17-Aug-09 20:23
Thomas Krojer17-Aug-09 20:23 
QuestionI am tring something different what is wrong??? Pin
JollyMansArt17-Aug-09 13:40
JollyMansArt17-Aug-09 13:40 
AnswerRe: I am tring something different what is wrong??? Pin
Henry Minute17-Aug-09 13:47
Henry Minute17-Aug-09 13:47 
AnswerRe: I am tring something different what is wrong??? Pin
Christian Graus17-Aug-09 13:57
protectorChristian Graus17-Aug-09 13:57 
QuestionNullable Type Pin
Mycroft Holmes17-Aug-09 13:20
professionalMycroft Holmes17-Aug-09 13:20 
AnswerRe: Nullable Type Pin
Christian Graus17-Aug-09 13:39
protectorChristian Graus17-Aug-09 13:39 
AnswerRe: Nullable Type Pin
Henry Minute17-Aug-09 13:59
Henry Minute17-Aug-09 13:59 
GeneralRe: Nullable Type Pin
Mycroft Holmes17-Aug-09 14:12
professionalMycroft Holmes17-Aug-09 14:12 
QuestionPointless locking? Pin
MarkLTX17-Aug-09 11:38
MarkLTX17-Aug-09 11:38 
AnswerRe: Pointless locking? Pin
Christian Graus17-Aug-09 11:49
protectorChristian Graus17-Aug-09 11:49 
AnswerRe: Pointless locking? Pin
PIEBALDconsult17-Aug-09 13:17
mvePIEBALDconsult17-Aug-09 13:17 
AnswerRe: Pointless locking? Pin
cmk17-Aug-09 18:34
cmk17-Aug-09 18:34 
GeneralRe: Pointless locking? Pin
MarkLTX18-Aug-09 3:21
MarkLTX18-Aug-09 3:21 
QuestionArray of class with implicit conversion [modified] Pin
DaveyM6917-Aug-09 11:23
professionalDaveyM6917-Aug-09 11:23 
AnswerRe: Array of class with implicit conversion Pin
Saksida Bojan17-Aug-09 11:32
Saksida Bojan17-Aug-09 11:32 
GeneralRe: Array of class with implicit conversion Pin
DaveyM6917-Aug-09 11:37
professionalDaveyM6917-Aug-09 11:37 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.