Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Problem1 {
- public static void main(String[] args) {
- System.out.println(getCost(1, 1, 1, 1)); // Should be 1021.787
- System.out.println(getCost(8, 3, 4, 5)); // Should be 3721.2572
- System.out.println(getCost(10, 3, 4, 8)); // Should be 4775.8565
- System.out.println(getCost(8, 2, 10, 10)); // Should be 7811.7972
- }
- public static double getCost(int drives, int software, int phones, int pens) {
- double driveCost = 49.95 * drives;
- if (drives > 10) {
- driveCost -= driveCost * .1;
- }
- else if (drives > 5) {
- driveCost -= driveCost * .05;
- }
- double softwareCost = Math.max(0, software * 25 - phones * 10);
- double phoneCost = 399 * phones;
- double penCost = 0;
- if (pens == 1) {
- penCost = 500 * 1;
- }
- else if (pens == 2) {
- penCost = 450 * 2;
- }
- else if (pens == 3) {
- penCost = 400 * 3;
- }
- else if (pens == 4) {
- penCost = 350 * 4;
- }
- else if (pens >= 5) {
- penCost = 300 * pens;
- }
- return (driveCost + softwareCost + phoneCost + penCost) * 1.06;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement