Posts

Showing posts from 2017

Exception_Handling Program

Create an exception class named NegativeNumberException extended from the class Exception. This class should contain a parameterless constructor to call the Exception class constructor with the message “You should enter a positive number”. Create a class named exercise3 that contains: a) A method named M1 that accepts a double variable as argument and returns its square root. The method should throw the NegativeNumberException exception defined above. b) The main method to prompt the user to enter a number and then to call the method M1 (insert a try-catch block to handle the NegativeNumberException exception). package javaapplication5; import java.util.*; class NegativeNumberException extends Exception { public NegativeNumberException() { super("You should enter a Positive Number."); } } public class JavaApplication5 { public static void main (String[] args) {         Scanner s;               ...

Create a class named weather report that holds a daily weather report with data member’s day_of_month, hightemp, lowtemp, amount_rain and amount_snow. Use different types of constructors to initialize the objects. Also include a function that prompts the user and sets values for each field so that you can override the default values. Generate monthly report that displays average of each attribute.

package javaapplication23; import java.util.Scanner; public class weather_report {     int day_of_month;     float hightemp, lowtemp, amount_rain, amount_snow;     public weather_report()     {         day_of_month=0;         hightemp=0;         lowtemp=0;         amount_rain=0;         amount_snow=0;             }     public weather_report(int dom,float ht,float lt,float ar,float as)     {     day_of_month=dom;     hightemp=ht;     lowtemp=lt;     amount_rain=ar;     amount_snow=as;         }         public void get()     {     System.out.println("\nEnter the values for the particular day:");     Scanner s=new Scanner(System.in);     Sys...

Create an abstract class called Plan, which comprises of a data member called ‘rate’ of type double, one member method called getRate(), which is to be implemented, and another member method called calculateBill(int units), which takes a parameter called ‘units’ of type integer. The calculateBill(int units) method will display the total amount of bill.

package javaapplication24; import java.util.Scanner; abstract class plan {         public double rate;         abstract public void getrate();         double b;         public void calculate_bill(int units)         {               //System.out.println("hello");                         b = units*rate;                     }          public void get()         {         System.out.println("the value is"+b);         }     //public static void main(String[] args) {           //}     } class domestic_plan extends plan {             public void getrate()   ...

Write a java program to create an abstract class named Shape that contains two integers and an abstract method named printArea(). Provide three classes named Rectangle, Triangle and Circle such that each one of the classes extends the class Shape. Each one of the classes contain only the method printArea( ) that prints the area of the given shape.

package javaapplication3; abstract class shape { int a=3,b=4; abstract public void print_area(); } class rectangle extends shape { public int area_rect;         @Override public void print_area() { area_rect=a*b;                 System.out.println("The area of rectangle is:"+area_rect); } } class triangle extends shape { int area_tri;         @Override public void print_area() { area_tri=(int) (0.5*a*b);                 System.out.println("The area of triangle is:"+area_tri); } } class circle extends shape { int area_circle;         @Override public void print_area() { area_circle=(int) (3.14*a*a);                 System.out.println("The area of circle is:"+area_circle); } } public class JavaApplication3 {     /**     ...

Create Employee Class with Method getdata and setdata. Create following subclasses to generate biodata. i) Personal record ii)) Professional record iii) Academic record Assume appropriate data members and member function to accept required data & print bio-data. Use Overriding at suitable places.Create bio-data using multilevel inheritances.

package javaapplication2; import java.util.Scanner; class Employee {             int id;         String name;         Scanner s=new Scanner (System.in);         public void getdata()         {             System.out.println("Enter your id:");             id=s.nextInt();             System.out.println("Enter your name:");             name=s.next();                     }         public void setdata()                 {             System.out.println("The id is"+id);             System.out.println("The name is"+name);                ...