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

how can i solve the following requirment
Hai guys,
I have a requirment.
The Apex class must be called 'StringArrayTest' and be in the public scope.
The Apex class must have a public static method called 'generateStringArray'.
The 'generateStringArray' method must return an array (or list) of strings. Each string must have a value in the format 'Test n' where n is the index of the current string in the array. The number of returned strings is specified by the integer parameter to the 'generateStringArray' method.
As of my understanding i created apex class.
public class StringArrayTest { public static list<string> generateStringArray() { list<string> ss = new list<string>(); ss.add('Test 0'); ss.add('Test 1'); ss.add('Test 2'); ss.add('Test 3'); ss.add('Test 4'); ss.add('Test 5'); ss.add('Test 6'); ss.add('Test 7'); ss.add('Test 8'); system.debug('the list of strings are='+ss); return ss; } }
but it is not staisfy the requirement .please help me any to slove the requirment
I have a requirment.
The Apex class must be called 'StringArrayTest' and be in the public scope.
The Apex class must have a public static method called 'generateStringArray'.
The 'generateStringArray' method must return an array (or list) of strings. Each string must have a value in the format 'Test n' where n is the index of the current string in the array. The number of returned strings is specified by the integer parameter to the 'generateStringArray' method.
As of my understanding i created apex class.
public class StringArrayTest { public static list<string> generateStringArray() { list<string> ss = new list<string>(); ss.add('Test 0'); ss.add('Test 1'); ss.add('Test 2'); ss.add('Test 3'); ss.add('Test 4'); ss.add('Test 5'); ss.add('Test 6'); ss.add('Test 7'); ss.add('Test 8'); system.debug('the list of strings are='+ss); return ss; } }
but it is not staisfy the requirement .please help me any to slove the requirment
Ashok, you should read the exercise again so that you are confortable with the different aspect of the exercise.
The Apex class must be called 'StringArrayTest' and be in the public scope.
--> public class StringArrayTest{
The Apex class must have a public static method called 'generateStringArray'.
-->public static List<String> generateStringArray(Integer n) {
The 'generateStringArray' method must return an array (or list) of strings.
-->public static List<String> generateStringArray(Integer n) {
Each string must have a value in the format 'Test n' where n is the index of the current string in the array.
s= 'Test ' + x;
The number of returned strings is specified by the integer parameter to the 'generateStringArray' method.
public static List<String> generateStringArray(Integer n) {
The whole solution:
Also,
As a common practice, if your question is answered, please choose 1 best answer.
But you can give every answer a thumb up if that answer is helpful to you.
Thanks
All Answers
Please try using loops (for, while). See below code.
Ashok, you should read the exercise again so that you are confortable with the different aspect of the exercise.
The Apex class must be called 'StringArrayTest' and be in the public scope.
--> public class StringArrayTest{
The Apex class must have a public static method called 'generateStringArray'.
-->public static List<String> generateStringArray(Integer n) {
The 'generateStringArray' method must return an array (or list) of strings.
-->public static List<String> generateStringArray(Integer n) {
Each string must have a value in the format 'Test n' where n is the index of the current string in the array.
s= 'Test ' + x;
The number of returned strings is specified by the integer parameter to the 'generateStringArray' method.
public static List<String> generateStringArray(Integer n) {
The whole solution:
Also,
As a common practice, if your question is answered, please choose 1 best answer.
But you can give every answer a thumb up if that answer is helpful to you.
Thanks
here another requirment
The Apex class must be called 'AccountHandler' and be in the public scope.
The Apex class must have a public static method called 'insertNewAccount'.
The 'insertNewAccount' method must accept an incoming string as a parameter, name the account after the parameter, insert it into the system and then return the account record.
The 'insertNewAccount' method must also accept an empty string, catch the failed DML and return null.
i did not understand this requirment please explain me any one
The Apex class must be called 'AccountHandler' and be in the public scope.
-->public class AccountHandler{
The Apex class must have a public static method called 'insertNewAccount'.
--> public static account insertNewAccount(string s){
The 'insertNewAccount' method must accept an incoming string as a parameter,
--> public static account insertNewAccount(string s){
name the account after the parameter,
set the name of the account equal to the string s (try to do it).
insert it into the system and then return the account record.
--> insert acc;
The 'insertNewAccount' method must also accept an empty string, catch the failed DML and return null.
--> catch (DmlException e) {......... try to fill in the rest
Try putting it all together, if you still have issue, post a new question with what you got and either I or someone else will help.
Thx
By the way, be sure to give thumbs up to any answer that helped you.
Doing so will give encouragement for people for helping you out (it's like a thank you).