Advertisement
Guest User

Purchase Receipt

a guest
Feb 14th, 2016
692
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.07 KB | None | 0 0
  1. public class Problem1 {
  2.  
  3.     public static void main(String[] args) {
  4.         System.out.println(getCost(1, 1, 1, 1)); // Should be 1021.787
  5.         System.out.println(getCost(8, 3, 4, 5)); // Should be 3721.2572
  6.         System.out.println(getCost(10, 3, 4, 8)); // Should be 4775.8565
  7.         System.out.println(getCost(8, 2, 10, 10)); // Should be 7811.7972
  8.     }
  9.    
  10.     public static double getCost(int drives, int software, int phones, int pens) {
  11.         double driveCost = 49.95 * drives;
  12.        
  13.         if (drives > 10) {
  14.             driveCost -= driveCost * .1;
  15.         }
  16.        
  17.         else if (drives > 5) {
  18.             driveCost -= driveCost * .05;          
  19.         }
  20.        
  21.         double softwareCost = Math.max(0, software * 25 - phones * 10);
  22.        
  23.         double phoneCost = 399 * phones;
  24.        
  25.         double penCost = 0;
  26.        
  27.         if (pens == 1) {
  28.             penCost = 500 * 1;
  29.         }
  30.        
  31.         else if (pens == 2) {
  32.             penCost = 450 * 2;
  33.         }
  34.        
  35.         else if (pens == 3) {
  36.             penCost = 400 * 3;
  37.         }
  38.        
  39.         else if (pens == 4) {
  40.             penCost = 350 * 4;
  41.         }
  42.        
  43.         else if (pens >= 5) {
  44.             penCost = 300 * pens;
  45.         }
  46.        
  47.         return (driveCost + softwareCost + phoneCost + penCost) * 1.06;
  48.     }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement