/
Shcod
/
java-hw-HashMap_HashSet
Обзор
Документация
Войти
/
Shcod
/
java-hw-HashMap_HashSet
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
src/main/java/Main.java
53 строки
3 KB
Shcod
first commit
05 авг 2026, 08:08
05 авг 2026, 08:08
f39ce00
Код
Авторство
О чём код?
import java.util.*; public class Main { public static void main(String[] args) { Map<Address, Integer> costPerAddress = new HashMap<>(); costPerAddress.put(new Address("Россия", "Магнитогорск"), 1000); costPerAddress.put(new Address("Россия", "Москва"), 2000); costPerAddress.put(new Address("Россия", "Санкт-Петербург"), 500); costPerAddress.put(new Address("Казахстан", "Астана"), 10000); costPerAddress.put(new Address("Беларусь", "Минск"), 5000); Set<String> deliveryCount = new HashSet<>(); try (Scanner scanner = new Scanner(System.in)) { int totalCost = 0; while (true) { try { System.out.println("Заполнение нового заказа."); System.out.print("Введите страну: "); String country = scanner.nextLine(); if (country.equalsIgnoreCase("end")) { break; } System.out.print("Введите город: "); String city = scanner.nextLine(); if (city.equalsIgnoreCase("end")) { break; } System.out.print("Введите вес (кг): "); int weight = Integer.parseInt(scanner.nextLine()); Address address = new Address(country, city); if (costPerAddress.containsKey(address)) { int deliveryCost = weight * costPerAddress.get(address); totalCost += deliveryCost; deliveryCount.add(country); System.out.println("Стоимость доставки составит: " + deliveryCost + " руб."); } else { System.out.println("Доставки по этому адресу нет."); } System.out.println("Общая стоимость всех доставок: " + totalCost + " руб."); System.out.println(); } catch (NumberFormatException e) { System.out.println("Не верно введён вес товара, используйте число."); } } if (!deliveryCount.isEmpty()) { System.out.println("Страны куда осуществились доставки: "); for (String country : deliveryCount) { System.out.println(country); } } } } }