we using java code DynamicArrayjava Replace all .pdf
Xxxx
1. package com.imk;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
final class tanya {
private final String questionType;
private final String bilangan;
private final ArrayList<String> answers;
private tanya(final String questionType, final String bilangan,
final ArrayList<String> answers) {
this.questionType = questionType;
this.bilangan = bilangan;
this.answers = answers;
}
/**
* Takes a comma separated String of the question type, the question, and
* the answers, and returns a {@link tanya} representation of them.
*
* @param input
* The input String made up of the type of question, the
question
* itself, and the answers (comma separated).
* @return a {@link tanya} representation of the input string.
* @throws IllegalArgumentException
*/
public static tanya parse(final String input)
throws IllegalArgumentException {
final String[] questionComponents;
final String questionType;
final String bilangan;
final ArrayList<String> answers = new ArrayList<String>();
// Split the input on commas
if (null != input) {
questionComponents = input.split(",");
} else {
throw new IllegalArgumentException(
"Question to be parsed was null."); // Dev String
}
// Extract the component parts of the question
if (4 < questionComponents.length) {
questionType = questionComponents[0].trim();
bilangan = questionComponents[1].trim();
for (int i = 2; i < questionComponents.length; i++) {
answers.add(questionComponents[i].trim());
}
} else {
throw new IllegalArgumentException(
"Question had insufficient parts. Note that at
least two answers are required."); // Dev
// String
}
// Construct and return a new Question
return new tanya(questionType, bilangan, answers);
2. }
/**
* Returns the type of the {@link tanya}
*
* @return the type of the {@link tanya}
*/
public final String getQuestionType() {
return questionType;
}
/**
* Returns the question element of the {@link tanya}
*
* @return the question element of the {@link tanya}
*/
public final String getQuestion() {
return bilangan;
}
/**
* Returns the answers, in a random order, as an ArrayList of String
*
* @return the answers, in a random order, as an ArrayList of String
*/
public final List<String> getAnswers() {
// ArryList is not immutable, create a defensive copy
final ArrayList<String> answers = new
ArrayList<String>(this.answers);
Collections.shuffle(answers);
return answers;
}
/**
* Returns the correct answer to the {@link tanya}
*
* @return the correct answer to the {@link tanya}
*/
public final String getAnswer() {
return answers.get(0);
}
}