/
lady
/
hashmap
Обзор
Документация
Войти
/
lady
/
hashmap
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
Main.java
57 строк
3 KB
lady
upload files
31 июл 2025, 14:25
31 июл 2025, 14:25
3e8f5d7
Код
Авторство
О чём код?
import java.util.*; public class Main { public static void main(String[] args) { Map<Address, Integer> costPerAddress = new HashMap<>(); costPerAddress.put(new Address("Россия","Москва"),150); costPerAddress.put(new Address("Россия","Астрахань"), 200); costPerAddress.put(new Address("Китай", "Пекин"),300); costPerAddress.put(new Address("Япония","Токио"),600); Scanner scanner = new Scanner(System.in); int cost = 0; Set<String> uniqueCountries = new HashSet<>(); System.out.println("Сервис доставки по миру"); System.out.println("Для завершения введите end"); while (true) { System.out.println("\nЗаполнение нового заказа:"); System.out.print("Введите страну: "); String countryInput = scanner.nextLine(); if ("end".equalsIgnoreCase(countryInput)) { System.out.println("Работа завершена."); break; } System.out.print("Введите город: "); String city = scanner.nextLine(); int weight; System.out.print("Введите вес (кг): "); String weightInput = scanner.nextLine(); weight = Integer.parseInt(weightInput); Address address = new Address(countryInput, city); String country = address.getCountry(); if (costPerAddress.containsKey(address)) { int costKg = costPerAddress.get(address); int totalCost = costKg * weight; cost += totalCost; uniqueCountries.add(country); System.out.printf("Стоимость доставки составит:" + totalCost + "руб."); System.out.printf("\nОбщая стоимость всех доставок:" + cost + "руб."); System.out.println("\nКоличество уникальных стран доставки: " + uniqueCountries.size()); } else { System.out.println("Доставки по этому адресу нет"); System.out.printf("\nОбщая стоимость всех доставок:" + cost + "руб."); System.out.println("\nКоличество уникальных стран доставки: " + uniqueCountries.size()); } } } }