/
Letta21
/
HashMap
Обзор
Документация
Войти
/
Letta21
/
HashMap
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
MainAdr.java
47 строк
2 KB
Letta21
update MainAdr.java
03 ноя 2025, 18:29
03 ноя 2025, 18:29
faeeae6
Код
Авторство
О чём код?
import java.util.*; public class MainAdr { public static void main(String[] args) { int sum = 0; Map<Adress, Integer> costPerAddress = new HashMap<>(); Set<String> uniqueCountries = new HashSet<>(); costPerAddress.put(new Adress("Russia", "Moscow"), 200); costPerAddress.put(new Adress("Russia", "Tver"), 100); costPerAddress.put(new Adress("Germany", "Berlin"), 500); costPerAddress.put(new Adress("France", "Paris"), 400); Scanner sc = new Scanner(System.in); while (true) { System.out.println("Заполнение нового заказа."); System.out.print("Введите страну или введите end: "); String country = sc.nextLine(); if (country.equals("end")) { break; } System.out.print("Введите город: "); String city = sc.nextLine(); System.out.print("Введите вес (кг): "); String weight = sc.nextLine(); boolean check = false; Adress orderAdress = new Adress(country, city); if (costPerAddress.containsKey(orderAdress)) { int costPerKg = costPerAddress.get(orderAdress); double weighT = Double.parseDouble(weight); uniqueCountries.add(country); System.out.println("Стоимость доставки составит: " + ((int) (weighT * costPerKg)) + " руб."); sum = sum + (int) (weighT * costPerKg); System.out.println("Общая стоимость всех доставок: " + sum + " руб."); System.out.println("Количество уникальных стран: " + uniqueCountries.size()); check = true; } if (!check) { System.out.println("Доставки по этому адресу нет"); } } } }