Софтуерно Инженерство
Loading...
+ Нов въпрос
dimitarg92 avatar dimitarg92 0 Точки

Mалко помощ за задачата "Alcohol Market"

import java.util.Scanner;
public class AlcoholMarket {
    public static void main(String[] args){
        Scanner scanner = new Scanner(System.in);
        double whiskeyPriceInBGN = Double.parseDouble(scanner.nextLine());
        double litersOfBeer = Double.parseDouble(scanner.nextLine());
        double litersOfWine = Double.parseDouble(scanner.nextLine());
        double litersOfBrandies = Double.parseDouble(scanner.nextLine());
        double litersOfWhiskey = Double.parseDouble(scanner.nextLine());

        double priceForBrandies = litersOfBrandies * 25;
        double priceOfWine = priceForBrandies - (0.4 * priceForBrandies);
        double priceOfBeer = priceForBrandies - (0.8 * priceForBrandies);
        double amountForBrandies = litersOfBrandies * 25;
        double amountOfWine = litersOfWine * priceOfWine;
        double amountForBeer = litersOfBeer * priceOfBeer;
        double amountForWhiskey = litersOfWhiskey * whiskeyPriceInBGN;

        double total = amountForBrandies + amountOfWine + amountForBeer + amountForWhiskey;
        System.out.printf("%.2f", total);








    }
}
Тагове:
mark79 avatar mark79 347 Точки

Здравей,

малко дребни грешки са преобърнали нещата. Може да ги разгледаш в коригирания ти код

        double priceForBrandies = whiskeyPriceInBGN / 2;
        double priceOfWine = priceForBrandies - (0.4 * priceForBrandies);
        double priceOfBeer = priceForBrandies - (0.8 * priceForBrandies);
        double amountForBrandies = litersOfBrandies * priceForBrandies;
        double amountOfWine = litersOfWine * priceOfWine;
        double amountForBeer = litersOfBeer * priceOfBeer;
        double amountForWhiskey = litersOfWhiskey * whiskeyPriceInBGN;

Поздрави :)

0
11/09/2019 09:40:21
ivano_ar avatar ivano_ar 0 Точки

1.zadacha

2.zadacha

3.osnova

0
radoslav.venchev avatar radoslav.venchev 2 Точки
import java.util.Scanner;

public class Alchohol {
    public static void main(String[] args) {

        /* The price of rakia is 50% from the whiskey's price.
           The wine is 40% of the rakia's price.
           The beer is 80% of the rakia's price.
         */

        // Getting the input data
        Scanner scanner = new Scanner(System.in);
        double whiskey_price = Double.parseDouble(scanner.nextLine());
        double beer_litres = Double.parseDouble(scanner.nextLine());
        double wine_litres = Double.parseDouble(scanner.nextLine());
        double rakia_litres = Double.parseDouble(scanner.nextLine());
        double whiskey_litres = Double.parseDouble(scanner.nextLine());

        // Calculating the prices per one litre.
        double rakia_price = whiskey_price / 2;
        double wine_price = rakia_price - (rakia_price * 0.4);
        double beer_price = rakia_price - (rakia_price * 0.8);

        //Calculating the sums
        double rakia_sum = rakia_litres * rakia_price;
        double wine_sum = wine_litres * wine_price;
        double beer_sum = beer_litres * beer_price;
        double whiskey_sum = whiskey_price * whiskey_litres;
        double end_sum = rakia_sum + wine_sum + beer_sum + whiskey_sum;

        //Output the result
        System.out.printf("%.2f", end_sum);

    }
}

0