Question

In Java, write JUnit tests to verify various question-type objects for the following below: public interface...

In Java, write JUnit tests to verify various question-type objects for the following below:

public interface IAnswer {

   public String getAnswer();

   }

import java.util.Scanner;

YesNo class:

public class YesNo implements IAnswer{

           private String question;

           public YesNo(String q){

               this.question = q;

           }
          
           //This function returns question text
           public String getQuestionText() {
               return question;
           }
          
           //This function takes answer from user
           public void answer(String userAnswer) {
               // Take care of answer
           }

           @Override

           public String getAnswer() {

               System.out.println(question);

               Scanner scan = new Scanner(System.in);

               String ans =scan.nextLine();

               System.out.print("Answer: ");

               scan.close();

               if(ans.equalsIgnoreCase("yes") || ans.equalsIgnoreCase("no")){

                   return ans;

               }else{

                   return "Invalid Answer";

               }

}

}

Essay class:

import java.util.Scanner;

public class Essay implements IAnswer{

private String question;

public Essay(String q){

this.question = q;

}

//This function returns question text
public String getQuestionText() {
   return question;
}

//This function takes answer from user
public void answer(String userAnswer) {
   // Take care of answer
}

@Override

public String getAnswer() {

System.out.println(question);

Scanner scan = new Scanner(System.in);

System.out.print("Answer: ");

String ans =scan.nextLine();

scan.close();

if(ans.length() <=140){

return ans;

}else{

return "Invalid Answer";

}

}

}

Likert class:

import java.util.Scanner;

public class Likert implements IAnswer {

   private String question;

   public Likert(String q) {

       this.question = q;

   }
  
   //This function returns question text
   public String getQuestionText() {
       return question;
   }
  
   //This function takes answer from user
   public void answer(String userAnswer) {
       // Take care of answer
   }

   @Override

   public String getAnswer() {

       System.out.println(question);

       Scanner scan = new Scanner(System.in);

       System.out.print("Answer: ");

       String ans = scan.nextLine();

       scan.close();

       if (ans.equalsIgnoreCase("Strongly Agree")

               || ans.equalsIgnoreCase("Agree")

               || ans.equalsIgnoreCase("Neither Agree nor Disagree")

               || ans.equalsIgnoreCase("Disagree")

               || ans.equalsIgnoreCase("Strongly Disagree")) {

           return ans;

       } else {

           return "Invalid Answer";

       }

   }

}

0 0
Add a comment Improve this question Transcribed image text
Answer #1

public interface IAnswer {

public String getAnswer();

}

import java.util.Scanner;

YesNo class:

public class YesNo implements IAnswer{

private String question;

public YesNo(String q){

this.question = q;

}

//This function returns question text
public String getQuestionText() {
return question;
}

//This function takes answer from user
public void answer(String userAnswer) {
// Take care of answer
}

@Override

public String getAnswer() {

System.out.println(question);

Scanner scan = new Scanner(System.in);

String ans =scan.nextLine();

System.out.print("Answer: ");

scan.close();

if(ans.equalsIgnoreCase("yes") || ans.equalsIgnoreCase("no")){

return ans;

}else{

return "Invalid Answer";

}

}

}

Essay class:

import java.util.Scanner;

public class Essay implements IAnswer{

private String question;

public Essay(String q){

this.question = q;

}

//This function returns question text
public String getQuestionText() {
return question;
}

//This function takes answer from user
public void answer(String userAnswer) {
// Take care of answer
}

@Override

public String getAnswer() {

System.out.println(question);

Scanner scan = new Scanner(System.in);

System.out.print("Answer: ");

String ans =scan.nextLine();

scan.close();

if(ans.length() <=140){

return ans;

}else{

return "Invalid Answer";

}

}

}

Likert class:

import java.util.Scanner;

public class Likert implements IAnswer {

private String question;

public Likert(String q) {

this.question = q;

}

//This function returns question text
public String getQuestionText() {
return question;
}

//This function takes answer from user
public void answer(String userAnswer) {
// Take care of answer
}

@Override

public String getAnswer() {

System.out.println(question);

Scanner scan = new Scanner(System.in);

System.out.print("Answer: ");

String ans = scan.nextLine();

scan.close();

if (ans.equalsIgnoreCase("Strongly Agree")

|| ans.equalsIgnoreCase("Agree")

|| ans.equalsIgnoreCase("Neither Agree nor Disagree")

|| ans.equalsIgnoreCase("Disagree")

|| ans.equalsIgnoreCase("Strongly Disagree")) {

return ans;

} else {

return "Invalid Answer";

}

}

}

Main class:

public class Main {

public static void main(String[] args) {

YesNo yesno = new YesNo("Do you like coffeee?");

System.out.println(yesno.getAnswer());

}

}

Add a comment
Know the answer?
Add Answer to:
In Java, write JUnit tests to verify various question-type objects for the following below: public interface...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write one JUnit test in Java for the following: Essay class: import java.util.Scanner; public class Essay implements IAn...

    Write one JUnit test in Java for the following: Essay class: import java.util.Scanner; public class Essay implements IAnswer{ private String question; public Essay(String q){ this.question = q; } //This function returns question text public String getQuestionText() {    return question; } //This function takes answer from user public void answer(String userAnswer) {    // Take care of answer } @Override public String getAnswer() { System.out.println(question); Scanner scan = new Scanner(System.in); System.out.print("Answer: "); String ans =scan.nextLine(); scan.close(); if(ans.length() <=140){ return ans; }else{ return...

  • Help check why the exception exist do some change but be sure to use the printwriter...

    Help check why the exception exist do some change but be sure to use the printwriter and scanner and make the code more readability Input.txt format like this: Joe sam, thd, 9, 4, 20 import java.io.File; import java.io.PrintWriter; import java.io.IOException; import java.io.FileNotFoundException; import java.io.FileWriter; import java.util.Scanner; public class Main1 { private static final Scanner scan = new Scanner(System.in); private static String[] player = new String[622]; private static String DATA = " "; private static int COUNTS = 0; public static...

  • You will write a single java program called MadLibs. java.

    You will write a single java program called MadLibs. java. This file will hold and allow access to the values needed to handle the details for a "MadLibs" game. This class will not contain a maino method. It will not ask the user for any input, nor will it display (via System.out.print/In()) information to the user. The job of this class is to manage information, not to interact with the user.I am providing a MadLibsDriver.java e^{*} program that you can...

  • write a program which include a class containing an array of words (strings).The program will search...

    write a program which include a class containing an array of words (strings).The program will search the array for a specific word. if it finds the word:it will return a true value.if the array does not contain the word. it will return a false value. enhancements: make the array off words dynamic, so that the use is prompter to enter the list of words. make the word searcher for dynamic, so that a different word can be searched for each...

  • Make a FLOWCHART for the following JAVA Prime Number Guessing Game. import java.util.Random; import java.util.Scanner; public...

    Make a FLOWCHART for the following JAVA Prime Number Guessing Game. import java.util.Random; import java.util.Scanner; public class Project2 { //Creating an random class object static Random r = new Random(); public static void main(String[] args) {    char compAns,userAns,ans; int cntUser=0,cntComp=0; /* * Creating an Scanner class object which is used to get the inputs * entered by the user */ Scanner sc = new Scanner(System.in);       System.out.println("*************************************"); System.out.println("Prime Number Guessing Game"); System.out.println("Y = Yes , N = No...

  • I Need UML Design for the following Java code: Colorable interface: public interface Colorable { //a...

    I Need UML Design for the following Java code: Colorable interface: public interface Colorable { //a void method named howToColor(). void howToColor(); } GeometricObject class: public class GeometricObject { } Sqaure class: public class Square extends GeometricObject implements Colorable{ //side variable of Square double side;    //Implementing howToColor() @Override public void howToColor() { System.out.println("Color all four sides."); }    //setter and getter methods for Square public void setSide(double side) { this.side = side; }    public double getSide() { return...

  • Java -Create an interface and implement it In the murach.db package, create an interface named IProductDB....

    Java -Create an interface and implement it In the murach.db package, create an interface named IProductDB. This interface should specify this abstract method: public abstract Product get(String productCode); Modify the ProductDB class so it implements the IProductDB interface. Write the code for the new ‘get’ method. Then remove the getProductByCode method. In the Main class, modify the code so it works with the new ProductDB class. This code should create an instance of the IProductDB interface like this: IProductDB db...

  • FOR JAVA: Summary: Create a program that adds students to the class list (see below). The...

    FOR JAVA: Summary: Create a program that adds students to the class list (see below). The solution should be named Roster402_v2.java. Allow the user to control the number of students added to the roster. Ask if the user would like to see their new roster to confirm additions. If yes, then display contents of the file, if no, end the program. ------------------------------------------------------------------------------------- List of student names and IDs for class (this will be your separate text file): Jones, Jim,45 Hicks,...

  • Using Java programming: Modify the delimiter class (provided below) so that it can "incorrectly" ...

    Using Java programming: Modify the delimiter class (provided below) so that it can "incorrectly" evaluate simple parenthesized math expressions . a) ask the user for the whole expression to solve b) Solve the expression only if there is no mismatch in the delimiters. If there is a mismatch, then output an error. If there is an error, allow the user to reenter a corrected/new expression. c) The program should be able to evaluate expressions that uses only the following basic...

  • Look for some finshing touches java help with this program. I just two more things added...

    Look for some finshing touches java help with this program. I just two more things added to this code. A loop at the end that will ask the user if they want to quit if they do want to quit the program stops if they don't it loads a new number sequence. import java.util.Random; import java.util.ArrayList; import java.util.Scanner; import java.util.Arrays; import java.util.List; import java.util.Collections; public class main { public static void main(String[] args) { List < Sequence > list =...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT