/
AleksejRo
/
9t.
Обзор
Документация
Войти
/
AleksejRo
/
9t.
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
Main.java
55 строк
2 KB
AleksejRo
upload files
08 авг 2025, 23:05
08 авг 2025, 23:05
5ea5851
Код
Авторство
О чём код?
//Далее в цикле пользователь вводит заказы (или end). Каждый заказ состоит из трёх частей: страны, города и веса в кг доставляемого товара. В ответ нужно написать, что такой адрес не обслуживается, или написать стоимость доставки и общую сумму всех сделанных доставок. import java.util.*; public class Main { public static void main(String[] args) { Map<Address, Integer> costPerAddress = new HashMap<>(); Address address1 = new Address("Russia", "Saint-Petersburg"); costPerAddress.put(address1, 5); Address address2 = new Address("Russia", "Moscow"); costPerAddress.put(address2, 7); Address address3 = new Address("Russia", "Orel"); costPerAddress.put(address3, 3); Address address4 = new Address("Russia", "Tver"); costPerAddress.put(address4, 4); int costForAllDelivery = 0; Scanner scanner = new Scanner(System.in); List<String> listc = new ArrayList<>(); while (true) { System.out.println("Enter your country or 'end'."); String countryByUser = scanner.nextLine(); if (countryByUser.equals("end")) { break; } if (!listc.contains(countryByUser)) { listc.add(countryByUser); } System.out.println("Enter your city."); String cityByUser = scanner.nextLine(); System.out.println("Enter the weight of your package."); int weightByUser = scanner.nextInt(); scanner.nextLine(); Address addressByUser = new Address(countryByUser, cityByUser); if (costPerAddress.containsKey(addressByUser)) { int cost = costPerAddress.get(addressByUser) * weightByUser; costForAllDelivery += cost; System.out.println("The shipping cost: " + cost + "\n" + "The shipping cost for all orders: " + costForAllDelivery + "\n" + "The number og unique countries: " + listc.size()); } else { System.out.println("There ia no such address for delivery."); } } } }