수집집계

2026년 2월 20일 10:01분

package com.jesusbornd.exodus;

import java.util.ArrayList;
import java.util.List;

public class Exodus_35_Chapter_Lv3 {

    public static class ContributionBox {
        private final List<Integer> amounts = new ArrayList<Integer>();

        public void give(int amount) {
            if (amount > 0) amounts.add(amount);
        }

        public int total() {
            int sum = 0;
            for (int i = 0; i < amounts.size(); i++) sum += amounts.get(i);
            return sum;
        }

        public int count() {
            return amounts.size();
        }
    }

    public static void main(String[] args) {
        ContributionBox box = new ContributionBox();

        box.give(5);
        box.give(10);
        box.give(20);

        System.out.println(box.count());
        System.out.println(box.total());
    }
}

class ContributionBox:
    def __init__(self):
        self.amounts = []

    def give(self, amount: int):
        if amount > 0:
            self.amounts.append(amount)

    def total(self) -> int:
        s = 0
        for a in self.amounts:
            s += a
        return s

    def count(self) -> int:
        return len(self.amounts)

box = ContributionBox()

box.give(5)
box.give(10)
box.give(20)

print(box.count())
print(box.total())

Comments

Avatar
 2026년 2월 20일 10:11분

“하나님 일은 ‘한 번의 큰 액션’보다 ‘작은 드림들이 쌓이는 과정’으로 완성된다.”



Search

← 목록으로