Я пытаюсь установить базовую цену предмета на 3 доллара, но это мешает остальной части моей математики (java) - PullRequest
0 голосов
/ 27 февраля 2020

Так что сейчас все работает нормально, пока объем элемента (p1v и p2v) больше 1, но я не могу найти способ для консоли вывести базовую цену в 3 доллара, если объем меньше чем 1. Для справки: стоимость предмета начинается с 3 долларов за первую единицу объема или его части, а затем увеличивается на 1 доллар за каждую дополнительную единицу.

public void calculateCost() {

        NumberFormat currency = NumberFormat.getCurrencyInstance();

        if (p1v < 1) {
            double cost = 3;
            System.out.printf("%nPackage 1 will cost " + currency.format(cost) + " to ship.");
        }

        if (p2v < 1) {
            double cost2 = 3;
            System.out.printf("%nPackage 1 will cost " + currency.format(cost2) + " to ship.");
        }

        if (p1v < 1 && p2v < 1) {

        double cost = 3 + p1v - 1;
        String message = "Package 1 will cost " + currency.format(cost) + " to ship.";
        System.out.printf("%n" + message);

        double cost2 = 3 + p2v - 1;
        String message2 = "Package 2 will cost " + currency.format(cost2) + " to ship.";
        System.out.printf("%n" + message2);

        if (cost >= 5 * cost2) {
            System.out.printf("%nThe first package is " + cost / cost2 + "times the cost of the second package.");
        } else if (cost2 >= 5 * cost) {
            System.out.printf("%nThe second package is " + cost2 / cost + "times the cost of the first package.");
        } else if (cost == cost2) {
            System.out.printf("%nThe first package is the same cost as the second package.");
        } else if (cost < 5 * cost2 && cost >= 4 * cost2) {
            System.out.printf("%nThe first package is quadruple the cost of the second package.");
        } else if (cost2 < 5 * cost && cost2 >= 4 * cost) {
            System.out.printf("%nThe second package is quadruple more than the cost of the first package.");
        } else if (cost < 4 * cost2 && cost >= 3 * cost2) {
            System.out.printf("%nThe first package is triple the cost of the first package.");
        } else if (cost2 < 4 * cost && cost2 >= 3 * cost) {
            System.out.printf("%nThe second package is triple the cost of the second package.");
        } else if (cost < 3 * cost2 && cost >= 2 * cost2) {
            System.out.printf("%nThe first package is twice the cost of the first package.");
        } else if (cost2 < 3 * cost && cost2 >= 2 * cost) {
            System.out.printf("%nThe second package is twice the cost of the second package.");
        } else if (cost < 2 * cost2) {
            System.out.printf("%nThe second package is slightly more than the cost of the first package.");
        } else if (cost2 < 2 * cost) {
            System.out.printf("%nThe first package is slightly more than the cost of the second package.");
        }

    }

}
...