atultiwari

Utility.java

Jul 16th, 2013
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.89 KB | None | 0 0
  1. // ---- Utility.java ----//
  2. package com.atultiwari.medicalquiz;
  3.  
  4. import java.util.List;
  5.  
  6.  
  7. /**
  8.  * @author rob
  9.  *
  10.  */
  11. public class Utility {
  12.    
  13.     /**
  14.      * Method to capitalise the first letter of a given string
  15.      *
  16.      * @param s
  17.      * @return
  18.      */
  19.     public static String capitalise(String s){
  20.         if (s==null || s.length()==0) return s;
  21.        
  22.         String s1 = s.substring(0, 1).toUpperCase() + s.substring(1);
  23.         return s1;
  24.     }
  25.  
  26.     /**
  27.      * Method to get set of answers for a list of questions
  28.      * @param questions
  29.      * @return
  30.      */
  31.     public static String getAnswers(List<Question> questions) {
  32.         int question = 1;
  33.         StringBuffer sb = new StringBuffer();
  34.        
  35.         for (Question q : questions){
  36.             sb.append("Q").append(question).append(") ").append(q.getQuestion()).append("? \n");
  37.             sb.append("Answer: ").append(q.getAnswer()).append("\n\n");
  38.             question ++;
  39.         }
  40.        
  41.         return sb.toString();
  42.     }
  43.  
  44. }
Advertisement
Add Comment
Please, Sign In to add comment