Sunday, April 1, 2018

TEMPERATURE CONVERTER USING EXCEPTION IN JAVA

A simple program that will ask the user to give temperature in Fahrenheit and convert into Celsius temperature equivalent using exceptions in Java.

I am currently accepting programming and web development work kindly contact me in the following email address for further details. Thank you.

My email address are the following jakerpomperada@gmail.com and jakerpomperada@yahoo.com.

My mobile number here in the Philippines is 09173084360.

My telephone number at home here in Bacolod City, Negros Occidental Philippines is  +63 (034) 4335675.




Sample Program Output


Program Listing

Celsius.java

package exceptiondemo;

import java.util.Scanner;
import java.util.InputMismatchException;
import java.text.DecimalFormat;

/**
 * NetBeans IDE 8.2
 * @author Mr. Jake R. Pomperada
 * March 20, 2018  Tuesday
 * Bacolod City, Negros Occidental
 */
public class Celsius {

    public static final DecimalFormat TWO_DECIMAL = new DecimalFormat(".##");
     
    public static void main(String[] args) {
        
        Scanner sc=new Scanner(System.in);
             boolean goodData = false;
                
              while(!goodData) {
              try {
                System.out.print("TEMPERATURE CONVERTER USING EXCEPTION");
                System.out.println("\n");
                System.out.print("Temperature in Fahrenheit  : ");
double temp=sc.nextDouble();
                
                double temperature = ((temp - 32)*5)/9;
                
                System.out.println("\n");
                System.out.println("The temperature in Celsius is " 
                        + TWO_DECIMAL.format(temperature) +".");
                System.out.println("\n");
goodData = true;
       
              } catch(InputMismatchException e) {
            
                sc.next();
                System.out.println("You Entered a Bad Data." );
                System.out.println("Please Try Again." );
                System.out.println("\n");
                }
            }  // while loop end
System.out.print("\t END OF PROGRAM");
        System.out.println("\n");
     }
}




No comments:

Post a Comment