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
GrogVix [38]
4 years ago
10

Write a simple calculator program. Your program should ask for three things two whole numbers and an operator in the form of an

expression like: 3 * 2 Use a select case structure to determine what operation needs to be performed on the two numbers. Your program should handle the arithmetic functions Add, Subtract, Multiply, and Divide (Depending on the operator entered).
Engineering
1 answer:
vekshin14 years ago
3 0

Answer:

The solution code is written in Java.

  1.        Scanner input = new Scanner(System.in);
  2.        System.out.print("Enter operator: ");
  3.        String operator = input.nextLine();
  4.        System.out.print("Enter first integer: ");
  5.        int num1 = input.nextInt();
  6.        System.out.print("Enter second integer: ");
  7.        int num2 = input.nextInt();
  8.        int result = 0;
  9.        switch(operator){
  10.            case "+":
  11.               result = num1 + num2;
  12.               break;
  13.            case "-":
  14.                result = num1 - num2;
  15.                break;
  16.            case "*":
  17.                result = num1 * num2;
  18.                break;
  19.            case "/":
  20.                result = num1 / num2;
  21.                break;
  22.            default:
  23.                System.out.println("Invalid operator");
  24.        }
  25.        System.out.println(result);

Explanation:

To ask for the user input for two whole numbers and an operator, we can use Java Scanner class object. Since the input operator is a string, we can use nextLine() method to get the operator string (Line 3). We use nextInt() method to get whole number input (Line 5 & 7).

Next we use the switch keyword and pass the operator into the switch structure to determine which case statement should be executed. For example,  if the input operator is "*" the statement  "<em>result = num1 * num2;</em> " will run and multiply <em>num1</em> with <em>num2. </em>

You might be interested in
The pressure distribution over a section of a two-dimensional wing at 4 degrees of incidence may be approximated as follows: Upp
Aliun [14]

Answer:

The lift coefficient is 0.3192 while that of the moment about the leading edge is-0.1306.

Explanation:

The Upper Surface Cp is given as

Cp_u=-0.8 *0.6 +0.1 \int\limits^1_{0.6} \, dx =-0.8*0.6+0.4*0.1

The Lower Surface Cp is given as

Cp_l=-0.4 *0.6 +0.1 \int\limits^1_{0.6} \, dx =-0.4*0.6+0.4*0.1

The difference of the Cp over the airfoil is given as

\Delta Cp=Cp_l-Cp_u\\\Delta Cp=-0.4*0.6+0.4*0.1-(-0.8*0.6-0.4*0.1)\\\Delta Cp=-0.4*0.6+0.4*0.1+0.8*0.6+0.4*0.1\\\Delta Cp=0.4*0.6+0.4*0.2\\\Delta Cp=0.32

Now the Lift Coefficient is given as

C_L=\Delta C_p cos(\alpha_i)\\C_L=0.32\times cos(4*\frac{\pi}{180})\\C_L=0.3192

Now the coefficient of moment about the leading edge is given as

C_M=-0.3*0.4*0.6-(0.6+\dfrac{0.4}{3})*0.2*0.4\\C_M=-0.1306

So the lift coefficient is 0.3192 while that of the moment about the leading edge is-0.1306.

5 0
3 years ago
If an object is near the surface of the earth the variation of its weight with distance from the center of the earth can ofteb b
zalisa [80]

Answer:

h=32.1 km

Explanation:

<em>solution:</em>

using newton law of gravitational attraction and newton second law:

W=\frac{Gmm_{E} }{r^{2} } \\a=\frac{Gm_{E}}{r^{2}} \\W=ma\\

m_{E}= mass of earth

r= distance between two masses

at sea level

a=g

r=R_{E}

a=\frac{Gm_{E}}{r^{2}}.............................(1)

Gm_{E} =gR_{E}^2.........................(2)

by substituting (2) and (1) a=g\frac{R_{E}^2 }{r^{2} } acceleration due to gravity at a distance r from the centre of the earth in terms of g (sea level)

so the weight of the object at a distance r from the centre of the earth (W=ma)

W=mg(Re^2/r^2)..........(3)

h the height above the surface of the earth: r=Re+h

putting the value of r in eq (3)

W=mg(Re/Re+h)^2

W=0.99 mg

solving for height h:

h=Re(1/√0.99)-(1))

h=32.1 km

4 0
3 years ago
Mechanical clips are used to close bags and keep things together. Investigate the design of various paper clips, hair clips, and
pochemuha

Answer:

Hair clip: this used to hold human hairs together especially long hairs

The Design parameters to be considered are : number of teeth, durability of the material to be used and also the width ( how wide the clip can open )

Advantages : very easy to use, holds hairs tight

Disadvantages : Expensive and material used is sometimes brittle

paper clips : This used to hold papers together it is made of a thin elastic wire

The design parameters to be considered are : length of the wire, material to be used and the elasticity of the material

advantages : it is quite cheap and good strength

disadvantages :it can hold a limited amount of papers together

potato chip bag clips: These clips are used on potato chip bags to ensure that the bags are air tight

The design parameters to be considered are : Elasticity of the material to be used , and size

Advantages : it helps to prevent the potato chips from getting exposed to air

disadvantages : Not very popular and its quite expensive

Explanation:

Hair clip: this used to hold human hairs together especially long hairs

The Design parameters to be considered are : number of teeth, durability of the material to be used and also the width ( how wide the clip can open )

Advantages : very easy to use, holds hairs tight

Disadvantages : Expensive and material used is sometimes brittle

paper clips : This used to hold papers together it is made of a thin elastic wire

The design parameters to be considered are : length of the wire, material to be used and the elasticity of the material

advantages : it is quite cheap and good strength

disadvantages :it can hold a limited amount of papers together

potato chip bag clips: These clips are used on potato chip bags to ensure that the bags are air tight

The design parameters to be considered are : Elasticity of the material to be used , and size

Advantages : it helps to prevent the potato chips from getting exposed to air

disadvantages : Not very popular and its quite expensive

4 0
3 years ago
Who is responsible for providing working conditions which are free from fall dangers?
olchik [2.2K]

Answer:

I am pretty confident it is the Employer!

Explanation:

They have the responsibility to provide a safe workplace that is free from serious hazards, according to the General Duty Clause of the OSH Act (OSHA Standards)

I hope this helped you!! :D

4 0
3 years ago
Read 2 more answers
What is the greatest speedup (in terms of throughput) possible with pipelining? You do not need to worry about the register timi
RUDIKE [14]

Answer:

The greatest speedup possible with pipelining is 2.5 times

Explanation:

As we know

Span of stage = Maximum span of any span

As stage B has the maximum duration of time, So

Duration of time of each stage = Time duration of Stage B = 8 ns

Now calculate the total time without pipeline = Duration of Stage A + Duration of Stage B + Duration of Stage C + Duration of Stage D = 5 ns + 8 ns + 4 ns + 3 ns = 20 ns

So the greatest speedup can be calculated as follow

Greatest speedup = Total time without pipeline / Duration of time of each stage = 20 ns / 8 ns = 2.5 times

3 0
3 years ago
Other questions:
  • Design a circuit with output f and inputs x1, x0, y1, and y0. Let X = x1x0 and Y = y1y0 represent two 2-digit binary numbers. Th
    10·1 answer
  • A _____ satellite system employs many satellites that are spaced so that, from any point on the Earth at any time, at least one
    10·1 answer
  • Which of the following is not an example of heat generation? a)- Exothermic chemical reaction in a solid b)- Endothermic Chemica
    15·1 answer
  • Joe has a set up in which the length of the load arm is 20cm and the length of the effort arm is 80cm. What is the mechanical ad
    12·2 answers
  • One of the most important parts about creating great photographs starts with choosing what to photograph
    6·1 answer
  • A 90-hp (shaft output) electric car is powered by an electric motor mounted in the engine compartment. If the motor has an avera
    8·1 answer
  • Definition of ceramics
    13·2 answers
  • Linear dimensioning commands are used to dimension _____.
    11·1 answer
  • Two long pipes convey water between two reservoirs whose water surfaces are at different elevations. One pipe has a diameter twi
    13·1 answer
  • How is the purple stem trait variation similar to the tougue-rolling trait variation
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!