Advertisement
Guest User

Untitled

a guest
Sep 15th, 2019
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.27 KB | None | 0 0
  1. //Bill subclass
  2. public class FixedBill extends Bill
  3. {
  4. private String fixedBillDesc; //description of expense
  5. private int fixedBillFrequency; //frequency of bill, monthly, quarterly, etc
  6. //variables set neutral default values
  7. public FixedBill()
  8. {
  9. fixedBillDesc = null;
  10. fixedBillFrequency = 0;
  11. }
  12. //constructor for FixedBill, sets values for variables
  13. public FixedBill(String owedTo, String owedFor, double owedAmt, String owedWhen, String owedPaidDate,
  14. String owedDesc, int owedFrequency)
  15. {
  16. setBiller(owedTo);
  17. setBillAcct(owedFor);
  18. setBillAmtDue(owedAmt);
  19. setBillDueDate(owedWhen);
  20. setFixedBillDesc(owedDesc);
  21. setBillPaidDate(owedPaidDate);
  22. setFixedBillFrequency(owedFrequency);
  23. }
  24.  
  25. //returns fixedBillFrequency text description
  26. public String fixedBillDecodeFrequency()
  27. {
  28. //decides what to return
  29. switch(fixedBillFrequency)
  30. {
  31. case 1 :
  32. return "monthly";
  33. case 2 :
  34. return "quarterly";
  35. case 3 :
  36. return "semi-annually";
  37. case 4 :
  38. return "annually";
  39. default :
  40. return null;
  41. }
  42. }
  43.  
  44. //sets fixedBillDesc
  45. public final void setFixedBillDesc(String owedDesc)
  46. {
  47. fixedBillDesc = owedDesc;
  48. }
  49.  
  50. //sets fixedBillFrequency
  51. public final void setFixedBillFrequency(int owedFrequency)
  52. {
  53. fixedBillFrequency = owedFrequency;
  54. }
  55.  
  56. //returns fixedBillDesc
  57. public final String getFixedBillDesc()
  58. {
  59. return fixedBillDesc;
  60. }
  61.  
  62. //returns fixedBillFrequency
  63. public final int getFixedBillFrequency()
  64. {
  65. return fixedBillFrequency;
  66. }
  67.  
  68. //returns string output containing all bill information, paid status, and its detailed info
  69. public String toString()
  70. {
  71. String output = String.format(getBiller() + " is owed $" + getBillAmtDue() +" on account " + getBillAcct()+ " by " + getBillDueDate()+"\n");
  72. if(getBillPaidDate() == null) //checks if bill was paid
  73. {
  74. output += "This bill has not yet been paid.";
  75. } else
  76. {
  77. output += "This bill was paid on "+ getBillPaidDate() +".";
  78. }
  79. output += "\nThis bill is for " + getFixedBillDesc() + " and is paid " + fixedBillDecodeFrequency() + ".\n";
  80. return output;
  81.  
  82. }
  83.  
  84. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement