/
aizner
/
hash
Обзор
Документация
Войти
/
aizner
/
hash
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
Main.java
70 строк
3 KB
aizner
Main.java
26 янв 2026, 19:36
Верифицирован
26 янв 2026, 19:36
dd758a7
Код
Авторство
О чём код?
import java.util.HashMap; import java.util.HashSet; import java.util.Map; import java.util.Scanner; import java.util.Set; public class Main { public static void main(String[] args) { Map<Address, Integer> costPerAddress = new HashMap<>(); costPerAddress.put(new Address("Россия", "Москва"), 250); costPerAddress.put(new Address("Россия", "Казань"), 200); costPerAddress.put(new Address("США", "Нью-Йорк"), 600); costPerAddress.put(new Address("Франция", "Париж"), 500); costPerAddress.put(new Address("Япония", "Токио"), 700); Scanner sc = new Scanner(System.in); int totalSum = 0; Set<String> uniqueCountries = new HashSet<>(); while (true) { System.out.println("Заполнение нового заказа."); System.out.print("Введите страну (или end): "); String country = sc.nextLine().trim(); if (country.equalsIgnoreCase("end")) { System.out.println("Работа завершена."); break; } System.out.print("Введите город: "); String city = sc.nextLine().trim(); System.out.print("Введите вес (кг): "); String weightStr = sc.nextLine().trim(); int weight; try { weight = Integer.parseInt(weightStr); if (weight <= 0) { System.out.println("Вес должен быть положительным числом!\n"); continue; } } catch (NumberFormatException e) { System.out.println("Некорректный вес!\n"); continue; } Address address = new Address(country, city); Integer pricePerKg = costPerAddress.get(address); if (pricePerKg == null) { System.out.println("Доставки по этому адресу нет\n"); continue; } int orderCost = pricePerKg * weight; totalSum += orderCost; uniqueCountries.add(country); System.out.println("Стоимость доставки составит: " + orderCost + " руб."); System.out.println("Общая стоимость всех доставок: " + totalSum + " руб."); System.out.println("Доставки оформлены в уникальные страны: " + uniqueCountries.size()); System.out.println(); } sc.close(); } }