java - How do I calculate subTotal using one method and multiple constants and variables? -


i'm getting java , have program need write class , classdriver. i'm supposed write program calculate total cheesecake orders (four different kinds) based on price , count. price given each constant. count based on user input. there can 1 subtotal method calculate subtotal of cheesecakes bought.

i'm not sure of concept need , i've been trying hours now. please able to.

public class cheesecakeorder {      private final double plain_cheesecake_price=10.0;     private final double marble_cheesecake_price=15.0;     private final double choco_chip_cheesecake_price=18.0;     private final double variety_cheesecake_price=22.0;     private final double school_share_rate=.12;     private int plaincheesecakecount=0;     private int marblecheesecakecount=0;     private int chocochipcheesecakecount=0;     private int varietycheesecakecount=0;      public double getplain_cheesecake_price()     {         return plain_cheesecake_price;     }      public double getmarble_cheesecake_price()     {         return marble_cheesecake_price;     }      public double getchoco_chip_cheesecake_price()     {         return choco_chip_cheesecake_price;     }      public double getvariety_cheesecake_price()     {         return variety_cheesecake_price;     }      public int getplaincheesecakecount()     {         return plaincheesecakecount;     }      public int getmarblecheesecakecount()     {         return marblecheesecakecount;     }      public int getchocochipcheesecakecount()     {         return chocochipcheesecakecount;     }      public int getvarietycheesecakecount()     {         return varietycheesecakecount;     }      public void setplaincheesecake(int plaincheesecakecount)     {         this.plaincheesecakecount=plaincheesecakecount;     }      public void setmarblecheesecake(int marblecheesecakecount)     {         this.marblecheesecakecount=marblecheesecakecount;     }      public void setchocochipcheesecakecount(int chocochipcheesecakecount)     {         this.chocochipcheesecakecount=chocochipcheesecakecount;     }      public void setvarietycheesecakecount(int varietycheesecakecount)     {         this.varietycheesecakecount=varietycheesecakecount;     }      public double calculatesubtotal()     {         double subtotal;         subtotal = price * count;         return subtotal;     }      public double calculatedonation()     {         double donation;         donation = (calculatesubtotal()*school_share_rate);         return donation;     }      public double calculatetotal()     {         double total;         total = donation+calculatesubtotal();         return total;     } } 

try using method uses variable arguments parameter. find argument count passed variable, loop through , calculate each 1 until reach end of collection.


Comments