জাভা প্রোগ্রামিং পর্ব-০৭



2.1 (Converting Celsius to Fahrenheit) Write a program that reads a Celsius degree in double from the console, then converts it to Fahrenheit and displays the result. The formula for the conversion is as follows:
fahrenheit = (9 / 5) * celsius + 32

Hint: In Java, 9 / 5 is 1, but 9.0 / 5 is 1.8.

Code : File Name- CelsiusToFahrenheit.java
import java.util.*;
public class CelsiusToFahrenheit {
    public static void main (String arg[]){

        Scanner input =new Scanner(System.in);
        System.out.print("Enter degre in Celsius : ");
        double celsius = input.nextDouble();

        double fahrenheit = (9.0/5.0)*celsius+32;
        System.out.print("Celsius" + celsius + "is" + fahrenheit + "in Fahrenheit");

        }
    }

2.2 (Computing the volume of a cylinder) Write a program that reads in the radius and length of a cylinder and computes volume using the following formulas:
area = radius * radius * π
volume = area * length

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

        System.out.print("Enter Radius of cylinder: = ");
        double radius =input.nextDouble();
        System.out.print("Enter length of cilynder: = ");
        double length =input.nextDouble();

        double area = radius*radius*3.14159;
        double volume = area*length;

        System.out.println("The area of cylinder is : = " + area);
        System.out.println("The volume of cylinder is : = " + volume);
        }
    }

2.3 (Converting feet into meters) Write a program that reads a number in feet, converts it
to meters, and displays the result. One foot is 0.305 meter.

Code : File Name- FeetToMeters.java
import java.util.*;
public class FeetToMeters {
    public static void main (String arg[]){
        Scanner input =new Scanner(System.in);
        System.out.print("Enter the value is feet : = ");
        double feet = input.nextDouble();
        double meter = (feet*0.305);
        System.out.print("Meter is = " +meter);
       }
    }

2.4 (Converting pounds into kilograms) Write a program that converts pounds into kilograms. The program prompts the user to enter a number in pounds, converts it to kilograms, and displays the result. One pound is 0.454 kilograms.

Code : File Name- PoundsToKilograms.java
import java.util.*;
import javax.swing.*;
public class PoundsToKilograms {
    public static void main (String arg[]){
        Scanner input =new Scanner (System.in);
        System.out.print("Enter value of pounds: = " );
        double pounds = input.nextDouble();

        double kilograms =pounds*0.454;
        System.out.print("Kilogram = " +kilograms);
        }
    }

2.5* (Financial application: calculating tips) Write a program that reads the subtotal and the gratuity rate, then computes the gratuity and total. For example, if the user enters 10 for subtotal and 15% for gratuity rate, the program displays $1.5 as gratuity and $11.5 as total.

Code : File Name- CalculatingTips.java
import java.util.*;
public class CalculatingTips {
    public static void main (String arg[]){
        Scanner input = new Scanner(System.in);
        System.out.print("Enter subtotal: =");
        double subtotals = input.nextDouble();
        System.out.print("Enter gratuity: = ");
        double gratuitys = input.nextDouble();

        double gratuity = (gratuitys/subtotals);
        double total = (subtotals+gratuity);

        System.out.print("Gratuity is: = $"+ gratuity + "and Total: = $"+total);
        }
    }

Loading
Twitter Delicious Facebook Digg Stumbleupon Favorites More

 
Flying Twitter Bird Widget By ICT Sparkle