/
Liza_S
/
HashMap_and_HashSet_collection
Обзор
Документация
Войти
/
Liza_S
/
HashMap_and_HashSet_collection
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
src/Main.java
55 строк
3 KB
Liza_S
upload files
24 июл 2025, 10:53
24 июл 2025, 10:53
b657e6c
Код
Авторство
О чём код?
import java.util.*; //TIP Для <b>запуска</b> кода нажмите <shortcut actionId="Run"/> или // щелкните значок <icon src="AllIcons.Actions.Execute"/> в боковой области. public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); Map<Address, Integer> costPerAddress = new HashMap<>(); Set<String> uniqueness = new HashSet<>(); int totalAmount = 0; costPerAddress.put(new Address("Moscow", "Russia"), 10500); costPerAddress.put(new Address("Peking", "China"), 8500); costPerAddress.put(new Address("Berlin", "Germany"), 7500); costPerAddress.put(new Address("London", "Great Britain"), 15500); costPerAddress.put(new Address("Rome", "Italy"), 12500); costPerAddress.put(new Address("Tokyo", "Japan"), 25500); costPerAddress.put(new Address("Ankara", "Turkey"), 5500); costPerAddress.put(new Address("Washington", "USA"), 50500); while (true){ System.out.println("Заполнение нового заказа.\n" + "Для выхода нажмите '0' "); System.out.println("Введите страну: "); String country = scanner.nextLine(); if (country.equals("0")){ System.out.println("Выход. До свидания!"); break; } System.out.println("Введите город: "); String city = scanner.nextLine(); System.out.println("Введите вес (кг): "); int weight = scanner.nextInt(); scanner.nextLine(); Address address = new Address(city, country); if (costPerAddress.containsKey(address)){ int price = costPerAddress.get(address); int shippingCost = price * weight; totalAmount += shippingCost; uniqueness.add(country); System.out.println("Стоимость доставки составит:" + shippingCost + "руб."); System.out.println("Общая стоимость всех доставок:" + totalAmount + "руб."); System.out.println("Количество уникальных стран доставки: " + uniqueness.size()); } else { System.out.println("Доставки по этому адресу нет"); } } scanner.close(); } }