1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
alukav5142 [94]
3 years ago
12

Let’s define a new language called dog-ish. A word is in the lan- guage dog-ish if the word contains the letters ’d’, ’o’, ’g’ a

re in the word in order. For example, "dpoags" would be in dog-ish because dpoags. Other words like "dog", "doooooog", "pdpopgp", and "qwqwedqweqweoqweqw- gasd" would be in dog-ish. "cat", "apple", "do", "g", would not be in dog-ish.
(a) (20 points) Define the method inDogish recursively such that it re- turns true if the word is in dog-ish and false if it is not. I left a dogishHelper method, which I guarantee you will need to recursively solve dogish. An iterative solution will receive no points.

(b) (20 points) Define the method inXish that does the same logic of dog- ish but for some word X. The method returns true if the word contains all the letters in the word X. The solution must be recursive. An iterative solution will receive no points.

class Main {public static void main(String[] args) {/* leave this main method blank but feel free to uncomment below linesto test your code */// System.out.println(dogish("aplderogad"));// System.out.println(dogishGeneralized("aplderogad", "dog"));} // returns true if the word is in dog-ish// returns false if word is not in dog-ishpublic static boolean inDogish(String word){return false;} // necessary to implement inDogish recursivelypublic static boolean dogishHelper(String word, char letter) {return false;} // a generalized version of the inDogish methodpublic static boolean inXish(String word, String x){return false;}}

Engineering
1 answer:
attashe74 [19]3 years ago
5 0

Answer and Explanation:

// code

class Main {

   public static void main(String[] args) {

       /*

        *

        *

        * your code

        *

        */

       System.out.println(inDogish("aplderogad"));

       System.out.println(inXish("aplderogad", "dog"));

   }

   // returns true if the word is in dog-ish

   // returns false if word is not in dog-ish

   public static boolean inDogish(String word) {

       // first find d

       if (dogishHelper(word, 'd')) {

           // first find string after d

           String temp = word.substring(word.indexOf("d"));

           // find o

           if (dogishHelper(temp, 'o')) {

               // find string after o

               temp = temp.substring(temp.indexOf("o"));

               // find g

               if (dogishHelper(temp, 'g'))

                   return true;

           }

The output is attached below

       }

       return false;

   }

   // necessary to implement inDogish recursively

   public static boolean dogishHelper(String word, char letter) {

       // end of string

       if (word.length() == 0)

           return false;

       // letter found

       if (word.charAt(0) == letter)

           return true;

       // search in next index

       return dogishHelper(word.substring(1), letter);

   }

   // a generalized version of the inDogish method

   public static boolean inXish(String word, String x) {

       if (x.length() == 0)

           return true;

       if (word.length() == 0)

           return false;

       if (word.charAt(0) == x.charAt(0))

           return inXish(word.substring(1), x.substring(1));

       return inXish(word.substring(1), x.substring(0));

   }

}

PS E:\fixer> java Main true true ne on

PS E:\fixer> java Main true true ne on

You might be interested in
Prompt the user to enter five numbers, being five people's weights. Store the numbers in an array of doubles. Output the array's
pochemuha

Answer:

import java.util.Scanner;

  public class PeopleWeights {

    public static void main(String[] args) {

    Scanner reader = new Scanner(System.in);  

    double weightOne = reader.nextDouble();

    System.out.println("Enter 1st weight:");

    double weightTwo = reader.nextDouble();

    System.out.println("Enter 2nd weight :");

    double weightThree = reader.nextDouble();

    System.out.println("Enter 3rd weight :");

    double weightFour = reader.nextDouble();

    System.out.println("Enter 4th weight :");

    double weightFive = reader.nextDouble();

    System.out.println("Enter 5th weight :");

     double sum = weightOne + weightTwo + weightThree + weightFour + weightFive;

     double[] MyArr = new double[5];

     MyArr[0] = weightOne;

     MyArr[1] = weightTwo;

     MyArr[2] = weightThree;

     MyArr[3] = weightFour;

     MyArr[4] = weightFive;

     System.out.printf("You entered: " + "%.1f %.1f %.1f %.1f %.1f ", weightOne, weightTwo, weightThree, weightFour, weightFive);

     double average = sum / 5;

     System.out.println();

     System.out.println();

     System.out.println("Total weight: " + sum);

     System.out.println("Average weight: " + average);

     double max = MyArr[0];

     for (int counter = 1; counter < MyArr.length; counter++){

        if (MyArr[counter] > max){

           max = MyArr[counter];

        }

     }

     System.out.println("Max weight: " + max);

  }

import java.util.Scanner;

  public class PeopleWeights {

    public static void main(String[] args) {

    Scanner reader = new Scanner(System.in);  

    double weightOne = reader.nextDouble();

    System.out.println("Enter 1st weight:");

    double weightTwo = reader.nextDouble();

    System.out.println("Enter 2nd weight :");

    double weightThree = reader.nextDouble();

    System.out.println("Enter 3rd weight :");

    double weightFour = reader.nextDouble();

    System.out.println("Enter 4th weight :");

    double weightFive = reader.nextDouble();

    System.out.println("Enter 5th weight :");

     double sum = weightOne + weightTwo + weightThree + weightFour + weightFive;

     double[] MyArr = new double[5];

     MyArr[0] = weightOne;

     MyArr[1] = weightTwo;

     MyArr[2] = weightThree;

     MyArr[3] = weightFour;

     MyArr[4] = weightFive;

     System.out.printf("You entered: " + "%.1f %.1f %.1f %.1f %.1f ", weightOne, weightTwo, weightThree, weightFour, weightFive);

     double average = sum / 5;

     System.out.println();

     System.out.println();

     System.out.println("Total weight: " + sum);

     System.out.println("Average weight: " + average);

     double max = MyArr[0];

     for (int counter = 1; counter < MyArr.length; counter++){

        if (MyArr[counter] > max){

           max = MyArr[counter];

        }

     }

     System.out.println("Max weight: " + max);

  }

8 0
3 years ago
Read 2 more answers
When a tensile specimen is stretched in the plastic region to an engineering strain of 0.2, calculate the amount of cold work pe
Valentin [98]

Answer:

0.2 x 100

Explanation:

Engineering strain is the original crossection/original crossection

cold work percentage is

original crossection/original crossection x 100

4 0
2 years ago
18. What is being shown in the above Figure?
slavikrds [6]

D. Camshaft gear backlash is being checked​

hope this helps :)

8 0
3 years ago
Read 2 more answers
A 2-lane highway is to be constructed across a 6-ft diameter metal culvert which is oriented perpendicular to the highway center
kvv77 [185]

Answer:

Dude just like forget the highway and drive on the interstate bruh

Explanation:

5 0
4 years ago
A First Stage in a turbine receives steam at 10 MPa, 800 C with an exit pressure of 800 KPa. Assume the stage is adiabatic and r
9966 [12]

Answer

given,

P₁  = 10 MPa                 T₁ = 800

P₂ = 800 KPa               T₂ = ?

Using formula

\dfrac{T_2}{T_1} = (\dfrac{P_2}{P_1})^{\dfrac{n-1}{n}}

For steam   n = 1.33                    

\dfrac{T_2}{800+273} = (\dfrac{800\times 10^{3}}{10\times 10^{6}})^{\dfrac{1.33-1}{1.33}}

T₂ = 573.368 K                    

T₂ = 573.368 - 273 = 300.368 °C

W = \dfrac{P_1V_1-P_2V_2}{n-1}

          =\dfrac{mR(T_1-T_2)}{n-1}

          =\dfrac{1\times 0.287\times (800 - 300.368)}{1.33-1}

      W = 434.53 kJ/kg

7 0
3 years ago
Other questions:
  • Sheet metal cutting operation along a straight line between two cutting edges is called Shearing Operation's. a)- True b)-False
    15·1 answer
  • Technician A says a "dry park check" is a good way to check ball joints and control arm bushings for looseness. Technician B say
    15·2 answers
  • What can you do to prepare for a long distance trip
    5·2 answers
  • The products of combustion from burner are routed to an industrial application through a thin-walled metallic duct of diameter D
    6·1 answer
  • : During a heavy rainstorm, water from a parking lot completely fills an 18-in.- diameter, smooth, concrete storm sewer. If the
    6·1 answer
  • When designing solid rockets, thrust and mass flow must be considered time dependent. a) True b) False
    9·1 answer
  • Assuming Stokes behavior, calculate the terminal settling velocity in standard air () for the following particles: (a) diameter
    5·1 answer
  • . In the U.S. fuel efficiency of cars is specified in miles per gallon (mpg). In Europe it is often expressed in liters per 100
    8·1 answer
  • 5√1024/4√1296+3√56/3√2401-4√16/3
    6·1 answer
  • 4. A banking system provides users with several services:
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!