/
on-line-javalex
/
HashSet
Обзор
Документация
Войти
/
on-line-javalex
/
HashSet
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
Value.java
57 строк
2 KB
on-line-javalex
update Value.java
06 дек 2025, 21:18
06 дек 2025, 21:18
f05818c
Код
Авторство
О чём код?
import java.io.IOException; import java.util.*; public class Value { public static void main(String[] args) throws IOException { Map<Address, Integer> costPerAddress = new HashMap<>(); costPerAddress.put(new Address("Россия", "Москва"), 69); costPerAddress.put(new Address("Россия", "Москва"), 69); costPerAddress.put(new Address("РБ", "Орша"), 139); costPerAddress.put(new Address("Россия", "Тверь"), 102); costPerAddress.put(new Address("Израиль", "Тель-Авиф"), 399); Scanner scanner = new Scanner(System.in); int general = 0; Set<String> countries = new HashSet<>(); while (true) { System.out.print("Заполнение нового заказа.\n" + "Введите страну: "); 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 = 0; try { weight = Integer.parseInt(scanner.nextLine()); } catch (NumberFormatException r){ System.out.println("Ошибка! Надо ввести вес в кг."); } Address address = new Address(country, city); if (costPerAddress.containsKey(address)) { int price = costPerAddress.get(address) * weight; general += price; countries.add(country); System.out.printf("Стоимость доставки составит: %d руб.\n", price); System.out.printf("Общая стоимость всех доставок: %d \n", general); System.out.printf("Количество посещенных стран: %d \n", countries.size()); } else { System.out.println("Сюда доставки нет!"); } } } }