Friday, February 29, 2008

Friday night class

Riverdog said; Well I am at school in our class room, I was let into the class room to look up some options on the system. There is another class coming in at 520 PM on Fridays, and I will leave soon. I got the homework and learned how to make the printer work in class. We needed the IP address for the printer to load properties last week.


/*File: Distance Traveled.java
*CSCI 1911 Class Bruce McDowell
**/

import java.util.Scanner; // Needed for the Scanner class
/**
This program demonstrates a user controlled for loop.
*/
public class DistanceTraveled
{
public static void main(String[] args)
{
int number; // Loop control variable
int maxValue; // Maximum value to display
int time;
int speed;
int distance;
System.out.println("I will display a table of " +
"time and distance travelled by the hour.");
// Create a Scanner object for keyboard input.
Scanner keyboard = new Scanner(System.in);
// Get the maximum value to display.
System.out.print("How fast is your car? ");
speed = keyboard.nextInt();
while (speed <= 0)
{
System.out.print("Invalid entry try again? ");
speed = keyboard.nextInt();
}
System.out.print("How many hours traveled? ");
time = keyboard.nextInt();
while (time <= 0)
{
System.out.print("Invalid entry try again? ");
time = keyboard.nextInt();
}
// Display the table.
System.out.println("Hour Distance Traveled");
System.out.println("-------------------------");
for (number = 1; number <= time; number++)
{
distance = speed * number;
System.out.println(number + "\t\t" +
distance);
}
}
}

No comments: