So I have code set up such that I have a subclass 'PBill' as an inherited extension of a class 'customer'. However, when I try to create a new PBill object in my main function, it says that no such object exists, and it can't figure out what to do. Here is my example:
public class customer {
private int reg;
private int prem;
private int raw;
private int total;
public customer(int re,int pr, int ra){
this.reg=re;
this.prem=pr;
this.raw=ra;
this.total=re+pr+ra;
}
public customer(int re){
this(re,0,0);
}
public customer(int re,int pr){
this(re,pr,0);
}
public int totalBag(){
return(reg);
}
public double calctot(){
if(this.reg>10){
reg+=1;
}
double totcost=reg*10+prem*15+raw*25;
return(totcost);
}
public String printBill(){
return("You bought "+reg+" bags of regular food, "+prem+" bags of premium food, and "+raw+" bags of raw food. If you bought more than 10 bags of regular food, you get one free bag! Your total cost is: $"+this.calctot()+".");
}
class PBill extends customer{
public PBill(int re, int pr, int ra){
super(re, pr, ra);
}
public PBill(int re, int pr){
super(re,pr);
}
public PBill (int re){
super(re);
}
public double calcTot(){
return(super.calctot()*.88);
}
public String printPBill(){
return("You are one of our valued Premium Customers! We appreciate your continued business. With your 12% discount, your total price is: $"+this.calcTot()+".");
}
}
The error message occurs when I try to call it in another class with a main object to create a new object, like this:
public static void main(String[] args){
PBill c1=new PBill(10,2);
Which is where it gives me the error that PBill can not be resolved to a type.
So how would I go about creating a new PBill object so that I can access the methods inside of it, and is there an easier way to define object inheritance?