Only thing different is I have to have a class that stores all of the information, then a demo program to get the users input and run everything. Not just all in one.
This is what I got so far, but obviously I make things much more complicated then what they need to be. This is the sound class that will be accesed by the soundDemo program. I wrote this one from scratch. I have to have mutator and accessor methods.
public class sound
{
private final double air = 1100;
private final double water = 4900;
private final double steel = 16400;
double distance;
double time;
// no arg constructor
public sound()
{
distance = 0.0;
}
//parameterized constructor
public sound(double d)
{
distance = d;
}
//mutator methods
public void setDistance(double d)
{
distance = d;
}
//accessor methods
public double getSpeedInAir()
{
return distance / 1100;
}
public double getSpeedInWater()
{
return distance / 4900;
}
public double getSpeedInSteel()
{
return distance / 16400;
}
}
This is my demo program. I have repeating information because I am not sure what needs to be where. I used the else if portion from the solution in the thread above.
import java.util.Scanner
import java.util.DecimalFormat
public class soundDemo
{
public static void main(String[] args)
{
double choice
System.out.print("Please choose 1. Air 2. Water 3. Steel 4. Quit ");
choice = keyboard.nextDouble();
if (input.equals("1"))
{
time = (distance / 1100);
System.out.println("The total time traveled is " + time + ".");
}
else if (input.equals("2"))
{
time = (distance / 4900);
System.out.println("The total time traveled is " + time + ".");
}
else if (input.equals("3"))
{
time = (distance / 16400);
System.out.println("The total time traveled is " + time + ".");
}
else
{
System.out.println("Invalid input!");
}
System.out.print("What distance would you like to know? ");
distance = keyboard.nextDouble();
I just need nudged in the right direction, because I'm pretty sure I have all the information already coded. It's just in the wrong place. Any tips would be greatly appreciated!

New Topic/Question
Reply



MultiQuote







|