/*
Programmer: Nerissa Agapay
Date Started: March 6,2009
Date Ended: March 7, 2009
Description:This program will calculate the numerator and denominator,
then press 'y' if you want to continue,
otherwise just press any key in the keyboard to terminate.
*/
import java.util.InputMismatchException;
import javax.swing.*;
public class UserFriendlyDivision{
public static float quotient(float x, float y)throws ArithmeticException{
public static void main(String args[]){
char ans='y';
while(ans=='y'){
try{
float x=Integer.parseInt(JOptionPane.showInputDialog("Enter numerator:"));//ask user to input a integer
float y=Integer.parseInt(JOptionPane.showInputDialog("Enter divisor:"));//second integer input
float quotient=x/y; //calculate the answer
System.out.println("The quotient is:"+quotient ); //display the quotient
}
}
catch(ArithmeticException Numerr)// organizing the error in arithmetic
{
System.err.println("You can't divide "+x+" by "+y);//message print
}
catch(InputMismatchException Inputerr)//organizing the error in inputMismatch like string
{
System.err.println("You enter bad data.\nPlease try again.");//message print
}
String a=(JOptionPane.showInputDialog("Do you want to continue?");
ans=a.chartAt(0);
}
}
}
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment