when I run it display this error Exception in thread "main" java.lang.NullPointerException at Abstract2.main(Abstract2.java:70) pleae tell me how to resolve it
my code is given below
import java.util.*;
abstract class plan
{
public double rate,bill;
public abstract void getrate();
public void cbill(int unit)
{
double bill=rate*unit;
System.out.println("bill is="+bill);
}
}
class domestic extends plan
{
public void getrate()
{
rate=2.5;
}
}
class commercial extends plan
{
public void getrate()
{
rate=5.5;
}
}
class industrial extends plan
{
public void getrate()
{
rate=7.5;
}
}
class bill
{
public plan getplan(String plantype)
{
if(plantype==("domestic"))
{
return new domestic();
}
if(plantype==("commercial"))
{
return new commercial();
}
if (plantype==("industrial"))
{
return new industrial();
}
return null;
}
}
class Abstract2
{
public static void main(String aa[])
{
plan p;//instance of class plan
String plantype;
int unit;
double rate;
bill b=new bill();
Scanner sc=new Scanner(System.in);
System.out.println("enter the plan type=");
System.out.println(" domestic");
System.out.println(" commercial");
System.out.println(" industrial");
plantype=sc.next();
System.out.println("enter the units");
unit=sc.nextInt();
p=b.getplan(plantype);
p.getrate();//line 70
p.cbill(unit);
}
}
please tell me how to resolve it