In Java, write classes the following different types of questions:
YesNo: this can be answered in one of two ways: yes or no. answer(String) would accept only "Yes" or "No" as valid answers.
Essay: this can be answered in at most 140 characters, including spaces.
Likert: this can be answered on a fixed, 5-point Likert scale (Strongly Agree, Agree, Neither Agree nor Disagree, Disagree, Strongly Disagree). answer(String) would accept only these precise words as valid answers.
Design the data in a way that captures their similarities Create these interfaces/classes, and write appropriate constructors that allows one to create a question using it.
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;
}
@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;
}
@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;
}
@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());
}
}
In Java, write classes the following different types of questions: YesNo: this can be answered in...
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;...
JAVA: Write a program that inputs a string that represents a binary number. The string can contain only 0s and 1s and no other characters, not even spaces. Validate that the entered number meets these requirements. If it does not, display an error message. If it is a valid binary number, determine the number of 1s that it contains. If it has exactly two 1s, display "Accepted". Otherwise, display "Rejected". All input and output should be from the console.
Programming Assignment Objective Write a Java program that utilizes multiple classes. Write a Java program that utilizes inheritance in a practical manner. Problem: Quiz Bowl Your high school quiz bowl team has been losing its edge and needs to find a method to improve. Knowing that you are a savvy programmer, your coach asks you to write a program that the team members can use to hone their skills. Quiz Bowl questions come in three varieties: True/False Multiple Choice (variable...
Using loops with the String and Character classes. You can also use the StringBuilder class to concatenate all the error messages. Floating point literals can be expressed as digits with one decimal point or using scientific notation. 1 The only valid characters are digits (0 through 9) At most one decimal point. At most one occurrence of the letter 'E' At most two positive or negative signs. examples of valid expressions: 3.14159 -2.54 2.453E3 I 66.3E-5 Write a class definition...
write java program and for the following (you can add more classes as you see necessary) as follows: a class called Coursewith courseCode, courseName,and creditHours; a superclass called FacultyMemberwith FacultyID, firstName, lastName, academicRank, and academicSpecialization; a course Convener subclass inherits from the FacultyMember class with specific member variables representing the coursesand members (Lecturers andTAs) whom he/she is responsible of; Lecturers andTAsare also subclasses that inherit from FacultyMemberclass with some specific member variables (i.e., maximumNumberOfCourses, quotaOfCreditHoursthey can take, and assignedCourses). Create...
JAVA :The following are descriptions of classes that you will create. Think of these as service providers. They provide a service to who ever want to use them. You will also write a TestClass with a main() method that fully exercises the classes that you create. To exercise a class, make some instances of the class, and call the methods of the class using these objects. Paste in the output from the test program that demonstrates your classes’ functionality. Testing...
The following is for java programming. the classes
money date and array list are so I are are pre made to help with
the coding so you can resuse them where applicable
Question 3. (10 marks) Here are three incomplete Java classes that model students, staff, and faculty members at a university class Student [ private String lastName; private String firstName; private Address address; private String degreeProgram; private IDNumber studentNumber; // Constructors and methods omitted. class Staff private String lastName;...
For this lab assignment, you will be writing a few classes that can be used by an educator to grade multiple choice exams. It will give you experience using some Standard Java Classes (Strings, Lists, Maps), which you will need for future projects. The following are the required classes: Student – a Student object has three private instance variables: lastName, a String; firstName, a String; and average, a double. It has accessor methods for lastName and firstName, and an accessor...
LAB 7-Movie List Program Goali Your assignment is to write a C++program to implement the ADT List by creating a list of movies. This assignment will help you practice: multiple file programming, classes, pablic and private methods, dynamie memory, constructors and destructors, arrays and files Implementation the required classes This lab assignment gives you the opportunity to practice creating classes and using dynamic memory in one of There are two classes to implement: Movie and MovieList. As you can see...
Write a Java Program that performs the following functionalities: and you can use if statements, cases, and string methods Enter a new main sentence Find a String Find all incidents of a String Find and Replace a String Replace all the incidents of a String Count the number of words Count a letter’s occurrences Count the total number of letters Delete all the occurrences of a word Exit The program will display a menu with each option above, and then...