/
shuchkin
/
NETOLOGY-HW_HASH
Обзор
Документация
Войти
/
shuchkin
/
NETOLOGY-HW_HASH
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
src/Main.java
39 строк
2 KB
Sergey Shuchkin
0.1
20 дек 2025, 14:00
20 дек 2025, 14:00
1a07012
Код
Авторство
О чём код?
import java.util.*; public class Main { public static void main(String[] args) { HashMap<Address, Integer> costPerAddress = new HashMap<>(); costPerAddress.put(new Address("Россия", "Москва"), 1000); costPerAddress.put(new Address("Россия", "Казань"), 800); costPerAddress.put(new Address("Казахстан", "Астана"), 1500); costPerAddress.put(new Address("Китай", "Пекин"), 100); System.out.println(costPerAddress); ShippingList shippingList = new ShippingList(); Scanner scanner = new Scanner(System.in); while (true) { System.out.print("Заполнение нового заказа.\nВведите страну (или 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 cost = costPerAddress.get(address); Shipping shipping = new Shipping(address, cost, weight); shippingList.add(shipping); System.out.printf("Стоимость доставки составит: %d руб.%n", shipping.getTotal()); System.out.printf("Общая стоимость всех доставок: %d руб.%n", shippingList.getTotal()); } else { System.out.println("Доставки по этому адресу нет"); } } System.out.println("Доставка в страны: " + shippingList.getUniqCountries()); } }