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
Which of the following class definition defines a legal abstract class Group of answer choices public class Rectangle abstract {
valkas [14]
<h2>Question</h2>

Which of the following class definition defines a legal abstract class Group of answer choices

(a)

public class Rectangle abstract {

   public abstract double findArea ( );

   

}

(b)

public abstract class Rectangle {

   public abstract double findArea ( );

   

}

(c)

public class Rectangle {

   public abstract double findArea ( );

   

}

(d)

public class abstract Rectangle {

   public abstract double findArea ( );

   

}

<h2>Answer:</h2>

(b)

public abstract class Rectangle {

   public abstract double findArea ( );

}

<h2>Explanation:</h2>

When a class is declared with the abstract keyword, the class is called an abstract class. Abstract classes cannot be instantiated and may include one or more abstract methods. If a class contains an abstract method, then it (the class) must be declared abstract.

In Java, abstract classes are defined using the following format:

<em>[access_modifier]</em> abstract class <em>[name_of_class]</em>

[access_modifier] specifies the access modifier of the class which could be public, private, e.t.c

abstract is the keyword that specifies that the class is an abstract class.

class is a keyword used for defining classes

name_of_class specifies the name of the class.

The only option that fulfils this format is <em>option b</em> where;

(i) The access modifier is public

(ii) The name of the class is Rectangle

Option a is not correct because the <em>abstract</em> keyword is supposed to come before the <em>class</em> keyword.

Option c is not correct because the keyword <em>abstract</em> is missing. In other words, the class must be declared abstract since it contains abstract method findArea();

Option d is not correct because the <em>abstract</em> keyword is supposed to come before the <em>class</em> keyword.

7 0
2 years ago
You and your friend who lives far away want to fairly and randomly select which of the two of you will travel to the other’s hom
Phantasy [73]

Answer:

c. your friend can hash all possible options and discover your secret.

Explanation:

SHA-256 is a set of hash functions that was designed by the NSA. SHA-2 is considered an upgrade on the set that was its predecessor, SHA-1. A hash is a mathematical function that condenses data in a process of one-way encryption. SHA-256 creates hash algoritms that are considered irreversible and unique. However, one of the properties of hashing algorithms is determinism, which means that any computer in the world would be able to compute a particular hash and get the same answer.

6 0
2 years ago
What are the primary functions of motor oil? a. Reduce friction and prevent wear b. Keep engine surfaces clean c. Remove heat to
ryzh [129]

The answer is E: all of the above.

7 0
2 years ago
Martha has a large data list and wants to sort it quickly and efficiently. Which algorithm should Martha use
Elena-2011 [213]

Answer:

quicksort

Explanation:

There are many types of asymptotically efficient sorting algorithms that can be used but one of the more commonly used for large data lists would be quicksort. This is a sorting algorithm that focuses on choosing a value from the list and working around that value in order to sort the data piece by piece. For larger data sets this method is widely used due to its speed and efficiency which is exactly what Martha needs in this scenario.

4 0
3 years ago
How do I add my bestie on brainy? /??!!! ​
ziro4ka [17]

Answer:

You have to remember their name on here

Explanation:

If u dont you cant talk to them again

3 0
2 years ago
Other questions:
  • Differentiate between third and fourth generation of computer​
    6·1 answer
  • According to a recent study, more than 75 percent of teens between the ages of twelve and seventeen in the United States have a
    11·2 answers
  • Within a google form when looking which option do u use?
    13·1 answer
  • Which describes which CTSO each student should join?]
    7·1 answer
  • In which step of writing a program does a programmer first use a<br> compiler?<br> documentin
    6·1 answer
  • What group in the review tab contains the commands and to accept or reject changes made to a document
    14·2 answers
  • The appropriate semaphore in C to give one more turn to writer so it can clean up IPC objects is WRITE_SEM. Is it true or false
    5·1 answer
  • What is computer code?<br> A. Java Script<br> B. XML<br> C. HTML<br> D. Any programming language
    6·1 answer
  • What are the characteristics of computer. Explain any one​
    15·2 answers
  • Numerous engineering and scientific applications require finding solutions to a set of equations. Ex: 8x + 7y = 38 and 3x - 5y =
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!