Loading...

Във форума е въведено ограничение, което позволява на потребителите единствено да разглеждат публикуваните въпроси.

PhoenixMaster123 avatar PhoenixMaster123 2 Точки

09. Padawan Equipment

Yoda is starting his newly created Jedi academy. So, he asked master John to buy the needed equipment. The
number of items depends on how many students will sign up. The equipment for each Padawan contains:
 Lightsaber
 Belt
 Robe
You will be given the amount of money John has, the number of students, and the prices of each item. Calculate
does John has enough money to buy equipment for each Padawan, or how much more money he needs.
There are some additional requirements:
 Lightsabres sometimes break, so John should buy 10% more (taken from the student's count), rounded up
to the next integer
 Every sixth belt is free
Input / Constraints
The input data should be read from the console. It will consist of exactly 5 lines:
 The amount of money John has – the floating-point number in the range [0.00…1,000.00]
 The count of students – integer in the range [0…100]
 The price of lightsabers for a single saber – the floating-point number in the range [0.00…100.00]
 The price of robes for a single robe – the floating-point number in the range [0.00…100.00]
 The price of belts for a single belt – the floating-point number in the range [0.00…100.00]
The input data will always be valid. There is no need to check it explicitly.
Output
The output should be printed on the console.
 If the calculated price of the equipment is less or equal to the money John has:
o "The money is enough - it would cost {the cost of the equipment}lv."
 If the calculated price of the equipment is more than the money John has:
o " John will need {neededMoney}lv more."
 All prices must be rounded to two digits after the decimal point.
Examples
Input Output Comments
100
2
1.0
2.0
3.0
The money is enough - it would cost
13.00lv.

Needed equipment for 2 padawans :
sabresPrice*(studentsCount + 10%) + robesPrice *
(studentsCount) + beltsPrice*(studentsCount-freeBelts)
1*(3) + 2*(2) + 3*(2) = 13.00
13.00 <= 100 – the money will be enough.

Input Output Comments
100
42
12.0
4.0
3.0
John will need 737.00lv more. Needed equipment for 42 padawans:
12*47 + 4*42 + 3*35 = 837.00
837 > 100 – need 737.00 lv. more.

https://pastebin.com/qgaDSwWV - Получавам 80/100, но не виждам грешката. Пробвах няколко различни варианта.

 

0
Fundamentals Module 16/01/2022 15:33:18
Axiomatik avatar Axiomatik 2422 Точки
            if (money <= amount)
            {
                Console.WriteLine($"The money is enough - it would cost {money:F2}lv.");
            }

money <= amount

;-)

1
krum_43 avatar krum_43 750 Точки

Ето още един вариант за решение 100/100.

https://pastebin.com/ZuSwFErd

1
ZdravkoSolakov avatar ZdravkoSolakov 5 Точки

Изпращам ти и Моето решение:

package Fundamentals_ExerciseBasic;

import java.util.Scanner;

public class P10PadawanEquipment {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        double amountMoney = Double.parseDouble(scanner.nextLine());
        int countStudents = Integer.parseInt(scanner.nextLine());
        double priceLightSabers = Double.parseDouble(scanner.nextLine());
        double priceRobes = Double.parseDouble(scanner.nextLine());
        double priceBelts = Double.parseDouble(scanner.nextLine());
        int freeBelts = countStudents / 6;

        double totalSum = (priceLightSabers * Math.ceil(countStudents  * 1.10)) + (priceRobes * (countStudents)) + (priceBelts *(countStudents - freeBelts ));
        
        if (amountMoney >= totalSum){
            System.out.printf("The money is enough - it would cost %.2flv.", totalSum);
        } else  {
            System.out.printf("George Lucas will need %.2flv more.", totalSum - amountMoney);
        }
    }
}
2
Можем ли да използваме бисквитки?
Ние използваме бисквитки и подобни технологии, за да предоставим нашите услуги. Можете да се съгласите с всички или част от тях.
Назад
Функционални
Използваме бисквитки и подобни технологии, за да предоставим нашите услуги. Използваме „сесийни“ бисквитки, за да Ви идентифицираме временно. Те се пазят само по време на активната употреба на услугите ни. След излизане от приложението, затваряне на браузъра или мобилното устройство, данните се трият. Използваме бисквитки, за да предоставим опцията „Запомни Ме“, която Ви позволява да използвате нашите услуги без да предоставяте потребителско име и парола. Допълнително е възможно да използваме бисквитки за да съхраняваме различни малки настройки, като избор на езика, позиции на менюта и персонализирано съдържание. Използваме бисквитки и за измерване на маркетинговите ни усилия.
Рекламни
Използваме бисквитки, за да измерваме маркетинг ефективността ни, броене на посещения, както и за проследяването дали дадено електронно писмо е било отворено.