Skip to main content

FEATURED POST

Why the World is Running Out of Computers

Question: Write a java program that implements bank transactions using user defined exception.

Question: Write a java program that implements bank transactions using user defined exception.



import java.util.*;

class UDE{

    public static void main(String ts7[]) throws MinimumBal {

        Scanner sc= new Scanner(System.in);

        double bal;

System.out.println("Enter current balance:");

bal=sc.nextDouble();

System.out.println("Enter amount to withdrawal");

        int n = sc.nextInt();

        try {

            if (bal<n)

                  throw new MinimumBal("Account ae taka nei bhai !\nYour Current balance is "+bal);

            else     System.out.println("Money left:"+(bal-n));        }

        catch (MinimumBalmab)  {

mab.printStackTrace();

}  }

}

class MinimumBal extends Exception{

    String message;

    public MinimumBal(String message)  {

this.message = message;  }

    public String toString(){

        return message;
    }
}
OUTPUT:


Keywords:

How to recover the classnotfoundexception in Java?
What are the top most requirements or expectations of client for develop Java web application?
Java program question paper in 2020







Comments

Popular Posts

Question: Create a base class called “Vehicle” that stores number of wheels and speed. Create the following derived classes

Question: Create a base class called “Vehicle” that stores number of wheels and speed. Create the following derived classes:  Ø “Car” that inherits “Vehicle” and also stores number of passengers.  Ø “Truck” that inherits “Vehicle” and also stores the load limit.  Write a main() function to create objects of these classes and display all the information about Car and Truck. Also, compare the speed of the two vehicles, Car and Truck and display “faster” or “slower” if Car is faster or slower than Truck. import java.util.*; class Vehicle{   int wheels;   double speed; } class Car extends Vehicle{   int pass;   void input(){    Scanner sc=new Scanner(System.in); System.out.println("Enter the car's details:\nNo. of wheels:");    wheels=sc.nextInt(); System.out.println("Speed of Car(Km/hr):");    speed=sc.nextDouble(); System.out.println("No. of passengers:");   ...

Question: Develop an abstract class “GeometricObject” which will have two variables colourand weight. It would have constructor function for setting the colour as “white” and the weight as 1.0 as default values. The class should have methods getColour() and getWeight() to return the colour and weight values to the caller. The class should have two abstract methods findArea() and findCircumference(). Write a subclass for “GeometricObject” called “Triangle” which will be able to calculate area and circumference for a triangle.

Question: Develop an abstract class “GeometricObject” which will have two variables colourand weight. It would have constructor function for setting the colour as “white” and the weight as 1.0 as default values. The class should have methods getColour() and getWeight() to return the colour and weight values to the caller. The class should have two abstract methods findArea() and findCircumference().  Write a subclass for “GeometricObject” called “Triangle” which will be able to calculate area and circumference for a triangle. import java.util.*; import java.math.*; abstract class GeometricObject {             String colour;             double weight;             public GeometricObject()             {      ...