/
hel_bumer
/
HashMap
Обзор
Документация
Войти
/
hel_bumer
/
HashMap
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
Delivery.java
43 строки
2 KB
hel_bumer
HashMap
16 фев 2026, 13:45
Верифицирован
16 фев 2026, 13:45
6f60847
Код
Авторство
О чём код?
import java.util.*; public class Delivery { public static void main(String[] args) { Map<Address, Integer> costPerAddress = new HashMap<>(); costPerAddress.put(new Address("Россия", "Уфа"), 100); costPerAddress.put(new Address("Россия", "Омск"), 110); costPerAddress.put(new Address("Россия", "Тула"), 120); costPerAddress.put(new Address("Белорусь", "Минск"), 200); costPerAddress.put(new Address("Казахстан", "Астана"), 300); Scanner scanner = new Scanner(System.in); int total = 0; Set<String> countries = new HashSet<>(); while (true) { System.out.println("Заполнение нового заказа."); System.out.println("Введите страну"); String country = scanner.nextLine(); System.out.println("Введите город"); String city = scanner.nextLine(); if ("end".equals(country) || "end".equals(city)) { break; } System.out.println("Введите вес (кг)"); int weight = Integer.parseInt(scanner.nextLine()); Address address = new Address(country, city); if (costPerAddress.containsKey(address)) { int currentPrice = weight * costPerAddress.get(address); total += currentPrice; countries.add(country); System.out.printf("Стоимость доставки составит:%d руб.\n", currentPrice); System.out.printf("Общая стоимость всех доставок:%d руб.\n", total); System.out.printf("Кол-во посещенных стран %d \n", countries.size()); } else { System.out.println("Доставки по такому адресу нет"); } } } }