/
SamMih
/
HOMEWORK11_HashSet_HashMap
Обзор
Документация
Войти
/
SamMih
/
HOMEWORK11_HashSet_HashMap
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
Main.java
61 строка
3 KB
SamMih
HOMEWORK11_HashSet_HashMap
21 июл 2025, 12:17
21 июл 2025, 12:17
26f7553
Код
Авторство
О чём код?
import java.util.*; public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); Map<Address, Integer> costPerAddress = new HashMap<>(); Set<String> uniqueCountries = new HashSet<>(); Address address1 = new Address("Japan", "Tokyo"); Address address2 = new Address("Russia", "Moscow"); Address address3 = new Address("USA", "New-York"); Address address4 = new Address("Belarus", "Minsk"); Address address5 = new Address("Russia", "Saint-Petersburg"); Address address6 = new Address("Russia", "Kazan"); costPerAddress.put(address1, 5000); costPerAddress.put(address2, 1000); costPerAddress.put(address3, 6000); costPerAddress.put(address4, 1500); costPerAddress.put(address5, 1200); costPerAddress.put(address6, 1300); int totalShippingCost = 0; while (true) { System.out.println("Заполнение нового заказа."); System.out.print("Введите страну: "); String inputCountry = scanner.nextLine(); if (inputCountry.equals("end")) { System.out.println("До новых встреч, пока!"); break; } System.out.print("Введите город: "); String inputCity = scanner.nextLine(); if (inputCity.equals("end")) { System.out.println("До новых встреч, пока!"); break; } System.out.print("Введите вес (кг): "); String in = scanner.nextLine(); if (in.equals("end")) { System.out.println("До новых встреч, пока!"); break; } int inputWeight = Integer.parseInt(in); Address newAddress = new Address(inputCountry, inputCity); uniqueCountries.add(inputCountry); if (costPerAddress.containsKey(newAddress)) { System.out.println("Стоимость доставки составит: " + (inputWeight * costPerAddress.get(newAddress)) + " руб."); totalShippingCost += (inputWeight * costPerAddress.get(newAddress)); System.out.println("Общая стоимость доставки составит: " + totalShippingCost + " руб."); System.out.println("Количество уникальных стран для доставки: " + uniqueCountries.size()); System.out.println(); } else { System.out.println("Такой адрес не обслуживается!"); System.out.println("Общая стоимость доставки составит: " + totalShippingCost + " руб."); System.out.println(); } } } }