Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static Object getLifeSaverMutualFromJsonString(String jsonString, List<Friend> friends, String friendId) {
- try {
- JSONObject jsonObject = new JSONObject(jsonString);
- QuestionLifeSaverMutual question = new QuestionLifeSaverMutual();
- question.setCorrectAnswer("" + jsonObject.getJSONArray("data").length());
- question.setFriendId(friendId);
- Friend aux = new Friend();
- aux.setId(friendId);
- question.setFriendName(friends.get(friends.indexOf(aux)).getName());
- question.setQuestionText("How many mutual friends do you have with " + question.getFriendName() + "?");
- question.setQuickFact(question.getFriendName() + " was born on July 17, 1984.");
- int mutualFriendCount = Integer.parseInt(question.getCorrectAnswer());
- int lowerLimit = 0;
- int upperLimit = mutualFriendCount + 20;
- if (mutualFriendCount - 20 > 0) {
- lowerLimit = mutualFriendCount - 20;
- }
- int[] generatedAnswers = GeneraUtils.getRandomOrderNumbersWithUpperLimitAndTotalSizeOf(
- lowerLimit,
- upperLimit,
- 3,
- Integer.parseInt(question.getCorrectAnswer())
- );
- String[] possibleAnswers = {""+generatedAnswers[0], ""+generatedAnswers[1], ""+generatedAnswers[2], ""+mutualFriendCount};
- int[] orderOfPossibleAnswers = GeneraUtils.getRandomOrderNumbersWithUpperLimitAndTotalSizeOf(0, 3, 4, null, null);
- question.setPossibleAnswer1(possibleAnswers[orderOfPossibleAnswers[0]]);
- question.setPossibleAnswer2(possibleAnswers[orderOfPossibleAnswers[1]]);
- question.setPossibleAnswer3(possibleAnswers[orderOfPossibleAnswers[2]]);
- question.setPossibleAnswer4(possibleAnswers[orderOfPossibleAnswers[3]]);
- return question;
- } catch (Exception e) {
- return null;
- }
- }
Add Comment
Please, Sign In to add comment