Click here to Skip to main content
16,017,986 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
ok so what im trying to do is return a value from method 1 "public double calculateAmout(int age, string policyTypeId)" to another method "public string startQuote"

So currently the "public string startQuote" requires the user to input all data when its called

what i want to do is take the 'age' and 'policyTypeId' variables perform a calculation and return a value to the 'double amount' variable in "public string startQuote".

these methods are using other objects, but these are functioning correctly

this is for an insurance company project (if any one is interested)

my code is below

C#
public string startQuote(DateTime quoteDate, string policyTypeId, double amount, DateTime obtainedLicenseDate, int numberOfFines, string carRego, int age, string make, string model, DateTime regoExpiryDate, string additionalAccessories, string carUse)
        {
            

            Car newCar = new Car(additionalAccessories,model,regoExpiryDate,make,carRego,carUse);
            string newCarResult = createNewCar(ref newCar);

            PolicyType policy = new PolicyType();
            policy = policy.getPolicyType(policyTypeId);

            Quote newQuote = new Quote("", quoteDate, policy, amount, obtainedLicenseDate, numberOfFines, newCar, age);
            string newQuoteResult = createNewQuote(ref newQuote);


            if (newQuoteResult == "Success" && newCarResult == "Success")
            {
                return "Success";
            }
            else
            {
                return "Fail";
            }
               

        }


public double calculateAmout(int age, string policyTypeId)
        {

            double amount;

            PolicyType policy = new PolicyType();
            policy = policy.getPolicyType(policyTypeId);



            if (policyTypeId == "PT+1001" & age > 25)
            {
                amount = 1500 + 0;
            }

            if (policyTypeId == "PT+1002" & age > 25)
            {
                amount = 500;
            }

            if (policyTypeId == "PT+1003" & age > 25)
            {
                amount = 1000;
            }

            if (policyTypeId == "PT+1001" & age < 25)
            {
                amount = 2500;
            }

            if (policyTypeId == "PT+1002" & age < 25)
            {
                amount = 1500;
            }

            if (policyTypeId == "PT+1003" & age < 25)
            {
                amount = 2000;
            }

            return amount;

        }


i know a case statement should be used for the public double calculateAmout method ... but this is still being built :P

cheers
Posted

You don't return value from a method to a method. You return a value to a caller, which looks like assignment operator:
C#
SomeType someVariable = SomeMethod(someParameterValue, anotherParameterValue);

where SomeType is a return type of SomeMethod.

Another way is out parameters:
C#
SomeType SomeMethod(SomeParameterType byValueParameter, out SomeOtherType byReferenceOutParameter) { /* ... */ }

//...
SomeParameterType myInput = //...
SomeOtherType actualByReferenceOutParameter; //not initialized, perfectly OK, but only for out parameters
SomeType returnedValue = SomeMethod(myInput, out actualByReferenceOutParameter);
//at this point, actualByReferenceOutParameter is initialized and a value is assigned


If looks like you need to read about C# and programming nearly from the very beginning, it can greatly help you.

Your code has too many problems. Hard-coded immediate constants like "PT+1001", "PT+1002", 25, 2000, "Success" makes code practically unsupportable, design is very ad-hoc, instead of "", string.Empty should be used, too many parameters, all is public (why), no signs of OOP…

—SA
 
Share this answer
 
Comments
sg_90 25-Apr-12 11:54am    
this is just one class .. its a 3 tier design

"PT+1001", "PT+1002" are values in an object that need to be used for this purpose
Sergey Alexandrovich Kryukov 25-Apr-12 12:31pm    
Not an excuse for hard-coding them...
--SA
So what's the problem? I can't see it.

All you need to is something like:
C#
double output = calculateAmount(age, policyTypeId);
Now, it's normal practice to use Pascal casing for method names, and you have a redundant call to getPolicyType in calculateAmount.
 
Share this answer
 
what i am trying to do is

use the 'age' and 'policyTypeId' variables in "public string startQuote".

and what ever value they have ... use that value and perform a calculation and return something to 'double amount'

getPolicyType returns the string policyTypeId

its like this

if your age is over 25 and choose a certian policy ... it will cost you x amount of dollars

thats what im trying to do
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900