Hi everyone. I am new to java programming and taking a class in college. I got to a problem which I can do but i don't know the correct way to do it. It says to use mutator and accesor . can you please explain what should i change? I also got an error running this program on my computer it says cannot find or locate the class. Thank you
write a program that should display a menu allowing the user to select air, water, or steel. Once the user has made a selection, he or she should be asked to enter the distance a sound wave will travel in the selected medium. The program will then display the amount of time it will take. Check that the user had selected on of the the available choices from the menu.
Design a class that stores in a distance field, in feet, traveled by a sound wave. The class should have the appropriate accessor and mutator methods for this field. In addition, the class should have the following methods:
getSpeedInAir. This method should return the number of seconds it would take a sound wave to travel, in air, the distance stored in the distance field. The formula to calculate the amount of time it will take the sound wave to travel the specified distance in air is:
Time= distance/1100
getSpeedInWater. This method should return the number of seconds it would take a sound wave to travel, in water, the distance stored in the distance field. The formula to calculate the amount of time it will take the sound wave to travel the specified distance in water is:
Time= distance/4900
getSpeedInSteel.This method should return the number of seconds it would take a sound wave to travel, in steel, the distance stored in the distance field. The formula to calculate the amount of time it will take the sound wave to travel the specified distance in steel is:
Time= distance/16400
import java.util.Scanner; // imports the scanner class
public class SSTheSpeedOfSound
{ // begin class
public static void main(String[] args)
{
System.out.printf("Medium\t\t\t Speed");
System.out.printf("Air\t\t\t 1100 feet/sec");
System.out.printf("Water\t\t\t 4900 feet/sec");
System.out.printf("Steel\t\t\t 16,400 feet/sec");
Scanner keyboard = new Scanner(System.in);
System.out.print("Enter air, water, or steel: ");
String input;
input = keyboard.nextLine();
System.out.print("Enter distance: ");
double distance;
distance = keyboard.nextDouble();
double time;
if (input.equals("air"))
{
time = (distance / 1100);
System.out.println("The total time traveled is " + time + ".");
}
else if (input.equals("water"))
{
time = (distance / 4900);
System.out.println("The total time traveled is " + time + ".");
}
else if (input.equals("steel"))
{
time = (distance / 16400);
System.out.println("The total time traveled is " + time + ".");
}
}
}