Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
1.7 kB
1
Indexable
Never
import java.util.*;

public class DataQueryProgram {
    private HashMap<String, DataEntry> dataMap;

    public DataQueryProgram() {
        dataMap = new HashMap<>();
    }

    public void addDataEntry(DataEntry entry) {
        dataMap.put(entry.getName(), entry);
    }

    public List<DataEntry> queryData(String query) {
        List<DataEntry> results = new ArrayList<>();

        for (DataEntry entry : dataMap.values()) {
            if (entry.getName().equalsIgnoreCase(query) ||
                entry.getBirthday().equalsIgnoreCase(query) ||
                entry.getNumber().equalsIgnoreCase(query) ||
                entry.getMemo().equalsIgnoreCase(query)) {
                results.add(entry);
            }
        }

        return results;
    }

    public static void main(String[] args) {
        DataQueryProgram program = new DataQueryProgram();

        // Sample data entries
        DataEntry entry1 = new DataEntry("John", "1990-05-15", "1234567890", "Friend");
        DataEntry entry2 = new DataEntry("Alice", "1985-12-20", "9876543210", "Colleague");

        // Adding data to the program
        program.addDataEntry(entry1);
        program.addDataEntry(entry2);

        // Querying data
        String query = "1234567890";
        List<DataEntry> queryResults = program.queryData(query);

        // Displaying query results
        if (queryResults.isEmpty()) {
            System.out.println("No matching entries found.");
        } else {
            System.out.println("Matching entries found:");
            for (DataEntry result : queryResults) {
                System.out.println(result);
            }
        }
    }
}