Guest User

Untitled

a guest
Nov 8th, 2019
85
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ADD TO THE TODO PART OF PrintCommand.java
  2.  
  3. private void runPrintPlan(Database database) {
  4. if (queryType.equals("NUM_CUSTOMERS")) {
  5. System.out.println("Number of customers under " + queryValue + " is " + database.numberOfCustomersUnderThisContract(queryValue));
  6. } // + database.me3(queryValue)
  7. if (queryType.equals("TOTAL_PAYED_TO_CUSTOMERS")) {
  8. System.out.println("Total amount payed under " + queryValue +" is " + database.totalAmountPaidForClaimsWithinPlan(queryValue));
  9. }
  10. }
  11.  
  12. long numberOfCustomersUnderThisContract(String planName) {
  13. ArrayList<String> plans = new ArrayList<>();
  14. for (Contract contract : contracts) {
  15. plans.add(contract.getPlanName());
  16. }
  17. return Collections.frequency(plans, planName);
  18. }
  19.  
  20.  
  21. ADD TO THE end of Database.java
  22. long totalAmountPaidForClaimsWithinPlan(String planName) {
  23. long totalPaid = 0;
  24. for (Claim claim : claims) {
  25. Contract contract = getContract(claim.getContractName());
  26. if (contract.getPlanName().equals(planName)) {
  27. if (claim.wasSuccessful()) {
  28. long deductible = getPlan(contract.getPlanName()).getDeductible();
  29. long claimAmount = claim.getAmount();
  30. totalPaid += (claimAmount - deductible);
  31. }
  32. }
  33. }
  34. return totalPaid;
  35. }
RAW Paste Data