I am extremely new to java and having a hard time grasping it for my summer class. I am stuck on one problem so if anybody could help that would be great!
The distance a vehicle travels can be calculated as follows:
Distance = Speed * Time
Write a program that asks the user for the speed of a vehicle (in MPH) and the number of hours they traveled. It should use a loop to display the distance a vehicle has traveled for each hour of a time period specified by the user. For example, if a vehicle is traveling at 40 MPH for a three hour time period, it should show something like this:
Hour Distance Traveled
-----------------------------------
1 40
2 80
3 120
Input Validation: Do not accept a negative number for speed and do not acept any value less than 1 for time traveled
This is what I Have so far...
package lab4;
public class num2
{
public static void main(String[] args)
{
final int Time_Incrememnt = 1;
int d;
int s;
int t;
int i;
String input;
System.out.println("What is the speed of the vehicle in MPH?");
s = keyboard.nextInt();
while (s <= 0)
{
System.out.print("Your speed must be greater than zero. Please re-enter.");
}
System.out.print("Enter the number of hours that you have traveled: ");
t = keyboard.nextInt();
while (t <= 1)
{
System.out.print("Your hours must be at least 1 or more. Please re-enter.");
System.out.println("Hours Distance Traveled");
System.out.println("--------------------------------");
for (i = 1; i <= t; i++)
d = s*t;
}
}
}