You need to sign in to do that
Don't have an account?

Fibonacci series on custom object (!)
I am given a work in which I have a custom object named Fibonacci .I have to write a class and associate the same with a page so that I can take the length of Fibonacci series from the page .Thats ok .Problem is that each Numbers coming in Fibonacci series should be inserted as a record in the Fibonacci object .Help with code please .
Thanks !
Hi Sdry !
Thanx for your support .By the way I found the solution what I wanted .
All Answers
Where exactely are you stuck ? Do you know how to configure a custom object ? configure fields ? Are you unsure what fields you need ? Are you in doubt on how to store data into a custom object ? If you want us to help you .. you got to give us something more specific.
Well.....the requirement is display each individual numbers of Fibonacci series as a Record of an custom object named FIBONACCI (which I have already created) .
and I am taking the length of the series by a parameter or from visualforce page(thats not my issue)
Problem is that when I am executing the method(or clicking the CommandButton ) I wish to see record NAMEs as 1,1,2,3,5,8,13,21..... in this order .
For convenience I assumed to map those number with [FIBONACCI].Name field but if you suggest me to create another custom field in that object I will .
I know inserting a record by apex but I dont understand how to iterate the loop and insert every single numbers individually into the object .
I am sorry for providing opaque requirement I am almost new to apex development .Let me know if you need any additional info .
Thanks Sdry :)
I see no issue with using the Name field as type text for your fibonacci values, You would have 1 record for each number.
Can you show me the code of your page & controller ? or any other code you have so far. It will be easier to help based on what you have.
This is my code to display Fibonacci series .But what I want is.....to display each number (e.g :1,1,2,3,5,8.....etc) to be a part of records of the FIBONACCI sObject (means there should be individual records named with those numbers or there is another custom field in the FIBONACCI sObject in which I am displaying each numbers individually ) .I basically need to know how to use the insert() function here and map each numbers with the NAME field or with the Custom Sobject field .
Thanks and Regards !
Hi Sdry !
Thanx for your support .By the way I found the solution what I wanted .
try this code for fibonacci series
Apex code:
public class Fibonacciseries {
public string generatefibonacciseries(Integer num){
String fibonacciseries='fibonacci series :';
Integer f1=0, f2=1, nextnum=0;
for(Integer i=0; i<=num; i++){
nextnum=f1+f2;
f1=f2;
f2=nextnum;
fibonacciseries +=','+String.ValueOf(nextnum);
}
return fibonacciseries;
}
}
Annoymous window:
Fibonacciseries f=new Fibonacciseries();
system.debug(f.generatefibonacciseries(8));
public class Fibonacciseries {
public string generateFibonacciseries(Integer n){
String fibonacciseries='fibonacci series :';
Integer f1=0, f2=1, nextnum=0;
for(Integer i=0; i<=n; i++){
nextnum=f1+f2;
f1=f2;
f2=nextnum;
fibonacciseries +=String.ValueOf(nextnum)+',';
}
return fibonacciseries;
}
}