Wednesday, March 11, 2009

DivisionTest

/*Programmer:Rosedil Mae P. Mobreros
Date started: March 09, 2009
Date ended: March 11, 2009
Description: A program that will generate the quotient, by asking first the numerator and denominator.

import java.util.Scanner;
import java.util.InputMismatchException;

public class DivisionTest{

public static float quotient(float numerator, float denominator)throws ArithmeticException
{
return numerator/denominator;
}

public static void main(String args[]){
Scanner scan=new Scanner(System.in);

String endchar="kjl";
char x=endchar.charAt(0);
float numerator=0;
float denominator=0;
String ask="kjl";



while(y!='s')
{
if(y != 'S')
{

try
{
System.out.println("Enter numerator:");
if((scan.next().charAt(0)=='s')||(scan.next().charAt(0)=='S'))
{
y=scan.next().charAt(0);
}
else
{
numerator=scan.nextFloat();
System.out.println("Enter divisor:");
denominator=scan.nextFloat();
float result=quotient(numerator,denominator);
System.out.println(numerator+"/"+denominator+" is "+answer);
}
}

catch(ArithmeticException err)
{
System.err.println("Dividing "+numerator+" by "+denominator);
}

catch(InputMismatchException inputerr)
{
System.err.println("The number you entered is not valid.\nPlease enter a valid number.");
}
catch(IndexOutOfBoundsException index)
{
System.err.println("");
}

}
else
{
y='s';
}
}

}
}

No comments:

Post a Comment