firstname,lastname,email address, date of birth
Add constructor that accept the following [parameter list:
all four parameters (first,last,email,dateofbirth)
Add readonly property that return the following computed information
Adult - whether or not the person is over 18
birthday - whether or not today is the person birthday
handle the following execptions
date of birth is in the future
date of birth is too far in the past(we're only dealing with who are alive)
invalid email address
CAN ANYBODY HELP ME OUT TO SOLVE THESE
PLZ..
VulpesPosted May 29, 2013, 3:09 PM
Sorry about that which I've now corrected.
If you want to catch the exceptions as well, then this will need to be done in the constructor, otherwise the person object won't be created.
Notice that if the email address is invalid, it remains at null.
If the date of birth is invalid, it remains at its default value of 01/01/0001:
Some sample output, throwing both exceptions:
Sinu JosephPosted Jun 6, 2013, 1:00 PM
and i have 2 class 1 for connection named MyDBConeection and 1 is for all data related class called student
in MyDbConnection I gave connection details
in my student class i gave 4 properties named Rollno,Name,Age,Course and corresponding methods
public int Getdetails
{
it will display all details in grid view
}
public dataset update ()
{
update the table
}
BUT i need is this
i have a button in my form called getdetails before update
like this
roll no - textbox
then getdetails button
then name,age and course then update button
i want to display all details in my textbox while clicking on the getdetails button then update
plzz help...............
Sinu JosephPosted Jun 5, 2013, 10:50 AM
i have a form ...
in that i have 4 textbox called customerid,name and address,phone no
but customerid entered starts with letter'C' and has three digits after it,
and the phone no value should be integer ..
how can u do it ..plz help ...me
Sinu JosephPosted Jun 5, 2013, 10:42 AM
because my mam will saw me .. thts y ...
dnt forget to answer my questions
VulpesPosted Jun 1, 2013, 1:33 PM
However, you can force the use to enter a valid date before it's tested for being too late or too early as follows:
The DateTime.TryParse tests whether a string represents a valid date or not. If it does, it returns true otherwise it returns false. If it is valid, the 'out' parameter will contain that date otherwise it contains the default date (01/01/0001).
The code keeps looping ('do' statement) until a valid date is entered.
Sinu JosephPosted Jun 1, 2013, 11:32 AM
i uploaded the screen shot
if we leave dateofbirth column it will terminate the program and point out the error in our prgm
" Console.Write(" Date of birth : "); string dob = Console.ReadLine();
DateTime dateofbirth = DateTime.Parse(dob);----> error (String was not recognized as a valid DateTime. )
person p = new person(first, last, email, dateofbirth); "
VulpesPosted Jun 1, 2013, 6:42 AM
Sinu JosephPosted Jun 1, 2013, 4:02 AM
mam asked me do with constuctor overloading..
if the user enters first,last and email then constructor with 3 parameter will invoked and the 4 th value will be nill
sorry,,,
VulpesPosted May 31, 2013, 4:31 PM
One other thing I missed before is that we have to make sure that the date of birth is such that we're only dealing with living people. Now the oldest ever (documented) person was 122 so we will throw an exception if some-one would be 123 or more.
Here's the revised code - with the changes highlighted. I'll leave it to you to come up with code to test the new constructors if you feel it's necessary:
Sinu JosephPosted May 31, 2013, 2:34 PM
all four parameters ,
person( first,last,email)
person (first,last,dateofbirth)
constructoe with 4 opara
with 3para
and with 2 para
canu do it for me ...
add code for this too..
VulpesPosted May 31, 2013, 1:44 PM
If you look back at the code where we entered John Smith with some deliberately invalid data:
The constructor then printed the following messages:
I don't think it's saying that you should print a message if the data is valid as that would be pointless.
Sinu JosephPosted May 31, 2013, 1:06 PM
hey can u help ..
mam gave me some modification for tht question
create a reference type called person.Populate the person class with the following properties to store the following info:
firstname,lastname,email address, date of birth
Add constructor that accept the following [parameter list:
use constructor overload
all four parameters (first,last,email,dateofbirth),
with first,last,email
with first,last,dateofbirth
and must show msg after entering date or email..
eg if we entered wrong email then show msg after entering email
or date
Add readonly property that return the following computed information
Adult - whether or not the person is over 18
birthday - whether or not today is the person birthday
handle the following execptions
date of birth is in the future
date of birth is too far in the past(we're only dealing with who are alive)
invalid email address
CAN ANYBODY HELP ME OUT TO SOLVE THESE
PLZ..
VulpesPosted May 30, 2013, 11:40 AM
Sinu JosephPosted May 30, 2013, 11:35 AM
sorry 4 disturbing u a lot...
i thk u r soo angry because of me rt..
sorry :(
i just wanna study thats all ..
anyway u have good knowldge in c#..
thanks 4 helping me
VulpesPosted May 30, 2013, 10:59 AM
The first one - I think fairly obvious - is that a readonly property can only have a 'get'. If it had a 'set' as well, then it wouldn't be read only.
Within the body of the 'get', we first have to find the person's 18th birthday by adding 18 years to his/her birthday. There's a built in DateTime method (AddYears) which does this for us.
We then check to see whether today is on or after the 18th birthday. We can use the >= operator for this, just like we do for numbers.
If it is, then the person's an adult and we return true.
Otherwise, the person's a minor and we return false.
Sinu JosephPosted May 30, 2013, 9:57 AM
sorry 4 disturbing u agian
can u explain this also plz...
public bool Adult // readonly property has only a 'get'
{
get
{
DateTime eighteen = _dateofbirth.AddYears(18); // 18th birthday
if (DateTime.Today >= eighteen)
{
return true;
}// adult if 18 or over
return false; // otherwise minor
}
}
Sinu JosephPosted May 30, 2013, 9:44 AM
Thank u soo much i understood everythg...
VulpesPosted May 30, 2013, 8:57 AM
So in this line:
p.firstname = "sinu";
'value' will be equal to "sinu".
Properties are really methods under the hood and the firstname property would be converted to something like this by the compiler:
public string get_firstname()
{
return _firstname;
}
public void set_firstname(string value)
{
_firstname = value;
}
This shows more clearly where 'value' is coming from.
Sinu JosephPosted May 30, 2013, 7:07 AM
{
get { return _firstname; }
set { _firstname = value; }---> can u explain this value .. y u r given purpose .. plz..
}
public string lastname
{
get { return _lastname; }
set { _lastname = value; }
}
public string email
{
get { return _email; }
set
{
// make sure there's just one @ in it:
string[] items = value.Split('@'); // split the string using @ as a separator
if (items.Length != 2) // there should be exactly 2 items if it's valid
{
throw new ArgumentException("Invalid email address");
}
_email = value; // otherwise it's OK to set it
}
}
public DateTime dateofbirth
{
get { return _dateofbirth; }
set
{
if (value > DateTime.Today) // if it's after today
{
throw new ArgumentException("Date of birth can't be in the future");
}
_dateofbirth = value; // otherwise it's OK to set it
}
}
Sinu JosephPosted May 29, 2013, 2:38 PM
but here if we entered wrong date there is no msg shown.
we have to handle the exception ..
if the email is not correct show a msg invalid email.
can u do that for me please
Sinu JosephPosted May 29, 2013, 2:19 PM
Sinu JosephPosted May 29, 2013, 2:14 PM
msg hav to print...
VulpesPosted May 29, 2013, 1:55 PM
If we run the program and enter Barack's details again, the console output will be:
Sinu JosephPosted May 29, 2013, 1:13 PM
its not working yar can u provide the working
i need is tht the user can enter the value at runtime
Sinu JosephPosted May 29, 2013, 12:55 PM
thanks for the answer ...
is it possible tht the user can enter the values .for ths question
VulpesPosted May 29, 2013, 11:25 AM
// if today's month and day are same as date of birth's, it's a birthday