answer.
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
Varvara68 [4.7K]
2 years ago
6

Your assignment is to write a menu driven program. The menu will be responded to using a switch statement. The menu options (cas

es) will be as follows (You should give them more succinct labels in your program): Read the user’s first name and echo it back out 20 times. Read the user’s age and double it and display the age and the doubled age. Read the user's age and output one of the following statements: Since you are xx years old, you are a teenager Since you are xx years old, you are NOT a teenager (***of course xx displays the user's age) Read a single integer between 3 and 50 from the user. Create a triangle of X’s with the as many rows as the value of the user's input. The triangle needs to be displayed on the screen and in a text document named triangle.txt.
Engineering
1 answer:
lord [1]2 years ago
3 0

Answer:

Explanation:

import java.util.Scanner;

public class Menu {

  public static void main(String[] args) {

      /*

      * Creating an Scanner class object which is used to get the inputs

      * entered by the user

      */

      Scanner sc = new Scanner(System.in);

      int choice;

do

{

  System.out.println("\n::MENU::");

      System.out.println("1.Echo Name");

      System.out.println("2.Double Your Age");

      System.out.println("3.Check Teenager or not");

      System.out.println("4.Display Triangle");

      System.out.println("5.Exit");

      System.out.print("Enter Choice:");

      choice = sc.nextInt();

      switch (choice) {

      case 1: {

          System.out.print("Enter your name");

          String name=sc.nextLine();

          for(int i=1;i<=20;i++)

          {

              System.out.println(name);

          }

          break;

      }

      case 2: {

          int age;

          System.out.print("Enter age :");

          age=sc.nextInt();

          System.out.println("Your age :"+age);

          System.out.println("Doubled age :"+(2*age));

         

         

         

          break;

      }

      case 3: {

          int age;

          System.out.print("Enter age :");

          age=sc.nextInt();

         

          if(age>=13 && age<=19)

          {

              System.out.println("Since you are "+age+" years old.Your are a Teenager");

          }

          else

          {

              System.out.println("Since you are "+age+" years old.Your are not a Teenager");

          }

          break;

      }

      case 4: {

          int rows;

          do

          {

          System.out.print("Enter a number (between 3 and 50):");

          rows=sc.nextInt();

          if(rows<3 || rows>50)

          {

              System.out.println("** Invalid.Must be between 3 and 50 **");

          }

          }while(rows<3 || rows>50);

          printTriangle(rows);

          break;

      }

      case 5:{

          break;

      }

      default: {

          System.out.println("** Invalid Choice **");

          break;

      }

      }  

}while(choice!=5);

     

  }

  private static void printTriangle(int size) {

      char ch='*';

      for (int a = 0; a < 2 * size - 1; a++) {

          if (a % 2 == 0) {

              for (int b = 0; b < (2 * size - 1) - a; b++) {

                  System.out.print(" ");

              }

              for (int c = 0; c <= a; c++) {

                  System.out.print(ch+" ");

              }

              System.out.println();

          }

      }

     

  }

}

___________________________

Output:

::MENU::

1.Echo Name

2.Double Your Age

3.Check Teenager or not

4.Display Triangle

5.Exit

Enter Choice:1

Enter your name: Mirian

Mirian

Mirian

Mirian

Mirian

Mirian

Mirian

Mirian

Mirian

Mirian

Mirian

Mirian

Mirian

Mirian

Mirian

Mirian

Mirian

Mirian

Mirian

Mirian

Mirian

::MENU::

1.Echo Name

2.Double Your Age

3.Check Teenager or not

4.Display Triangle

5.Exit

Enter Choice:2

Enter age :23

Your age :23

Doubled age :46

::MENU::

1.Echo Name

2.Double Your Age

3.Check Teenager or not

4.Display Triangle

5.Exit

Enter Choice:3

Enter age :16

Since you are 16 years old.Your are a Teenager

::MENU::

1.Echo Name

2.Double Your Age

3.Check Teenager or not

4.Display Triangle

5.Exit

Enter Choice:4

Enter a number (between 3 and 50):6

*

* * *

* * * * *

* * * * * * *

* * * * * * * * *

* * * * * * * * * * *

::MENU::

1.Echo Name

2.Double Your Age

3.Check Teenager or not

4.Display Triangle

5.Exit

Enter Choice:5

You might be interested in
The following passage contains a fragment. Select the correct revision. Presley took the exuberance of gospel and added the freq
Semmy [17]

Answer:

A

Explanation:

Option A was the only option that did not have a sentence fragment. All the other choices were fragments because they interrupted the flow of the sentence. A sentence fragment means that if you started reading where the period is, you would understand everything about the sentence and it would be clear. You cannot have an incomplete sentence that does not have background information. An example would be: And that is how you install it. This leaves information unanswered, such as what the subject of the sentence is, or in other words, what you were installing. Another indicator that this was a sentence fragment was that the sentence began with the word "And." Sentence fragments very commonly start with the word and, because that word shows that it is a continuation of a topic.

7 0
2 years ago
Evan notices a small fire in his workplace. Since the fire is small and the atmosphere is not smoky he decides to fight the fire
Norma-Jean [14]

Answer:

not calling the firemean

Explanation:

7 0
2 years ago
The 10-kg block slides down 2 m on the rough surface with kinetic friction coefficient μk = 0.2. What is the work done by the fr
Rashid [163]

Answer:

153.2 J

Explanation:

Let's first list our given parameters;

mass (m) of the block = 10 kg

which slides down ( i.e displacement) = 2 m

kinetic coefficient of friction (μk) = 0.2

In the diagram shown below;  if we take an integral look at the component of force in the direction of the displacement; we have

F_x= Fcos 40°

F_x= 100 (cos 40°)

F_x= 76.60 N

Workdone by the friction force can now be determined as:

W = F_x × displacement

W = 76.60 × 2

W = 153.2 J

∴  the work done by the friction force = 153.2 J

7 0
2 years ago
Tech A says that as moisture levels increase in brake fluid, the boiling point of the brake fluid decreases. Tech B says that fi
dezoksy [38]

Answer: Both Technician A and B are correct.

Explanation:

Technicians A and B are both right about their diagnosis. The Society of Automotive Engineers performed extensive research on vehicle brake fluids and found that there is typically a 2% moisture content in the brake fluid after a year of operating a vehicle. And as the moisture content of the brake fluid rises, the boiling point of the brake fluid decreases as well.

4 0
2 years ago
Q3: Summation Write a recursive implementation of summation, which takes a positive integer n and a function term. It applies te
harina [27]

Answer:

Here is the recursive function summation:

def summation(n, term):      

   if n == 1:  

       return term(n)

   else:

       return term(n) + summation(n - 1, term)

Explanation:

The function summation() has two arguments where n is a positive integer and term is a function term. term has the lambda function which is a small function having an argument and an expression e.g lambda b: b+20

So the summation() function is a recursive function which returns sum of the first n terms in the sequence defined by term ( a lambda function).

If you want to check if this function works, you can call this function by passing values to it like given in the question.

summation(5, lambda x: 2**x)

Here the value of n is 5 and the term is a lambda function x: 2**x

If you want to see the results of this function on output screen then use:

print(summation(5, lambda x: 2**x))

The print() function will print the results on screen.

This returns the sum of first 5 terms in sequence defined in the function x: 2**x

In recursive methods there are two cases: base case and recursive case. Base case is the stopping case which means that the recursion will stop when the base case/ base condition evaluates to true. The recursive case is when the function keeps calling itself so the recursive function keepsexecuting until the base case becomes true.

Here the base case is if n == 1:  So the recursive function calling itself until the value of n becomes 1.  

Recursive case is:

       return term(n) + summation(n - 1, term)

For the above example with n= 5 and term = x:2**x the recursions starts from n and adds all the terms of the series one by one and the value of n keeps decrementing by 1 at every recursive call.

When the value of n is equal to 1 the base case gets true and the recursion ends and the result of the sum is displayed in output.

This is how the summation() function works for the above function call:

2^1 + 2^2 + 2^3 + 2^4 + 2^5

n is 5 So this term function is called recursively 5 times and at every recursive call its value decreases by 1. Here the term function is used to compute 2 raise to power n. So in first recursive call the 2 raise to the power 5 is computed, then 5 is decremented and then in second recursive call to summation(), 2 raise to the power 4 is calculated, in third recursive call  to summation(), 2 raise to the power 3 is calculated, in fourth recursive call  to summation(), 2 raise to the power 2 is calculated, in fifth recursive call  to summation(), 2 raise to the power 1 is calculated, then the base condition is reached as n==1. So the recursion stops and the sum of the above computed power function results is returned which is 62.

2^1 + 2^2 + 2^3 + 2^4 + 2^5 = 62

The screen shot of recursive function along with the output of explained examples is attached.

6 0
2 years ago
Other questions:
  • A rod is 2m long at temperature of 10oC. Find the expansion of the rod, when the temperature is raised to 80oC. If this expansio
    7·1 answer
  • Water at 400 kPa with a quality of 75% has its pressure raised 200 kPa (to 600 kPa) in a constant volume process. What is the ne
    15·1 answer
  • A woman approaches a room attendant with a letter. She requests that the attendant leave the letter in Room 1201. Which is the m
    9·1 answer
  • A 12-L volume of oil is subjected to a pressure change, which produces a volume strain on the oil of -3.0 × 10-4. The bulk modu
    6·1 answer
  • Air is compressed adiabatically from p1 1 bar, T1 300 K to p2 15 bar, v2 0.1227 m3 /kg. The air is then cooled at constant volum
    13·1 answer
  • Water is to be withdrawn from an 8-m-high water reservoir by drilling a 2.2-cm-diameter hole at the bottom surface. Disregarding
    12·2 answers
  • 15. A cold-chamber die-casting machine operates automatically, supported by two industrial robots.The machine produces two zinc
    9·2 answers
  • Reconsider Couette flow between two parallel plates as derived in class, but with the top plate moving with a known velocity +i
    13·1 answer
  • A rectification column is fed 100 kg mol/h of a mixture of 50 mol % benzene and 50 mol % toluene at 101.32 kPa abs pressure. The
    5·1 answer
  • 2.24 Carbon dioxide (CO2) gas in a piston-cylinder assembly undergoes three processes in series that begin and end at the same s
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!