Latest Activity In Study Groups

Join Your Study Groups

VU Past Papers, MCQs and More

We non-commercial site working hard since 2009 to facilitate learning Read More. We can't keep up without your support. Donate.

Suppose you have to write a small Java program that catches exceptions with super classes. You are required to use inheritance to create an exception superclass (called ExceptionA) and exception subclasses ExceptionB and ExceptionC; where ExceptionB inherits from ExceptionA and ExceptionC inherits from ExceptionB. Your program must demonstrate that the catch block for type ExceptionA catches exceptions of types ExceptionB and ExceptionC.


Hint: You can use Arithmetic exception like divide by 0 or any similar one.
NOTE: You are required to use Graphical User Input (GUI) to show output on the screen.

Views: 18306

Attachments:

Replies to This Discussion

yes i agree.

not related to assignment.

apko mila solution ?

I have a perfect solution but I can't upload here due to rules of the Developer who has developed the program related to this assignment. if you want a perfect solution of this assignment then you should contact with Sami Zain. All credit goes to Sami Zain who helped me so much. the link is given below. don't forget to like his page...

https://www.facebook.com/JavaWorkHouse/

no code for Arithmetic exception like divide by 0

to plz ap snd kr dyn . sami zain se kasy kha ja skta
????

Ghulam Rasool Khan

menay jo link share kea hay wahan se mil jaiy gi. lekin usay yahan post mat kijiay ga

@Ghulam Rasool Khan ..osmien output1 ya output2 ki file upload karni hia?

Assignment.java
ExceptionA.java
ExceptionB.java
ExceptionC.java

ye chaar files kam ki hen. is k bagher code incomplete hay in chaaroun ko submit krna hay janab

ghulam rusool yeh cmplt solution nhi hai plus exception ki file mein ap ny exception se extend kia hai or exception ki file nhi bnai, arithmetic operation b perform nhi hua is m

This is the correct one, dont run in cmd, run in compiler, netbeans or online compiler

import java.util.Scanner;
public class DivideByZeroDemo
{

public static void main(String[] args)
{
Demo oneTime = new Demo();
oneTime.doIt();
}
}
class Demo
{
private int numerator;
private int denominator;
private double quotient;
public void doIt()
{
try
{
System.out.println("Enter numerator:");
Scanner keyboard = new Scanner(System.in);
numerator = keyboard.nextInt();
System.out.println("Enter denominator:");
denominator = keyboard.nextInt();
if (denominator == 0)
throw new ArithmeticException("Division by zero!");
quotient = numerator / (double)denominator;
System.out.println(numerator + "/" + denominator +
" = " + quotient);
}
catch(Exception e)
{
System.out.println(e.getMessage());
giveSecondChance();
}
System.out.println("End of program.");
}
public void giveSecondChance()
{
System.out.println("Try again:");
System.out.println("Enter numerator:");
Scanner keyboard = new Scanner(System.in);
numerator = 12;
System.out.println("Enter denominator:");
System.out.println("Be sure the denominator is not zero.");
denominator = 2;
if (denominator == 0)
{
System.out.println("I cannot do division by zero.");
System.out.println("Since I cannot do what you want,");
System.out.println("the program will now end.");
System.exit(0);
}
quotient = ((double)numerator) / denominator;
System.out.println(numerator + "/" + denominator +
" = " + quotient);
}
}

if there is any problem, you can email me  bwpmukarram@gmail.com

and if you see its wrong then highlight the mistake

bro code mei error a rha hai mere pass
java.lang.ExceptionInInitializerError
Caused by: java.lang.RuntimeException: Uncompilable source code - class DivideByZeroDemo is public, should be declared in a file named DivideByZeroDemo.java
at DivideByZeroDemo.(DivideByZeroDemo.java.java:2)
Exception in thread "main" C:\Users\Mudas\AppData\Local\NetBeans\Cache\8.2\executor-snippets\run.xml:53: Java returned: 1
BUILD FAILED (total time: 0 seconds)

ye wala error a rha hai

RSS

© 2021   Created by + M.Tariq Malik.   Powered by

Promote Us  |  Report an Issue  |  Privacy Policy  |  Terms of Service