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
A genetically engineered hormone.
I am Lyosha [343]
What is the question?
3 0
3 years ago
When a retaining structure moves towards the soil backfill, the stress condition is called:__________.
Alecsey [184]

Answer:

(C) passive state.

Explanation:

The earth pressure is the pressure exerted by the soil on the shoring system. They are three types of earth pressure which are:

a) Rest state: In this state, the retaining wall is stationary, this makes the lateral stress to be zero.

b) Active state: In this state, the wall moves away from the back fill, this leads to an internal resistance. Hence the active earth pressure is less than earth pressure at rest

c) Passive state: In this state the wall is pushed towards the back fill, this leads to shearing resistance. Hence, the passive earth pressure is greater than earth pressure at rest

6 0
3 years ago
Explain why the scenario below describes a team of mechanical engineers.
babymother [125]

Explanation:

because mechanical engineers fix air conditioners cars and other stuffs

5 0
3 years ago
Read 2 more answers
Which of the following statements is true of a mature technology?
hoa [83]

Answer:

I think it is( More expensive than immature technologies) I took engineering class and this question is still quite tricky.

Explanation:

8 0
3 years ago
Privacy settings allow account owners to decide who can
VLD [36.1K]
Access their accounts.

anyone can search for them online.
they only meet in person with who they choose.
no one can view their personal information (other than companies they give it to.)
6 0
3 years ago
Other questions:
  • Whenever you are around construction sites, you should A speed up so you get through it quicker and avoid falling rocks B maneuv
    10·1 answer
  • List four reasons why we need aceuracy in machined parts.
    8·1 answer
  • Often an attacker crafts e-mail attacks containing malware designed to take advantage of the curiosity or even greed of the reci
    14·1 answer
  • Three possible career opportunities in embedded systems engineering
    11·1 answer
  • A compressed-air drill requires an air supply of 0.25 kg/s at gauge pressure of 650 kPa at the drill. The hose from the air comp
    6·1 answer
  • In the High Low Logic Index low levels are bearish and high levels are bullish, generally True False
    13·1 answer
  • O local utilizado pelos grandes avioes para descolar e aterrar
    14·1 answer
  • 1. In order to minimize hazards, what should you do before starting a job
    10·2 answers
  • What should be your strongest tool be for gulding your ethical decisions making process
    5·1 answer
  • Write down the three formula to find the three types of slope of curve Q with respect to L.
    5·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!