Revision: 1774
Author: [email protected]
Date: Thu Dec 10 05:22:44 2009
Log: Create hashmap of questions and provide a human readable label as a key
http://code.google.com/p/simal/source/detail?r=1774

Modified:
   
/trunk/uk.ac.osswatch.simal.ssmm/src/main/uk/ac/osswatch/simal/ssmm/SustainabilityRating.java
   
/trunk/uk.ac.osswatch.simal.ssmm/src/main/uk/ac/osswatch/simal/ssmm/model/Question.java
   
/trunk/uk.ac.osswatch.simal.ssmm/src/test/uk/ac/osswatch/simal/ssmm/model/QuestionTest.java

=======================================
---  
/trunk/uk.ac.osswatch.simal.ssmm/src/main/uk/ac/osswatch/simal/ssmm/SustainabilityRating.java
    
Thu Dec 10 03:46:15 2009
+++  
/trunk/uk.ac.osswatch.simal.ssmm/src/main/uk/ac/osswatch/simal/ssmm/SustainabilityRating.java
    
Thu Dec 10 05:22:44 2009
@@ -1,12 +1,14 @@
  package uk.ac.osswatch.simal.ssmm;

+import java.util.LinkedHashMap;
  import java.util.Scanner;

  import uk.ac.osswatch.simal.ssmm.model.Question;

  public class SustainabilityRating {

-         private static final Object HELP_COMMAND = "help";
+  private static final Object HELP_COMMAND = "help";
+  private static LinkedHashMap<String, Question> questions = new  
LinkedHashMap<String, Question>();

        /**
           * @param args
@@ -16,7 +18,8 @@
                  System.out.println("If you want more details type '" + 
HELP_COMMAND  
+ "'");
                  System.out.println("If you are unsure of the answer simply 
press  
enter");

-                 Question question = new Question("What is the project name?", 
"Please  
provide a project name.");
+                 Question question = new Question("Project name", "What is the 
project  
name?", "Please provide a project name.");
+                 questions.put(question.getLabel(), question);
                  String answer = askQuestion(question);
                  System.out.println("Name: " + answer);
          }
@@ -29,6 +32,12 @@
         * @return
         */
        private static String askQuestion(Question question) {
+               System.out.println("\n");
+               System.out.println(question.getLabel());
+               for (int i = 0; i < question.getLabel().length(); i++) {
+                       System.out.print("=");
+               }
+               System.out.println("\n");
                System.out.println(question.getText());
                Scanner in = new Scanner(System.in);
                String answer = in.nextLine();
=======================================
---  
/trunk/uk.ac.osswatch.simal.ssmm/src/main/uk/ac/osswatch/simal/ssmm/model/Question.java
  
Thu Dec 10 03:46:15 2009
+++  
/trunk/uk.ac.osswatch.simal.ssmm/src/main/uk/ac/osswatch/simal/ssmm/model/Question.java
  
Thu Dec 10 05:22:44 2009
@@ -8,16 +8,19 @@
        String text;
        String details;
        String answer;
+       private String label;

        /**
         * Create a default question that accepts a text response.
         *
+        * @param label a human readable label for the question
         * @param text - the text of the question
         * @param details - a description of the question
         * @param answer - a default answer
         */
-       public Question(String text, String details,
+       public Question(String label, String text, String details,
                        String answer) {
+               setLabel(label);
                setText(text);
                setDetails(details);
                setAnswer(answer);
@@ -26,10 +29,12 @@
        /**
         * Create a default question that accepts a text response.
         *
+        * @param label a human readable label for the question
         * @param text the text of the question
         * @param details a description of the question
         */
-       public Question(String text, String details) {
+       public Question(String label, String text, String details) {
+               setLabel(label);
                setText(text);
                setDetails(details);
        }
@@ -78,5 +83,21 @@
        public void setAnswer(String answer) {
                this.answer = answer;
        }
+
+       /**
+        * Get a human readable label for this question.
+        * @return
+        */
+       public String getLabel() {
+               return label;
+       }
+
+       /**
+        * Set a human readable label for this question.
+        * @return
+        */
+       public void setLabel(String newLabel) {
+               this.label = newLabel;
+       }

  }
=======================================
---  
/trunk/uk.ac.osswatch.simal.ssmm/src/test/uk/ac/osswatch/simal/ssmm/model/QuestionTest.java
      
Thu Dec 10 03:46:15 2009
+++  
/trunk/uk.ac.osswatch.simal.ssmm/src/test/uk/ac/osswatch/simal/ssmm/model/QuestionTest.java
      
Thu Dec 10 05:22:44 2009
@@ -10,7 +10,8 @@
   *
   */
  public class QuestionTest {
-
+
+       static String QUESTION_LABEL = "Test Label";
        static String QUESTION_TEXT = "Is this a question?";
        static String QUESTION_DETAILS = "This is just a question for testing.";
        static String QUESTION_ANSWER = "Yes, of course it's a question.";
@@ -19,15 +20,27 @@

        @BeforeClass
        public static void createQuestion() {
-               question = new Question(QUESTION_TEXT, QUESTION_DETAILS,  
QUESTION_ANSWER);
+               question = new Question(QUESTION_LABEL, QUESTION_TEXT, 
QUESTION_DETAILS,  
QUESTION_ANSWER);
        }

        @Test
        public void testCreateQuestion(){
-               Question test = new Question(QUESTION_TEXT, QUESTION_DETAILS);
+               Question test = new Question(QUESTION_LABEL, QUESTION_TEXT,  
QUESTION_DETAILS);
                assertEquals("Question text is incorrect", QUESTION_TEXT,  
test.getText());
                assertEquals("Description for question is not being set 
correctly",  
QUESTION_DETAILS, test.getDetails());
        }
+
+       @Test
+       public void testGetLabel() {
+               assertEquals("Question label is incorrect", QUESTION_LABEL,  
question.getLabel());
+       }
+
+       @Test
+       public void testSetLabel() {
+               question.setLabel("testing");
+               assertEquals("Question label is not being set correctly", 
"testing",  
question.getLabel());
+               question.setLabel(QUESTION_LABEL);
+       }

        @Test
        public void testGetText() {

--

You received this message because you are subscribed to the Google Groups 
"Simal Commits" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/simal-commits?hl=en.


Reply via email to