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 steam turbine in a power plant receives 5 kg/s steam at 3000 kPa, 500°C. Twenty percent of the flow is extracted at 1000 kPa t
MrMuchimi

Answer:

The temperature of the first exit (feed to water heater) is at 330.15ºC. The second exit (exit of the turbine) is at 141ºC. The turbine Power output (if efficiency is %100) is 3165.46 KW

Explanation:

If we are talking of a steam turbine, the work done by the steam is done in an adiabatic process. To determine the temperature of the 2 exits, we have to find at which temperature of the steam with 1000KPa and 200KPa we have the same entropy of the steam entrance.

In this case for steam at 3000 kPa, 500°C, s= 7.2345Kj/kg K. i=3456.18 KJ/Kg

For steam at 1000 kPa and s= 7.2345Kj/kg K → T= 330.15ºC i=3116.48KJ/Kg

For steam at 200 kPa and s= 7.2345Kj/kg K → T= 141ºC i=2749.74KJ/Kg

For the power output, we have to multiply the steam flow with the enthalpic jump.

The addition of the 2 jumps is the total power output.

4 0
3 years ago
A 10-mm-diameter Brinell hardness indenter produced an indentation 1.55 mm in diameter in a steel alloy when a load of 500 kg wa
BigorU [14]

Answer:

HB = 3.22

Explanation:

The formula to calculate the Brinell Hardness is given as follows:

HB = \frac{2P}{\pi D\sqrt{D^{2}- d^{2} } }

where,

HB = Brinell Hardness = ?

P = Applied Load in kg = 500 kg

D = Diameter of Indenter in mm = 10 mm

d = Diameter of the indentation in mm = 1.55 mm

Therefore, using these values, we get:

HB = \frac{(2)(500)}{\pi (10)\sqrt{10^{2}- 1.55^{2} } }

<u>HB = 3.22 </u>

4 0
3 years ago
What is a table saw for
svet-max [94.6K]

Answer:

a table

Explanation:

because you can saw the table

5 0
2 years ago
Read 2 more answers
What is the last step to the design process?
ryzh [129]

Answer:

B: Present solution

4 0
3 years ago
What is the unit of electric current?
Bess [88]

Answer: amps, or amperes

Explanation: Electric current is measured in amperes, usually shortened to amps.

6 0
2 years ago
Other questions:
  • Vending machine controller (adapted from Katz, "Contemporary Logic Design") Design and implement a finite state machine that con
    10·1 answer
  • A tool chest has 950 N weight that acts through the midpoint of the chest. The chest is supported by feet at A and rollers at B.
    15·1 answer
  • A rigid bar pendulum is attached to a cart, which moves along the horizontal plane. The rigid bar has a center of mass at L/2. T
    5·1 answer
  • What is 7-?=4 i need help
    9·2 answers
  • Which of these physical concepts is most important in civil engineering?
    14·1 answer
  • Three communications channels in parallel have independent failure modes of 0.1 failure per hour. These components must share a
    5·1 answer
  • A hemispherical shell with an external diameter of 500 mm and a thickness of 20 mm is going to be made by casting, located entir
    12·1 answer
  • Agricultural economics is a study of how agriculture and business are related.<br> False<br> True
    15·1 answer
  • Q1. (20 marks) Entropy Analysis of the heat engine: consider a 35% efficient heat engine operating between a large, high- temper
    10·1 answer
  • Can you help me with this
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!