Question
Please dont use hashmap or Apache commons, its a basic computer science II course. You have FillInTheBlank.java: package question1; public class FillInTheBlank { /** *
Please dont use hashmap or Apache commons, its a basic computer science II course.
You have FillInTheBlank.java:
package question1;
public class FillInTheBlank { /** * Data fields question and answer */ private String question, answer; /** * Copy constructor to access the data fields. */ public FillInTheBlank(String question, String answer) { this.question = question; this.answer = answer; } /** * Constructor */ public FillInTheBlank(FillInTheBlank in) { this.question = in.question; this.answer = in.answer; } /** * The getQuestion method, which accesses, the question. * @return, the question itself. */ public String getQuestion() { return this.question; } /** * The setQuestion method, which sets the questions. * @param question, sets the question */ public void setQuestion(String question) { this.question = question; }
/** * The getAnswer method, which accesses the answer. * @return the answer */ public String getAnswer() { return this.answer; }
/** * The setAnswer mehod, which sets the answer. * @param answer, the answer to set */ public void setAnswer(String answer) { this.answer = answer; } /** * @return string representation of question */ @Override public String toString() { return this.question; } }
Then you have Quiz.java:
package question1;
public class Quiz { private int numQuestions; private String title; private FillInTheBlank quiz[];
/** * Constructors */ public Quiz() { this.numQuestions = 5; this.title = "My Own Quiz"; this.quiz = new FillInTheBlank[numQuestions]; } /** * Constructors */ public Quiz(int numQuestions, String title) { this.numQuestions = numQuestions; this.title = title; this.quiz = new FillInTheBlank[numQuestions]; } /** * Constructors */ public Quiz(Quiz in) { this.numQuestions = in.numQuestions; this.title = in.title; this.quiz = new FillInTheBlank[numQuestions];
// deep copy for(int i=0; i /** * @return the title */ public String getTitle() { return this.title; } /** * @param title the title to set */ public void setTitle(String title) { this.title = title; } /** * sets the question at some index (deep clone) */ public FillInTheBlank setQuestion(int index, FillInTheBlank inQuestion) { if(index < 0 || index >= numQuestions) { return null; } else { this.quiz[index] = new FillInTheBlank(inQuestion); return this.quiz[index]; } } /** * returns the question at some index */ public FillInTheBlank getQuestion(int index) { if(index < 0 || index >= numQuestions) { return null; } else { return this.quiz[index]; } } /** * prints the questions */ public void printText() { System.out.println("Quiz Title: " + title); System.out.println("The questions you have set for the quiz are: "); for(int i=0; i /** * string representation of quiz */ public String toString() { return "Quiz: " + title + " " + "Can hold " + numQuestions + " Qusetions."; } } And finally you have the QuizTester.java: package question1; import java.util.*; public class QuizTester { public static void main(String[] args) { Scanner in = new Scanner(System.in); System.out.print("Enter the title of the quiz: "); String title = in.nextLine(); System.out.print("How many questions are there in the quiz? "); int n = Integer.parseInt(in.nextLine()); // create quiz Quiz quiz = new Quiz(n, title); // ask user for the questions and answers and fill the quiz System.out.println(); for(int i=0; i // print quiz.printText(); System.out.println(); System.out.println("The answer to the questions are: "); quiz.printAnswers(); in.close(); } } The question I would like for you to complete is the following: Create a second quiz using your quiz copy constructor. For your second (copied) test, swap the first and last questions and for the middle question change the question AND the answer (do this by access the questions set methods, not by replacing the question). Finally, print the two tests and two answer sets to show that they are distinct and that the changes to one do not affect the other (i.e., your deep copy is working). Thanks in advacne!
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started