Blog Page 3

Write a program to define custom exception called “no match exception” that is thrown...

/*Write a program to define custom exception called "no match exception" that is thrown when a string is not equal to "internet" This string is providing through Joption pane.*/ import javax.swing.JOptionPane; class MatchException extends Exception { public MatchException() { //super(message); } } class matchstring { public...

Write a java probram that accepts 5 even numbers from joptionpane. If any of...

/*Write a java probram that accepts 5 even numbers from joptionpane. If any of the number is odd then throw custom exception OddException and count such invalid numbers.*/ import javax.swing.JOptionPane; class oddevenexception extends Exception { public oddevenexception() { super("oddException"); } } class oddeven { int n=new int; public...

Write a java program which takes 2 arguments – a string and its length....

/*Write a java program which takes 2 arguments - a string and its length. If the length of the string is not according to given one then throw the user defined LengthMatcnhException and handles it appropriately*/ ...

Write a program to display the sum of digits of given numbers with exception...

/*Write a program to display the sum of digits of given numbers with exception handling.*/ import java.io.*; import javax.swing.JOptionPane; class bb { public void set(int a,int b,int c) ...

Write an application that prompts user for a color name. If it is not...

/*Write an application that prompts user for a color name. If it is not red, white or blue, throw a user defined exception and prompt the user again to enter color.*/ import javax.swing.JOptionPane; public class twelth { /*public static...

Write an interface called Numbers with a method int process(int x,int y). Write a...

/*Write an interface called Numbers with a method int process(int x,int y). Write a class called Sum in which the process() method finds the sum of two numbers and returns an int value. Write another...

Write a program which takes an array as an argument to a function, sort...

/*Write a program which takes an array as an argument to a function, sort it and return it back to main program.*/ import javax.swing.JOptionPane; class array { public void aray(int a) { System.out.println(a.class); } } public class sort_array { public static void main(String args) { array a=new...

Define a class MotorVehicle as modelName,modelNumeber,modelPrice, and a method display()to display these details.Create another...

/*Define a class MotorVehicle as modelName,modelNumeber,modelPrice, and a method display()to display these details.Create another class Car which inherits the class MotorVehicle and has the member discountRate,and having display() method to display details.Test this class with suitable constructor.*/ import...

Write a class with a method to find the area of a rectangle. Create...

/*Write a class with a method to find the area of a rectangle. Create a subclass to find the volume of a rectangular shaped box.*/ import javax.swing.JOptionPane; class Rectangle { protected int l,b,h; public void area() { l=Integer.parseInt(JOptionPane.showInputDialog(null,"Enter length")); b=Integer.parseInt(JOptionPane.showInputDialog(null,"Enter breadth")); h=Integer.parseInt(JOptionPane.showInputDialog(null,"Enter height")); int...

Create a class named student with sid and sname as a data member.Create array...

/*Create a class named student with sid and sname as a data member.Create array of student class and display the details.*/ import javax.swing.JOptionPane; class student { int sid; String sname; public void get() { sid=Integer.parseInt(JOptionPane.showInputDialog(null,"Enter id")); sname=JOptionPane.showInputDialog(null,"Enter name"); } ...