/
conann
/
hash
Обзор
Документация
Войти
/
conann
/
hash
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
Main.java
47 строк
2 KB
Kirill Opra
upload files
18 апр 2025, 15:36
18 апр 2025, 15:36
f892e2c
Код
Авторство
О чём код?
import java.util.*; public class Main { public static void main(String[] args) { Map <Address, Integer> costPerAddress = new HashMap<>(); costPerAddress.put(new Address("Россия", "Москва"), 12500); costPerAddress.put(new Address("Россия", "Санкт-Петербург"), 10500); costPerAddress.put(new Address("Швеция", "Стокгольм"), 15000); costPerAddress.put(new Address("Ирландия", "Дублин"), 17500); costPerAddress.put(new Address("Франция", "Париж"), 8500); costPerAddress.put(new Address("Италия", "Рим"), 5000); costPerAddress.put(new Address("Англия", "Лондон"), 7500); Scanner scanner = new Scanner(System.in); int totalCost = 0; Set<String> countries = new HashSet<>(); while (true) { System.out.println("\nЗаполнение нового заказа! \n"); System.out.print("Введите страну или 'end' для завершения заполнения заказа: "); String country = scanner.nextLine(); if ("end".equals(country)) { break; } System.out.print("Введите город: "); String city = scanner.nextLine(); System.out.print("Введите вес (кг): "); int weight = Integer.parseInt(scanner.nextLine()); Address address = new Address(country, city); if (costPerAddress.containsKey(address)) { int price = weight * costPerAddress.get(address); totalCost += price; countries.add(country); System.out.println("\nСтоимость доставки: " + price + " руб."); System.out.println("Общая стоимость всех доставок: " + totalCost + " руб."); System.out.println("Колличество стран: " + countries.size()); }else { System.out.println("Доставка в указанный город не доступна!"); } } System.out.println("Заказы успешно отправлены!"); } }