edge lab LIVE! starts Tuesday in Munich. Grab a workshop seat and take home the board you build on. Code FRIEND-HACKSTER saves 20%. () Learn more!
Hardi Kurnianto
Published

[PantryPal] Smart Pantry Tracker Built with Modern Java

PantryPal tracks groceries, predicts expiry, and flags food to use first.

IntermediateFull instructions provided8 hours58
[PantryPal] Smart Pantry Tracker Built with Modern Java

Things used in this project

Hardware components

Webcam, Logitech® HD Pro
Webcam, Logitech® HD Pro
×1
Raspberry Pi 3 Model B
Raspberry Pi 3 Model B
×1

Software apps and online services

Java 26
Java 26

Story

Read more

Code

Main.java

Java
package com.pantrypal;

import com.pantrypal.model.Product;
import com.pantrypal.service.PantryService;
import com.pantrypal.service.ProductLookupService;
import com.pantrypal.web.DashboardServer;


public class Main {

    public static void main(String[] args) throws Exception {
        PantryService pantryService = new PantryService();
        ProductLookupService lookupService = new ProductLookupService();

        seedDemoData(pantryService, lookupService);

        int port = args.length > 0 ? Integer.parseInt(args[0]) : 8080;
        DashboardServer server = new DashboardServer(pantryService, lookupService, port);
        server.start();

        Runtime.getRuntime().addShutdownHook(new Thread(server::stop));
    }

    private static void seedDemoData(PantryService pantryService, ProductLookupService lookupService) {
        Product milk = lookupService.manualEntry("0001", "Susu UHT", "Dairy", 7);
        Product bread = lookupService.manualEntry("0002", "Roti Tawar", "Bakery", 4);
        Product cannedBeans = lookupService.manualEntry("0003", "Kacang Kaleng", "Canned", 365);

        pantryService.addItem(milk, 2);
        pantryService.addItem(bread, 1);
        pantryService.addItem(cannedBeans, 5);
    }
}

PanrtyPal

Credits

Hardi Kurnianto
24 projects • 20 followers
Master student at Intelligent Control and Systems Engineering Department

Comments