Monday, March 9, 2009

User-Friendly Division

//Programmer Name: Jay S. Gil
//Date Finished: MARCH 11, 2009
//Purpose: To apply my knowledge in making a program of division.

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

public class Division {

public static void main(String[] args)
{
division(100, 0);
} public static void division(int numerator, int denominator )throws Exception

{
return numerator/denominator;}

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

int numerator;
int denominator;
char x=exitchar.charAt(0);

while(x!='q'){if(x != 'Q')
{
try {
if((scan.next().charAt(0)=='q')(scan.next().charAt(0)=='Q')){x=scan.next().charAt(0);
}
else
{
numerator=scan.nextInt();

System.out.println("Enter the divisor:");
denominator=scan.nextFloat();
int average = numerator / denominator;
System.out.println("Average : " + average);
}
}
int average = numerator / denominator;
System.out.println("Average : " + average);
} catch (Exception ex)
{
System.out.println("Divide" + ex.getMessage() + "Exception" + "\n" + "Please check the denominator");

catch(InputMismatchException inputerr)
{
System.err.println("You enter bad data.\nPlease try again.");
}

catch(IndexOutOfBoundsException index)
{
System.err.println("");}
}else
{
x='q';
}
} }
}

1 comment:

  1. This user-friendly division are indicate that when you enter a data,for example the user input an character value it quickly responce that the value entered are invalid..
    or such a bad data. IF the user enter the zero value denominator the program reply that the user must check the denominator and it could be an invalid. This program might have a good relation with the user. It is a looping division.

    ReplyDelete