How JustAnswer Works:

  • Ask an Expert
    Experts are full of valuable knowledge and are ready to help with any question. Credentials confirmed by a Fortune 500 verification firm.
  • Get a Professional Answer
    Via email, text message, or notification as you wait on our site.
    Ask follow up questions if you need to.
  • 100% Satisfaction Guarantee
    Rate the answer you receive.

Ask tejas_speed Your Own Question

tejas_speed
tejas_speed, Computer Software Engineer
Category: Programming
Satisfied Customers: 21
Experience:  Computer Engineer With Knowledge of ASP.Net and C#
32711602
Type Your Programming Question Here...
tejas_speed is online now
A new question is answered every 9 seconds

Validation

Customer Question

validation
Submitted: 1 year ago.
Category: Programming
Expert:  LogicPro replied 1 year ago.

Hi

Provide the details

Customer: replied 1 year ago.
ok I have this code:
protected bool isLearnersPermit = false;
// Check for learner's permit.
DateTime now = DateTime.Today;
LocalTime dateOfbirth = driver.getDateOfBirth();
int DriverAge = now.Year - dateOfbirth.getYear();
if (driver.getIdType() != IdType.LEARNERS_PERMIT)
{
if (DriverAge > 21)
{
isLearnersPermit = false;
isLearnersPermitDrvNum = f + 1;
}
else
{
isLearnersPermit = true;
}
}Scenario 1 - check to see if Driver 1 = 20 years old then Driver 2 can't have learner's permit
Scenario 2 - check to see if Driver 2 = 21 years old then I can add learner's permit
Scenario 3 - check to see if Driver 1 or 2 are not learner's permit regardless of their age I can process it --- this is not happening in the below code.
for example if they have regular driver license and at any age I should process my form because they do not apply to scenarios 1 & 2.
Expert:  LogicPro replied 1 year ago.

Is it Java?

Customer: replied 1 year ago.
no C#
Expert:  LogicPro replied 1 year ago.

If you have any file(s), Zip all files; upload the zipped file to http://wikisend.com or http://ge.tt and post download link here.

Customer: replied 1 year ago.
i'm not available via phone...sorry
Expert:  LogicPro replied 1 year ago.

let me check it

Customer: replied 1 year ago.
ok, let me know when done...thanks
Expert:  LogicPro replied 1 year ago.

In the code, only 1 driver is defined, not 2.

Customer: replied 1 year ago.
i want to loop through all the drivers I have, i can have more than 2 drivers.
Expert:  LogicPro replied 1 year ago.

Can you provide me complete code, then I would be able to help you.

Customer: replied 1 year ago.
int driverCount = rev.getDriverCount();
.Driver driver;for (int j = 0; j < driverCount; j++)
{
driver = rev.getDriver(j);// The following checks are only for newly added drivers that are not excluded.
if (driver.IsNewlyIncluded())
{
// Check for learner's permit.
LocalTime now = new LocalTime().getDate();
LocalTime dateOfbirth = driver.getDateOfBirth();
int DriverAge = now.daysApart(dateOfbirth) / 365;
string idType = driver.getIdType();if (idType != IdType.LEARNERS_PERMIT)
{
if (DriverAge > 21)
{
isLearnersPermit = false;
isLearnersPermitDrvNum = f + 1;
}
else
{
isLearnersPermit = true;
}
}
}
}
Expert:  LogicPro replied 1 year ago.

ok, I will check and reply.

Customer: replied 1 year ago.
thanks
Expert:  LogicPro replied 1 year ago.

welcome

Customer: replied 1 year ago.
how long will it take?
Expert:  LogicPro replied 1 year ago.

in the loop also, it will check driver one by one.

Expert:  LogicPro replied 1 year ago.

It is not using 2 driver objects.

Customer: replied 1 year ago.
it is I just omitted the class
Expert:  LogicPro replied 1 year ago.

Should there be 2 driver objects?

Customer: replied 1 year ago.
no all the drivers are using the same objects
Customer: replied 1 year ago.
I think the problem might be my if statement
Expert:  LogicPro replied 1 year ago.

ok, in that case, code should be something like this:

Code:

int driverCount = rev.getDriverCount();
            Driver driver;
            for (int j = 0; j < driverCount; j++)
            {
               driver = rev.getDriver(j);
               if (driver.IsNewlyIncluded())
               {
                    bool isLearnersPermit = false; // Check for learner's permit.
                    DateTime now = DateTime.Today;
                    DateTime dateOfbirth = driver.getDateOfBirth();
                    int DriverAge = now.Year - dateOfbirth.getYear();
                    if (driver.getIdType() != IdType.LEARNERS_PERMIT)
                    {
                        if (DriverAge == 20)
                        {
                            isLearnersPermit = false;
                            //isLearnersPermitDrvNum = f + 1;
                        }
                        else if (DriverAge == 21)
                        {
                            isLearnersPermit = false;
                            isLearnersPermitDrvNum = f + 1;
                        }
                        else
                        {
                            isLearnersPermit = true;
                        }
                    }
               }
            }

Expert:  LogicPro replied 1 year ago.

We can continue the conversation until you're satisfied and rate my answer as excellent. I can address follow up questions and I'm always here to help.

You can ask me again using "For LogicPro only" at the start of your questions like other customers to get instant answers. It will ensure that question is for me.

Please bookmark my profile page:

http://www.justanswer.com/homework/expert-logicpro/

so you can come back and ask me a question anytime.

Thank you for using this site!

Useful resources:

https://ww2-secure.justanswer.com/help/do-i-have-rate-answer

http://ww2.justanswer.com/help/how-do-i-rate-answer-hl

Customer: replied 1 year ago.
I've tested this and I think I've tried this logic but it's not working :(
Customer: replied 1 year ago.
message should only pop up if 1st driver is less than 20 and adding 2nd driver Learner's Permit.
Expert:  LogicPro replied 1 year ago.

Please provide me complete code with complete requirements.

Expert:  LogicPro replied 1 year ago.

I will have to see your screen. I'm going to make an offer for remote service that you can use. When you accept it, I'll be immediately notified and can do the work to help you while you watch. After accepting, let me know

Customer: replied 1 year ago.
I don't think I have access to do this
Customer: replied 1 year ago.
I mean permission to do so
Expert:  LogicPro replied 1 year ago.

Are you getting the offer?

Customer: replied 1 year ago.
but I am not allowed to do screenshots
Expert:  LogicPro replied 1 year ago.

what error are you getting in accepting the offer?

Once you accept the offer only then I can provide you remote help

Customer: replied 1 year ago.
can't do it now, I'm not authorized
Customer: replied 1 year ago.
basically the code you provided is not popping up the error at all
Expert:  LogicPro replied 1 year ago.

You want to display error messages also?

Customer: replied 1 year ago.
already done so but it's not validating it
Expert:  LogicPro replied 1 year ago.

Here it is with pop ups:

Code:

int driverCount = rev.getDriverCount();
            Driver driver;
            for (int j = 0; j < driverCount; j++)
            {
               driver = rev.getDriver(j);
               if (driver.IsNewlyIncluded())
               {
                    bool isLearnersPermit = false; // Check for learner's permit.
                    DateTime now = DateTime.Today;
                    DateTime dateOfbirth = driver.getDateOfBirth();
                    int DriverAge = now.Year - dateOfbirth.getYear();
                    if (driver.getIdType() != IdType.LEARNERS_PERMIT)
                    {
                        if (DriverAge == 20)
                        {
                            isLearnersPermit = false;
                            //isLearnersPermitDrvNum = f + 1;
                            MessageBox.Show("Driver 2 can't have learner's permit");
                        }
                        else if (DriverAge == 21)
                        {
                            isLearnersPermit = true;
                            isLearnersPermitDrvNum = f + 1;
                            MessageBox.Show("add learner's permit");
                        }
                        else
                        {
                            isLearnersPermit = true;
                            MessageBox.Show("Driver 1 or 2 are not learner's permit regardless of their age");
                        }
                    }
               }
            }

Customer: replied 1 year ago.
this is the requirements:
Driver 1 = 20 yrs old
Driver 2 = Learner's Permit therefore can't add it
Driver 2 = 21 yrs old
Driver 3 = Learner's Permit therefore can add itHowever if no learner's permit need to be added the process should go through regardless of ageI hope that makes sense now :)
Expert:  LogicPro replied 1 year ago.

My apologies. I am out of ideas and opting out for other experts to join you.

Thank you.

I would be happy to help you with your other questions though.

Customer: replied 1 year ago.
oh ok
Customer: replied 1 year ago.
are you here? I think I fixed it but need a little bit help now. can you help?
Expert:  tejas_speed replied 1 year ago.

Hi Sir,

I can help you out with your issue. Could you please explain me the error that you are getting currently?

Customer: replied 1 year ago.
I am not receiving any error but not getting what I intend to do.
So far I have this code but when driver is older than 21, I should be able to add Learners Permit this is not happening in this code.
int driverCount = rev.getDriverCount();
Driver driver;for (int f = 0; f < driverCount; f++)
{
driver = rev.getDriver(f);
if ((driver != null) && (!driver.isDeleted()))
{
// The following checks are only for newly added drivers that are not excluded.
if (driver.IsNewlyIncluded())
{
// Check for learner's permit.
LocalTime now = new LocalTime().getDate();
LocalTime dateOfbirth = driver.getDateOfBirth();
int DriverAge = now.daysApart(dateOfbirth) / 365;
string idType = driver.getIdType();if (idType != IdType.LEARNERS_PERMIT)
{
if (DriverAge == 20)
{
isLearnersPermit = true;
isLearnersPermitDrvNum = f + 1;
}
else if (DriverAge >= 21)
{
isLearnersPermit = true;
//isLearnersPermitDrvNum = f + 1;
}
}
else
{
isLearnersPermit = false;
}
}
}
}
Expert:  tejas_speed replied 1 year ago.

Hi Sir,

Please try this code. If you still do not get expected result. I will share one more solution.

int driverCount = rev.getDriverCount();
Driver driver;
for (int f = 0; f < driverCount; f++)
{
driver = rev.getDriver(f);
if ((driver != null) && (!driver.isDeleted()))
{
// The following checks are only for newly added drivers that are not excluded.
if (driver.IsNewlyIncluded())
{
// Check for learner's permit.
LocalTime now = new LocalTime().getDate();
LocalTime dateOfbirth = driver.getDateOfBirth();
int DriverAge = now.daysApart(dateOfbirth) / 365;
string idType = driver.getIdType();
if (idType != IdType.LEARNERS_PERMIT)
{
if (DriverAge < 20)
{
isLearnersPermit = false;
isLearnersPermitDrvNum = f + 1;
}
else if (DriverAge >= 21)
{
isLearnersPermit = true;
isLearnersPermitDrvNum = f + 1;
}
}
else
{
isLearnersPermit = false;
}
}
}
}

Customer: replied 1 year ago.
not working
Customer: replied 1 year ago.
this is my requirements:
Scenario 1 - check to see if Driver 1 = 20 years old then Driver 2 can't have learner's permit
Scenario 2 - check to see if Driver 2 = 21 years old then I can add learner's permit
Scenario 3 - check to see if Driver 1 or 2 are not learner's permit regardless of their age I can process it --- this is not happening in the below code.
for example if they have regular driver license and at any age I should process my form because they do not apply to scenarios 1 & 2.
Expert:  tejas_speed replied 1 year ago.

Hi Sir,

I think this will work.

int driverCount = rev.getDriverCount();
Driver driver;
for (int f = 0; f < driverCount; f++)
{
driver = rev.getDriver(f);
if ((driver != null) && (!driver.isDeleted()))
{
// The following checks are only for newly added drivers that are not excluded.
if (driver.IsNewlyIncluded())
{
// Check for learner's permit.
LocalTime now = new LocalTime().getDate();
LocalTime dateOfbirth = driver.getDateOfBirth();
int DriverAge = now.daysApart(dateOfbirth) / 365;
string idType = driver.getIdType();
if (idType != IdType.LEARNERS_PERMIT)
{
sLearnersPermit = true;
isLearnersPermitDrvNum = f + 1;
}
else
{
if (DriverAge < 20)
{
isLearnersPermit = false;
isLearnersPermitDrvNum = f + 1;
}
else if (DriverAge >= 21)
{
isLearnersPermit = true;
isLearnersPermitDrvNum = f + 1;
}
}
}
}
}

Customer: replied 1 year ago.
with the latest code only scenario 2 works
Expert:  tejas_speed replied 1 year ago.

I think all three sholud work. Try to create 3 conditions. 1st should be less than 20 and having no licence. 2nd should be greater than 20 and having no licence and 3rd should be of any age and holding a regular license. Write your code like this.

int driverCount = rev.getDriverCount();
Driver driver;
for (int f = 0; f < driverCount; f++)
{
driver = rev.getDriver(f);
if ((driver != null) && (!driver.isDeleted()))
{
// The following checks are only for newly added drivers that are not excluded.
if (driver.IsNewlyIncluded())
{
// Check for learner's permit.
LocalTime now = new LocalTime().getDate();
LocalTime dateOfbirth = driver.getDateOfBirth();
int DriverAge = now.daysApart(dateOfbirth) / 365;
string idType = driver.getIdType();
if (idType != IdType.LEARNERS_PERMIT)
{
// Write your code to process form over here as driver is having regular licence
}
else
{
if (DriverAge < 20)
{
isLearnersPermit = false;
isLearnersPermitDrvNum = f + 1;
}
else if (DriverAge >= 21)
{
isLearnersPermit = true;
isLearnersPermitDrvNum = f + 1;
}
}
}
}
}

Customer: replied 1 year ago.
I've tested it scenario 1 is not working, if driver is less than 20 it's allowing to add learners permit license
Customer: replied 1 year ago.
here's my latest code:
if (idType != IdType.LEARNERS_PERMIT)
{
isLearnersPermit = true;
isLearnersPermitDrvNum = f + 1;
}
else
{
if (DriverAge < 20)
{
isLearnersPermit = false;
isLearnersPermitDrvNum = f + 1;
}
else if (DriverAge >= 21)
{
isLearnersPermit = true;
isLearnersPermitDrvNum = f + 1;
}
}
Expert:  tejas_speed replied 1 year ago.

The code that has been given by me should work correctly since we have set isLearnersPermit = false; when dricers age is less than 20. You should not allow program to go ahead if drivers age is less than 20. Nothing else needs to be done. rest is fine in the code.

Customer: replied 1 year ago.
the problem is that if 1st driver is older than 21 and 2nd driver is less than 20, it's prompting that I can't add learners permit because one of the driver is less than 20
Expert:  tejas_speed replied 1 year ago.

You should do this.

int driverCount = rev.getDriverCount();
Driver driver;
for (int f = 0; f < driverCount; f++)
{
driver = rev.getDriver(f);
if ((driver != null) && (!driver.isDeleted()))
{
// The following checks are only for newly added drivers that are not excluded.
if (driver.IsNewlyIncluded())
{
// Check for learner's permit.
LocalTime now = new LocalTime().getDate();
LocalTime dateOfbirth = driver.getDateOfBirth();
int DriverAge = now.daysApart(dateOfbirth) / 365;
string idType = driver.getIdType();
if (idType != IdType.LEARNERS_PERMIT)
{
// Write your code to process form over here as driver is having regular licence
}
else
{
if (DriverAge < 20)
{

//Do not add learners permit
isLearnersPermit = false;
isLearnersPermitDrvNum = f + 1;
}
else if (DriverAge >= 21)
{

//Add your code over here which provides learners permit
isLearnersPermit = true;
isLearnersPermitDrvNum = f + 1;
}
}
}
}
}

Customer: replied 1 year ago.
Write your code to process form over here as driver is having regular licence? what do you mean by that? which code might that be?
Expert:  tejas_speed replied 1 year ago.

your 3rd condition code i.e. driver with regular permit.