home hardware prices news articles forums photos user reviews
Go Back   Tech Support Forums - TechIMO.com > PC Hardware and Tech > Webmastering and Programming
Ask a Tech Support Question (free)!

calling upon classes in C#

Reply
Get bargains at  »  Dealighted.com
 
Thread Tools Search this Thread
Currently Active Users: 2159
Discussions: 200,948, Posts: 2,379,400, Members: 246,309
Old January 29th, 2006, 05:03 PM   Digg it!   #1 (permalink)
Mobile Member
 
ShuckyD's Avatar
 
Join Date: Apr 2005
Location: S. Central PA
Posts: 3,601
calling upon classes in C#

im trying to get the exact context down for being able to call upon a class i made in a C# console app. Our teach wanted us to make a console app then add a class and call it date and then use the main part of the program to run the class "date," i copied the basic stuff i need into the class "date" then i need to call it from the other "window" where the program started.. then i can see my output then work on it form there? does anyone know the context on how to call on a class in C# (console app)

thanks

J.D.
__________________
Thinkpad T61 14.1" wide | WinXP Pro | C2D T8300 CPU | 3GB DDR2 | 160GB HDD | AGN & WWAN
Lenovo S10 10.2" LED display | 1.6Ghz Atom CPU | 1GB DDR2 | 1.3mp webcam | B/G WiFi | 160GB HDD
ShuckyD is offline   Reply With Quote
Old January 29th, 2006, 11:24 PM     #2 (permalink)
Mobile Member
 
ShuckyD's Avatar
 
Join Date: Apr 2005
Location: S. Central PA
Posts: 3,601
well to sorta elaborate on the first part of my post.... Im back in programming this semester and i have an assignment that i have to do, its working with multiple classes, well we make a class and call on it in the program, i guess class1, but im not sure exactly how to call on it, or really where to start on the program, if i get an inkling as to where to start im pretty sure i could do it from there, i understand what the code is saying and somewhat how to write it, its just that im confused as how to do "error checking" well heres the assignment that i was given:

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

here is the code that was given to me from the text...

Code:
using System;

namespace ex8_4
{
	/// <summary>
	/// Summary description for Date.
	/// </summary>
	public class Date
	{
		private int month; //1-12
		private int day; //1-31 based on month
		private int year; // any  year

		//constructor confirms proper value for month
		//call method CheckDay to confirm proper value for day

		public Date(int theMonth, int theDay, int theYear)
		{
			//validation of month
			if ( theMonth > 0 && theMonth <= 12)
				month = theMonth;
			else
			{
				month = 1;
				Console.WriteLine(
					"Month {0} invalid. Set to month 1.", theMonth);
			}

			year = theYear; // year validation
			day = CheckDay( theDay );

		}  //end of date constructor

		//a utility method to confirm proper day value based on month and year

		private int CheckDay( int testDay)
		{
			int[] daysPerMonth = 
				{0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

			//a check to make sure its not a leap year

			if (month == 2 && testDay == 29 &&
				(year % 400 == 0 ||
				(year % 4 == 0 && year % 100 != 0 )))
				return testDay;

			Console.WriteLine(
				"Day {0} invalid. Set to day 1.", testDay);

			return 1;  //leaves object in consistent state
		}

		//returns date string as month/day/year

		public string ToDateString()
		{
			return month + "/" + day + "/" + year;
		}

		//time to add some methods

	}//end class Date
			


		}
so this is a nice foundation for me to start on, although im not sure what to do next, my main part of my console app looks like this:

using System;

namespace ex8_4
{
class Class1
{
[STAThread]
static void Main(string[] args)
{
// what do i write in here???

Date date = new //????
}
}
}


soo yea any suggestions or help would be appreciated, any thoughts would also be great. Im still wondering how/where to write the methods to do the things it wants me to, i think in the date.cs but then how to i word it so that the program calls upon that class.. (getting back to my original ?? )
ShuckyD is offline   Reply With Quote
Old January 31st, 2006, 02:39 PM     #3 (permalink)
Caveat Emptor
 
Rootstonian's Avatar
 
Join Date: Mar 2005
Location: Out of my mind
Posts: 3,241
Send a message via AIM to Rootstonian
All your code will belong in the class as functions (appropriately called "methods"). Looks like error checking is in there for month, day and year???

Your "main{}" should probably look like this:

main() {

int i;

Date myDate(12,25,2006);

for(i=0;i<10;i++)

{
myDate.NextDay(); // you write this to increment the day (and month? and year?)
myDate.PrintDate(); // you write this one too (might call existing method to format)

}

}
Rootstonian is offline   Reply With Quote
Old February 1st, 2006, 05:32 PM     #4 (permalink)
Mobile Member
 
ShuckyD's Avatar
 
Join Date: Apr 2005
Location: S. Central PA
Posts: 3,601
thanks roots,

well i have my stuff due today and i was already able to figure it out.. What i was having a problem with was understanding how to get the array to work correctly and then how to call from the main class, into the other class i made so that i can get it right... (pretty much formatting issues)

Console.WriteLine("\n"); //courtesy space
Console.WriteLine("Check increment day");
cls_Date Day_Obj=new cls_Date(12,22,1981);
Day_Obj.NextDay();

Console.WriteLine("12-22-1981-Next day={0} ",Day_Obj.ToString());
Console.WriteLine("\n");


thats how i was able to refer to the other class, i was all confused on how to get it to do it, until i asked the teach on monday to show us how we need to format it, he pretty much just sat down an coded it for us.. haha although i had some of it done, i still didnt know how to make em relate...
ShuckyD is offline   Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search

Similar Threads
Thread Thread Starter Forum Replies Last Post
License Classes JimRune IMO Community 2 August 29th, 2005 12:48 AM
Web Dev Classes FMF Certification and Education 0 May 18th, 2005 06:44 AM
What are you classes for school? Blazer06 IMO Community 34 August 31st, 2004 06:45 AM
Classes about programming MadMan2k Webmastering and Programming 12 August 10th, 2004 07:34 PM


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Most Active Discussions
Making Health Care Worse (172)
Is It Just Me? (2936)
The disrespect of Obama by Russian .. (22)
Wireless Televisions. (12)
windows 7 problem (7)
CPU fan stops spinning randomly (8)
Regular Build (6)
Is the PSU I received dead? (12)
radeon x850xt platinum & shader.. (5)
Print spooler problem (15)
HIS HD5770 graphic card question (15)
windows vista security holes (9)
Install XP pro and a Vista laptop ?.. (11)
Dept. of HS: NSA 'Helped' Develop V.. (15)
Recent Discussions
How to convert MP3's (4)
Wireless Televisions. (12)
Graphics Card Upgrade Question (3)
Laptop with wireless problem. (2)
Internet Lost (1)
Hp Artist Edition + Matching Bag (0)
My monitor won't turn on after instal.. (0)
Asus P4G8X Mobo (6)
radeon x850xt platinum & shader 3 (5)
Xbox 360 GTA: SA disk error (1)
Is the PSU I received dead? (12)
windows 7 internet problem (5)
Multiple Restarts Required at Boot (0)
BSOD On Startup (ntoskrnl.exe) (2)
Print spooler problem (15)
Have you switched yet? (86)
screen resolution vs monitor size (2)
sms storage to PC (0)
Regular Build (6)
Open With ..... Win7 (0)
java code for fibonacci (1)
[F@H SPAM 11/16/09] ! 1/2 months to r.. (35)
windows 7 problem (7)
CPU fan stops spinning randomly (8)
Partition Magic caused HDD problem (3)


All times are GMT -4. The time now is 09:04 PM.
TechIMO Copyright 2009 All Enthusiast, Inc.



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28