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
Varvara68 [4.7K]
3 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]3 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
Suppose the following two events occur at the same time: the Chicago Cubs win the World Series, and the workers who make Cubs me
Annette [7]

Answer:

the answer would be decrease decrease

3 0
4 years ago
A non-licensed person may be the SOLE owner of a civil, electrical, or mechanical engineering business under which of the follow
kotegsom [21]

Answer:

(d) None. No provisions exist.

Explanation:

B&P Code § 6738 prohibits a non-licensed person from being the sole proprietor of an engineering business. The non-licensed can be a partner in an engineering business that offers civil, electrical, or mechanical services. It is mandatory that at least one licensed engineer must be a co-owner of the business.

5 0
3 years ago
The process of generation of force by the high speed that pushes the jet engine forward is based on Newton’s _____ law of motion
jasenka [17]

Answer:

The process of generation of force by the high speed that pushes the jet engine forward is based on Newton’s 2 law of motion ?

Explanation:

1, Newton’s first law states that, if a body is at rest or moving at a constant speed in a straight line, it will remain at rest or keep moving in a straight line at constant speed unless it is acted upon by a force. This postulate is known as the law of inertia.

2,  

Newton’s second law is a quantitative description of the changes that a force can produce on the motion of a body. It states that the time rate of change of the momentum of a body is equal in both magnitude and direction to the force imposed on it. The momentum of a body is equal to the product of its mass and its velocity. Momentum, like velocity, is a vector quantity, having both magnitude and direction. A force applied to a body can change the magnitude of the momentum, or its direction, or both.For a body whose mass m is constant, it can be written in the form F = ma, where F (force) and a (acceleration)

3, Newton’s third law states that when two bodies interact, they apply forces to one another that are equal in magnitude and opposite in direction.The third law is also known as the law of action and reaction. This law is important in analyzing problems of static equilibrium, where all forces are balanced, but it also applies to bodies in uniform or accelerated motion. The forces it describes are real ones, not mere bookkeeping devices. For example, a book resting on a table applies a downward force equal to its weight on the table. According to the third law, the table applies an equal and opposite force to the book.

5 0
3 years ago
Read 2 more answers
Refrigerant 134a is the working fluid in a vaporcompression heat pump that provides 35 kW to heat a dwelling on a day when the o
Dennis_Churaev [7]

Answer:

Hello, dear.

For the answer please see the explanation below.

Explanation:

The compressor power is:

2.212kW

(b) The refrigeration capacity is:

3.62 tons

(c) The coefficient of performance is:

5.75

5 0
4 years ago
How many steps is a player allowed to take after catching a ball while running
KATRIN_1 [288]

Answer:

A moving player may only take 2 legal steps after catching the ball to shoot, pass or to come to a stop.

so (B. 2)

Explanation:

On this play, the offensive player catches the ball in the air and lands with a left, right, left prior to shooting. This is a traveling violation for taking 3 steps.

7 0
3 years ago
Other questions:
  • Consider the following class definitions: class smart class superSmart: public smart { { public: public: void print() const; voi
    6·1 answer
  • what is the method of the slope stabilization, and how many type of method of the stabilization, please help explain the types o
    13·1 answer
  • Vending machine controller (adapted from Katz, "Contemporary Logic Design") Design and implement a finite state machine that con
    10·1 answer
  • A company that produces footballs uses a proprietary mixture of ideal gases to inflate their footballs. If the temperature of 23
    11·1 answer
  • Which Car is more aerodynamic
    12·2 answers
  • The primary energy source for the controller in a typical control system is either brainlythe primary energy source for the cont
    10·1 answer
  • Air modeled as an ideal gas enters a combustion chamber at 20 lbf/in.2
    10·1 answer
  • New ventures that are based on strategic value, such as valuable technology, are attractive while those with low or no strategic
    12·2 answers
  • Drag the tiles to the boxes to form correct pairs. Identify the designations of the three employees in an automobile company fro
    6·1 answer
  • For installations where the nonlinear load is huge, most consulting engineers will specify ____-rated transformers.
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!