BaşlayınÜcretsiz başlayın

Detecting missing strings

The sales data for your coffee shop may contain data entry errors like empty fields or whitespaces. Check the sample sale for these errors, and print messages to display a default value or to indicate the issue.

The necessary packages such as Objects, and StringUtils have been imported for you.

Bu egzersiz, kursun bir parçasıdır

Cleaning Data in Java

Kursa Göz Atın

Egzersiz talimatları

  • Return coffeeName with a default name if null.
  • Check if paymentMethod is empty or whitespace.

Uygulamalı etkileşimli egzersiz

Bu egzersizi bu örnek kodu tamamlayarak deneyin.

public class CoffeeSalesExample {
    private record CoffeeSales(LocalDate date, String coffeeName,
            String paymentMethod, Integer quantity, Double amount) {
    }

    public static void main(String[] args) {
		CoffeeSales sale = new CoffeeSales(LocalDate.of(2024, 3, 1), null, " ", 1, 6.26);

		// Return coffeeName with a default if null
		String coffeeName = ____.____(sale.coffeeName(), "[No coffee name]");
		System.out.println("coffeeName: " + coffeeName);

        // Check if paymentMethod is empty or whitespace
        if (____.____(sale.paymentMethod())) {
            System.out.println("Payment method cannot be empty or whitespace");
        }
    }
}
Kodu Düzenle ve Çalıştır