জাভা প্রোগ্রামিং পর্ব-১৮



2.23 (Physics: acceleration) Average acceleration is defined as the change of velocity divided by the time taken to make the change, as shown in the following formula:
a= (v1-v0)/t
Write a program that prompts the user to enter the starting velocity V0 in meters/second, the ending velocity in meters/second, and the time span t in seconds, and displays the average acceleration.

Code : File name-Acceleration.java
import java.util.*;
import javax.swing.*;
public class Acceleration {
    public static void main (String arg[]){
        Scanner input =new Scanner (System.in);
        double value0, value1, t, avg;

        System.out.print("Enter value for v0: = ");
        value0= input.nextDouble();
        System.out.print("Enter value for v1: = ");
        value1= input.nextDouble();
        System.out.print("Enter value for t: = ");
        t= input.nextDouble();

        avg = (value1-value0)/t;
        System.out.print("The average acceleration is : = " + avg);
        }
    }

2.24 (Physics: finding runway length) Given an airplane’s acceleration a and take-off speed v, you can compute the minimum runway length needed for an airplane to take off using the following formula: length = v2/2a
Write a program that prompts the user to enter v in meters/second (m2/s) and the acceleration a in meters/second squared and displays the minimum runway length.

Code : File name-RunwayLength.java
import java.util.*;
import javax.swing.*;
public class RunwayLength {
    public static void main (String arg[]){
        Scanner input =new Scanner (System.in);
        double acceleration, speed, length;

        System.out.print("Enter speed: =");
        speed = input.nextDouble();
        System.out.print("Enter accelaration: =");
        acceleration = input.nextDouble();

        length = (Math.pow(speed, 2)/(2*acceleration));
        System.out.print("The minimum runway length for this airplane is: = "+length);
        }
    }

2.25* (Current time) Listing 2.6, ShowCurrentTime.java, gives a program that displays the current time in GMT. Revise the program so that it prompts the user to enter the time zone offset to GMT and displays the time in the specified time zone.

Code : File name-CurrentTime.java
import java.util.*;
import javax.swing.*;
public class CurrentTime {
    public static void main (String arg[]){
        Scanner input =new Scanner (System.in);

        System.out.print("The GMT time is: = ");
        double gmt = input.nextDouble();
        gmt = gmt*60;

        long totalMilliseconds = System.currentTimeMillis();
        long totalSeconds = totalMilliseconds/1000;
        long currentSecond =(totalSeconds%60);
        long totalMinutes = totalSeconds/60;
        totalMinutes = (long)(totalMinutes+gmt);
        long currentMinutes = (totalMinutes)%60;
        long totalHours = (totalMinutes)/60;
        long currentHours = totalHours%24;

        System.out.println("Current time is " +currentHours + ":" +currentMinutes + ":" +currentSecond);
        }
    }

Loading
Twitter Delicious Facebook Digg Stumbleupon Favorites More

 
Flying Twitter Bird Widget By ICT Sparkle