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()
    {
        rate=3.50;
    }


}

class commercial_plan extends plan
{
    @Override
    public void getrate()
    {
        rate=7.50;
    }

}

class institutional_plan extends plan
{
    @Override
    public void getrate()
    {
        rate=5.50;
    }

}

class getplanfactory
{
    int unit;
    public void getplan(String plantype,int

unit)
    {
        if((plantype.equals("dp")))
        {
            domestic_plan d;
            d = new domestic_plan();
            d.getrate();
            d.calculate_bill(unit);
            d.get();
           
        }
        else if((plantype.equals("cp")))
        {
            commercial_plan c;
            c = new commercial_plan();
            c.getrate();
            c.calculate_bill(unit);
            c.get();
        }
        else{
       
       
        institutional_plan i;
            i = new institutional_plan();
            i.calculate_bill(unit);
            i.getrate();
            i.calculate_bill(unit);
            i.get();
        }
   
    }

   // private int strcmp(String plantype, String

dp) {
    //    throw new

UnsupportedOperationException("Not supported

yet."); //To change body of generated methods,

choose Tools | Templates.
   // }

    /*private int strcmp(String plantype, String

dp) {
        throw new UnsupportedOperationException

("Not supported yet."); //To change body of

generated methods, choose Tools | Templates.
    */

}

public class generatebill
{

public static void main(String[] args)
{
   
   int u;
    String s1;
getplanfactory g1;
    g1 = new getplanfactory();
Scanner s=new Scanner(System.in);
System.out.println("Enter

domestic,commercial,institutional");
s1=s.next();

System.out.println("Enter the units");
u=s.nextInt();
g1.getplan(s1,u);
}
}

/*Output:
run:
Enter domestic,commercial,institutional
dp
Enter the units
56
the value is196.0
BUILD SUCCESSFUL (total time: 13 seconds)

*/

Comments

  1. ▷ Top 10 casino sites in the world - Casino Sites
    Top 10 Casino Sites · 1. Grosvenor Casino · 2. PlayOJO Casino · 아트그라비아 장주님 3. 벳 365 한글 PlayOJO Casino · 4. 라이브 스코어 사이트 Vivo 룰렛 만들기 Gaming · 5. Betway Casino · 룰렛 만들기 6. Betsson Casino.

    ReplyDelete

Post a Comment

Popular posts from this blog

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.

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.

Exception_Handling Program