Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

java Write the method public boolean sameWords(String[] otherWords) from the Quiz6 class in the previous question. This method should return true if the words array

java

Write the method public boolean sameWords(String[] otherWords) from the Quiz6 class in the previous question.

This method should return true if the words array contains the same text strings in the same order as the array otherWords. It should return false if they do not contain the same text strings in the same order.

In addition, this method must handle the following cases:

  • One array is smaller or larger than the other (in which case it should return false).
  • One or both arrays are null. In this case it should return true if both arrays are null, and false if only one is null.
    public class Quiz6 { public int score; private String[] words; // Returns true if otherWords contains the same text strings in the // same order as words. String matching is done with .equals. public boolean sameWords(String[] otherWords) { // You will implement this in the next problem. // For this problem assume this method is correctly implemented. // It does NOT create a new array. } public void setWords() { String[] newWords = {"Add", "Subtract", "Multiply"}; this.words = newWords; newWords[1] = "Divide"; } public static void main(String[] args) { Quiz6 solver = new Quiz6(); solver.score = 0; solver.setWords(); String[] testWords = {"Add", "Subtract", "Multiply"}; if (solver.sameWords(testWords)) { System.out.println("Same"); } else { System.out.println("Different"); } } } Thanks

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Modeling And Design

Authors: Toby J. Teorey, Sam S. Lightstone, Tom Nadeau, H.V. Jagadish

5th Edition

0123820200, 978-0123820204

More Books

Students also viewed these Databases questions