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
garik1379 [7]
3 years ago
5

The Speed of Sound (Java Project. Please make it easy to understand. I'm a beginner at this. I believe we are supposed to use a

switch or if/else) The speed of sound depends on the material the sound is passing through. Below is the approximate speed of sound (in feet per second) for air, water and steel: air: 1,100 feet per second water: 4,900 feet per second steel: 16,400 feet per second Write a program class TheSpeedOfSound that asks the user to enter �air�, �water�, or �steel�, and the distance that a sound wave will travel in the medium. The program should then display the amount of time it will take. You can calculate the amount of time it takes sound to travel in air with the following formula: time = distance/1,100 You can calculate the amount of time it takes sound to travel in watert with the following formula: time = distance/4,900 You can calculate the amount of time it takes sound to travel in steel with the following formula: time = distance/16,400the user should enter an "A" for "air", a "W" for "water, and an "S" for steel and the distance.use the switch statement as part of your solution.display your answer using the printf statement.
Computers and Technology
1 answer:
Ilya [14]3 years ago
6 0

Answer:

The program of this question can be given as:

Program:

//import pacakge for user input.

import java.util.Scanner;

//define class  

public class SpeedofSound              

{

  public static void main(String a[]) //define main function

  {  

      //define variable.

      String medium;                            

      double distance,time=0;

      //creating Scanner class object for input from user.

      Scanner s=new Scanner(System.in);  

      //print message.

      System.out.printf("Enter medium(air,water or steel) : ");

      medium=s.nextLine();  //taking input.

      //print message.

      System.out.printf("Enter the distance that the sound will travel : ");

      distance=s.nextDouble(); //taking input.

      switch(medium) //checking condtion between range.

      {

          case "air":

                  time=distance/1100;         //apply formula

                  break;

          case "water":

                  time=distance/4900;            //apply formula

                  break;

          case "steel":

                  time=distance/16400;            //apply formula

                  break;

          default:

                  System.out.printf("Sorry, you must enter air,water or steel"); //error for invalid input of medium

                  System.exit(0);

      }

      System.out.printf("It take "+time+" seconds"); //print final answer.

  }

}

Output:

Enter medium(air,water or steel) : air

Enter the distance that the sound will travel : 200

It take 0.18181818181818182 seconds

Explanation:

In this program first, we import packages for user input. Then we declare the class in the class we declare all the variables and then we create the scanner class object. It is used for taking input from the user. Then we use the switch statement It is used for condition. It works between the ranges. In the switch statement, we apply all the formula that is given in the question. and at the last, we print the output using printf function in java.

You might be interested in
This refers to the people involved in the data processing operation.
yawa3891 [41]
The people involved in the data processing operation are known as <span>Peopleware.</span>
6 0
3 years ago
The method needed to arrange for an object to be notified when a window's close-window button has been clicked is
Readme [11.4K]
The correct answer that would best complete the given statement above would be the term addWindowListener. <span>The method needed to arrange for an object to be notified when a window's close-window button has been clicked is addWindowListener. Hope this is the answer that you are looking for. </span>
7 0
3 years ago
14 Copy a picture of a crane on the next page. Do not trace them. Make a freehand sketch. (2) 2 Look at the placed where the Mar
PtichkaEL [24]

Answer:

Hope it helps.have a look.

3 0
2 years ago
19) If you want to find your lowest paid, full time employee (with "FT" in column B and each employee's salary found in column C
Vadim26 [7]

Answer:

MAXIF

Explanation:

The MAXIF function is a function used in Ms Excel.

  • This function indicates the maximum value located on an array .

Option B

7 0
2 years ago
Read 2 more answers
g Assignment 8: Driving costs Driving is expensive. Write a program with a car's miles/gallon and gas dollars/gallon as input, a
zavuch27 [327]

Answer:

miles_gallon = float(input("Enter car's miles/gallon: "))

dollars_gallon = float(input("Enter gas dollars/gallon: "))

print("Gas cost for 20 miles is $", (20 / miles_gallon) * dollars_gallon)

print("Gas cost for 75 miles is $", (75 / miles_gallon) * dollars_gallon)

print("Gas cost for 500 miles is $", (500 / miles_gallon) * dollars_gallon)

Explanation:

*The code is in Python.

Ask the user to enter the car's miles/gallon and gas dollars/gallon

Calculate the gas cost for 20 miles, divide 20 by miles_gallon and multiply the result by dollars_gallon, then print it

Calculate the gas cost for 75 miles, divide 75 by miles_gallon and multiply the result by dollars_gallon, then print it

Calculate the gas cost for 500 miles, divide 500 by miles_gallon and multiply the result by dollars_gallon, then print it

5 0
2 years ago
Other questions:
  • What does the picture indicate on the famous book “Dawn of the century”?​
    10·1 answer
  • Why are listening and speaking part of the Common Core and ELD Standards? Why is this particularly important for our ELD student
    14·1 answer
  • Write an if-else statement to describe an object. Print "Balloon" if isBalloon is true and isRed is false. Print "Red balloon" i
    9·1 answer
  • It is important to verify internet source because-------- choose that apply. A.the source should be written by real author. B.an
    6·2 answers
  • Please Help!! How to code this in Python?
    11·1 answer
  • A _________ is a task at the lowest level of the WBS that represents the level of work that the project manager uses to monitor
    5·1 answer
  • Janet received an email from a bank asking for the password for her Internet banking account. She emailed back her password. A f
    12·2 answers
  • Which line of code will eliminate the element “calculator” from an array of supplies?
    13·1 answer
  • Any action that causes harm to your computer is called a
    15·1 answer
  • Which of the following is the best description of an ip address?
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!