SlideShare a Scribd company logo
1 of 2
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);
}

      /**
        * 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);
      }

}

More Related Content

What's hot

The Ring programming language version 1.8 book - Part 37 of 202
The Ring programming language version 1.8 book - Part 37 of 202The Ring programming language version 1.8 book - Part 37 of 202
The Ring programming language version 1.8 book - Part 37 of 202Mahmoud Samir Fayed
 
Java Generics Introduction - Syntax Advantages and Pitfalls
Java Generics Introduction - Syntax Advantages and PitfallsJava Generics Introduction - Syntax Advantages and Pitfalls
Java Generics Introduction - Syntax Advantages and PitfallsRakesh Waghela
 
Java Foundations: Lists, ArrayList<T>
Java Foundations: Lists, ArrayList<T>Java Foundations: Lists, ArrayList<T>
Java Foundations: Lists, ArrayList<T>Svetlin Nakov
 
Java chapter 6 - Arrays -syntax and use
Java chapter 6 - Arrays -syntax and useJava chapter 6 - Arrays -syntax and use
Java chapter 6 - Arrays -syntax and useMukesh Tekwani
 
Functions & closures
Functions & closuresFunctions & closures
Functions & closuresKnoldus Inc.
 
Python programming Part -6
Python programming Part -6Python programming Part -6
Python programming Part -6Megha V
 
On Parameterised Types and Java Generics
On Parameterised Types and Java GenericsOn Parameterised Types and Java Generics
On Parameterised Types and Java GenericsYann-Gaël Guéhéneuc
 
List,tuple,dictionary
List,tuple,dictionaryList,tuple,dictionary
List,tuple,dictionarynitamhaske
 
Linked Lists: The Role of Locking : The Art of Multiprocessor Programming : N...
Linked Lists: The Role of Locking : The Art of Multiprocessor Programming : N...Linked Lists: The Role of Locking : The Art of Multiprocessor Programming : N...
Linked Lists: The Role of Locking : The Art of Multiprocessor Programming : N...Subhajit Sahu
 
Python Variable Types, List, Tuple, Dictionary
Python Variable Types, List, Tuple, DictionaryPython Variable Types, List, Tuple, Dictionary
Python Variable Types, List, Tuple, DictionarySoba Arjun
 
Python Workshop Part 2. LUG Maniapl
Python Workshop Part 2. LUG ManiaplPython Workshop Part 2. LUG Maniapl
Python Workshop Part 2. LUG ManiaplAnkur Shrivastava
 
Lecture 8 abstract class and interface
Lecture   8 abstract class and interfaceLecture   8 abstract class and interface
Lecture 8 abstract class and interfacemanish kumar
 

What's hot (19)

Generics
GenericsGenerics
Generics
 
Chapter 16 Dictionaries
Chapter 16 DictionariesChapter 16 Dictionaries
Chapter 16 Dictionaries
 
The Ring programming language version 1.8 book - Part 37 of 202
The Ring programming language version 1.8 book - Part 37 of 202The Ring programming language version 1.8 book - Part 37 of 202
The Ring programming language version 1.8 book - Part 37 of 202
 
Java Collections
Java  Collections Java  Collections
Java Collections
 
Java Generics Introduction - Syntax Advantages and Pitfalls
Java Generics Introduction - Syntax Advantages and PitfallsJava Generics Introduction - Syntax Advantages and Pitfalls
Java Generics Introduction - Syntax Advantages and Pitfalls
 
Java2
Java2Java2
Java2
 
Java Foundations: Lists, ArrayList<T>
Java Foundations: Lists, ArrayList<T>Java Foundations: Lists, ArrayList<T>
Java Foundations: Lists, ArrayList<T>
 
Java chapter 6 - Arrays -syntax and use
Java chapter 6 - Arrays -syntax and useJava chapter 6 - Arrays -syntax and use
Java chapter 6 - Arrays -syntax and use
 
C# Generics
C# GenericsC# Generics
C# Generics
 
Functions & closures
Functions & closuresFunctions & closures
Functions & closures
 
Python programming Part -6
Python programming Part -6Python programming Part -6
Python programming Part -6
 
Generics collections
Generics collectionsGenerics collections
Generics collections
 
On Parameterised Types and Java Generics
On Parameterised Types and Java GenericsOn Parameterised Types and Java Generics
On Parameterised Types and Java Generics
 
List,tuple,dictionary
List,tuple,dictionaryList,tuple,dictionary
List,tuple,dictionary
 
Linked Lists: The Role of Locking : The Art of Multiprocessor Programming : N...
Linked Lists: The Role of Locking : The Art of Multiprocessor Programming : N...Linked Lists: The Role of Locking : The Art of Multiprocessor Programming : N...
Linked Lists: The Role of Locking : The Art of Multiprocessor Programming : N...
 
Python Variable Types, List, Tuple, Dictionary
Python Variable Types, List, Tuple, DictionaryPython Variable Types, List, Tuple, Dictionary
Python Variable Types, List, Tuple, Dictionary
 
Java Generics - by Example
Java Generics - by ExampleJava Generics - by Example
Java Generics - by Example
 
Python Workshop Part 2. LUG Maniapl
Python Workshop Part 2. LUG ManiaplPython Workshop Part 2. LUG Maniapl
Python Workshop Part 2. LUG Maniapl
 
Lecture 8 abstract class and interface
Lecture   8 abstract class and interfaceLecture   8 abstract class and interface
Lecture 8 abstract class and interface
 

Viewers also liked

Temen a la oficina de vacaciones partyh Aquí es cómo hacer frente
Temen a la oficina de vacaciones partyh Aquí es cómo hacer frenteTemen a la oficina de vacaciones partyh Aquí es cómo hacer frente
Temen a la oficina de vacaciones partyh Aquí es cómo hacer frentebumpyworker6875
 
Aruba Certified Expert Program - View Certificate
Aruba Certified Expert Program - View CertificateAruba Certified Expert Program - View Certificate
Aruba Certified Expert Program - View CertificateTinoka McPherson
 
Problemas fundamentales de la humanidad
Problemas fundamentales de la humanidadProblemas fundamentales de la humanidad
Problemas fundamentales de la humanidadJagg602
 

Viewers also liked (11)

Anthony Peppe III
Anthony Peppe IIIAnthony Peppe III
Anthony Peppe III
 
USDS
USDSUSDS
USDS
 
Astrotec About Us
Astrotec About UsAstrotec About Us
Astrotec About Us
 
Temen a la oficina de vacaciones partyh Aquí es cómo hacer frente
Temen a la oficina de vacaciones partyh Aquí es cómo hacer frenteTemen a la oficina de vacaciones partyh Aquí es cómo hacer frente
Temen a la oficina de vacaciones partyh Aquí es cómo hacer frente
 
Front Marquis
Front MarquisFront Marquis
Front Marquis
 
Aruba Certified Expert Program - View Certificate
Aruba Certified Expert Program - View CertificateAruba Certified Expert Program - View Certificate
Aruba Certified Expert Program - View Certificate
 
Certificate III in IT
Certificate III in ITCertificate III in IT
Certificate III in IT
 
Problemas fundamentales de la humanidad
Problemas fundamentales de la humanidadProblemas fundamentales de la humanidad
Problemas fundamentales de la humanidad
 
Logo de caifanes jaguares
Logo de caifanes jaguaresLogo de caifanes jaguares
Logo de caifanes jaguares
 
Lopo Lesman
Lopo LesmanLopo Lesman
Lopo Lesman
 
20160716100627
2016071610062720160716100627
20160716100627
 

Similar to Xxxx

OrderTest.javapublic class OrderTest {       Get an arra.pdf
OrderTest.javapublic class OrderTest {         Get an arra.pdfOrderTest.javapublic class OrderTest {         Get an arra.pdf
OrderTest.javapublic class OrderTest {       Get an arra.pdfakkhan101
 
META-INFMANIFEST.MFManifest-Version 1.0.classpath.docx
META-INFMANIFEST.MFManifest-Version 1.0.classpath.docxMETA-INFMANIFEST.MFManifest-Version 1.0.classpath.docx
META-INFMANIFEST.MFManifest-Version 1.0.classpath.docxandreecapon
 
package singlylinkedlist; public class Node { public String valu.pdf
package singlylinkedlist; public class Node { public String valu.pdfpackage singlylinkedlist; public class Node { public String valu.pdf
package singlylinkedlist; public class Node { public String valu.pdfamazing2001
 
ReversePoem.java ---------------------------------- public cl.pdf
ReversePoem.java ---------------------------------- public cl.pdfReversePoem.java ---------------------------------- public cl.pdf
ReversePoem.java ---------------------------------- public cl.pdfravikapoorindia
 
Labprogram.javaLinkedList.javaimport java.util.NoSuchElementEx.pdf
Labprogram.javaLinkedList.javaimport java.util.NoSuchElementEx.pdfLabprogram.javaLinkedList.javaimport java.util.NoSuchElementEx.pdf
Labprogram.javaLinkedList.javaimport java.util.NoSuchElementEx.pdffreddysarabia1
 
Copy your completed LinkedList class from Lab 3 into the LinkedList..pdf
Copy your completed LinkedList class from Lab 3 into the LinkedList..pdfCopy your completed LinkedList class from Lab 3 into the LinkedList..pdf
Copy your completed LinkedList class from Lab 3 into the LinkedList..pdffacevenky
 
LabProgram.javaimport java.util.NoSuchElementException;public .pdf
LabProgram.javaimport java.util.NoSuchElementException;public .pdfLabProgram.javaimport java.util.NoSuchElementException;public .pdf
LabProgram.javaimport java.util.NoSuchElementException;public .pdffantasiatheoutofthef
 
Given the code below create a method called, getCollisionCount that .pdf
Given the code below create a method called, getCollisionCount that .pdfGiven the code below create a method called, getCollisionCount that .pdf
Given the code below create a method called, getCollisionCount that .pdfaucmistry
 
File LinkedList.java Defines a doubly-l.pdf
File LinkedList.java Defines a doubly-l.pdfFile LinkedList.java Defines a doubly-l.pdf
File LinkedList.java Defines a doubly-l.pdfConint29
 
New folderjsjfArrayStack.classpackage jsjf;publicsynchronize.docx
New folderjsjfArrayStack.classpackage jsjf;publicsynchronize.docxNew folderjsjfArrayStack.classpackage jsjf;publicsynchronize.docx
New folderjsjfArrayStack.classpackage jsjf;publicsynchronize.docxcurwenmichaela
 
Class DiagramIn the Assignment #10, you are given three files Ass.pdf
Class DiagramIn the Assignment #10, you are given three files Ass.pdfClass DiagramIn the Assignment #10, you are given three files Ass.pdf
Class DiagramIn the Assignment #10, you are given three files Ass.pdfxlynettalampleyxc
 
How do I fix it in LinkedList.javaLabProgram.javaLinkedList.jav.pdf
How do I fix it in LinkedList.javaLabProgram.javaLinkedList.jav.pdfHow do I fix it in LinkedList.javaLabProgram.javaLinkedList.jav.pdf
How do I fix it in LinkedList.javaLabProgram.javaLinkedList.jav.pdfmail931892
 
Please help me to make a programming project I have to sue them today- (1).pdf
Please help me to make a programming project I have to sue them today- (1).pdfPlease help me to make a programming project I have to sue them today- (1).pdf
Please help me to make a programming project I have to sue them today- (1).pdfseoagam1
 
java write a program to evaluate the postfix expressionthe program.pdf
java write a program to evaluate the postfix expressionthe program.pdfjava write a program to evaluate the postfix expressionthe program.pdf
java write a program to evaluate the postfix expressionthe program.pdfarjuntelecom26
 
Javai have to make a method that takes a linked list and then retu.pdf
Javai have to make a method that takes a linked list and then retu.pdfJavai have to make a method that takes a linked list and then retu.pdf
Javai have to make a method that takes a linked list and then retu.pdfstopgolook
 
How do I fix it in javaLinkedList.java Defines a doubl.pdf
How do I fix it in javaLinkedList.java Defines a doubl.pdfHow do I fix it in javaLinkedList.java Defines a doubl.pdf
How do I fix it in javaLinkedList.java Defines a doubl.pdffmac5
 
How do I fix it in LinkedList.javaLinkedList.java Define.pdf
How do I fix it in LinkedList.javaLinkedList.java Define.pdfHow do I fix it in LinkedList.javaLinkedList.java Define.pdf
How do I fix it in LinkedList.javaLinkedList.java Define.pdfmail931892
 
we using java code DynamicArrayjava Replace all .pdf
we using java code   DynamicArrayjava   Replace all .pdfwe using java code   DynamicArrayjava   Replace all .pdf
we using java code DynamicArrayjava Replace all .pdfgudduraza28
 

Similar to Xxxx (20)

OrderTest.javapublic class OrderTest {       Get an arra.pdf
OrderTest.javapublic class OrderTest {         Get an arra.pdfOrderTest.javapublic class OrderTest {         Get an arra.pdf
OrderTest.javapublic class OrderTest {       Get an arra.pdf
 
META-INFMANIFEST.MFManifest-Version 1.0.classpath.docx
META-INFMANIFEST.MFManifest-Version 1.0.classpath.docxMETA-INFMANIFEST.MFManifest-Version 1.0.classpath.docx
META-INFMANIFEST.MFManifest-Version 1.0.classpath.docx
 
package singlylinkedlist; public class Node { public String valu.pdf
package singlylinkedlist; public class Node { public String valu.pdfpackage singlylinkedlist; public class Node { public String valu.pdf
package singlylinkedlist; public class Node { public String valu.pdf
 
ReversePoem.java ---------------------------------- public cl.pdf
ReversePoem.java ---------------------------------- public cl.pdfReversePoem.java ---------------------------------- public cl.pdf
ReversePoem.java ---------------------------------- public cl.pdf
 
Labprogram.javaLinkedList.javaimport java.util.NoSuchElementEx.pdf
Labprogram.javaLinkedList.javaimport java.util.NoSuchElementEx.pdfLabprogram.javaLinkedList.javaimport java.util.NoSuchElementEx.pdf
Labprogram.javaLinkedList.javaimport java.util.NoSuchElementEx.pdf
 
Copy your completed LinkedList class from Lab 3 into the LinkedList..pdf
Copy your completed LinkedList class from Lab 3 into the LinkedList..pdfCopy your completed LinkedList class from Lab 3 into the LinkedList..pdf
Copy your completed LinkedList class from Lab 3 into the LinkedList..pdf
 
LabProgram.javaimport java.util.NoSuchElementException;public .pdf
LabProgram.javaimport java.util.NoSuchElementException;public .pdfLabProgram.javaimport java.util.NoSuchElementException;public .pdf
LabProgram.javaimport java.util.NoSuchElementException;public .pdf
 
Given the code below create a method called, getCollisionCount that .pdf
Given the code below create a method called, getCollisionCount that .pdfGiven the code below create a method called, getCollisionCount that .pdf
Given the code below create a method called, getCollisionCount that .pdf
 
File LinkedList.java Defines a doubly-l.pdf
File LinkedList.java Defines a doubly-l.pdfFile LinkedList.java Defines a doubly-l.pdf
File LinkedList.java Defines a doubly-l.pdf
 
New folderjsjfArrayStack.classpackage jsjf;publicsynchronize.docx
New folderjsjfArrayStack.classpackage jsjf;publicsynchronize.docxNew folderjsjfArrayStack.classpackage jsjf;publicsynchronize.docx
New folderjsjfArrayStack.classpackage jsjf;publicsynchronize.docx
 
Class DiagramIn the Assignment #10, you are given three files Ass.pdf
Class DiagramIn the Assignment #10, you are given three files Ass.pdfClass DiagramIn the Assignment #10, you are given three files Ass.pdf
Class DiagramIn the Assignment #10, you are given three files Ass.pdf
 
How do I fix it in LinkedList.javaLabProgram.javaLinkedList.jav.pdf
How do I fix it in LinkedList.javaLabProgram.javaLinkedList.jav.pdfHow do I fix it in LinkedList.javaLabProgram.javaLinkedList.jav.pdf
How do I fix it in LinkedList.javaLabProgram.javaLinkedList.jav.pdf
 
Please help me to make a programming project I have to sue them today- (1).pdf
Please help me to make a programming project I have to sue them today- (1).pdfPlease help me to make a programming project I have to sue them today- (1).pdf
Please help me to make a programming project I have to sue them today- (1).pdf
 
java write a program to evaluate the postfix expressionthe program.pdf
java write a program to evaluate the postfix expressionthe program.pdfjava write a program to evaluate the postfix expressionthe program.pdf
java write a program to evaluate the postfix expressionthe program.pdf
 
Javai have to make a method that takes a linked list and then retu.pdf
Javai have to make a method that takes a linked list and then retu.pdfJavai have to make a method that takes a linked list and then retu.pdf
Javai have to make a method that takes a linked list and then retu.pdf
 
How do I fix it in javaLinkedList.java Defines a doubl.pdf
How do I fix it in javaLinkedList.java Defines a doubl.pdfHow do I fix it in javaLinkedList.java Defines a doubl.pdf
How do I fix it in javaLinkedList.java Defines a doubl.pdf
 
Java Generics
Java GenericsJava Generics
Java Generics
 
How do I fix it in LinkedList.javaLinkedList.java Define.pdf
How do I fix it in LinkedList.javaLinkedList.java Define.pdfHow do I fix it in LinkedList.javaLinkedList.java Define.pdf
How do I fix it in LinkedList.javaLinkedList.java Define.pdf
 
Java programs
Java programsJava programs
Java programs
 
we using java code DynamicArrayjava Replace all .pdf
we using java code   DynamicArrayjava   Replace all .pdfwe using java code   DynamicArrayjava   Replace all .pdf
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); } }