Ex2 App Development
Ex2 App Development
AIM:
To build a cross platform application for a simple expense manager which allows
entering expenses and income on each day and display category wise weekly income and
expenses.
PROCEDURE:
Step 1: Initialize state variables using `useState` for `transactions`, `amount`, `category`, and
`transactionType`.
Step 2: When the "Add Transaction" button is clicked.
Step 3: Check if both `amount` and `category` fields have values.
Step 4: If they do:
Step 5: Create a new transaction object with type, amount, category, and the current date.
Step 6: Add this transaction to the `transactions` array using `setTransactions`.
Step 7: Reset `amount` and `category` to empty strings.
Step 8: `calculateWeeklyReport` function.
Step 9: Iterate through `transactions`.
Step 10: Group transactions by category, summing their income and expenses separately.
Step 11: Construct an object containing categories with their respective income and expenses
for the week.
Step 12: Display input fields for `amount`, `category`, and a dropdown for `transactionType`.
Step 13: Allow users to input values for these fields.
Step 14: Provide an "Add Transaction" button to add transactions based on user input.
Step 15: Show a categorized list of income and expenses for the week, generated from
`calculateWeeklyReport`.
PROGRAM:
<br />
<label>
Category:
<input
type="text"
value={category}
onChange={(e) => setCategory(e.target.value)}
/>
</label>
<br />
<label>
Transaction Type:
<select
value={transactionType}
onChange={(e) => setTransactionType(e.target.value)}
>
<option value="Expense">Expense</option>
<option value="Income">Income</option>
</select>
</label>
<br />
<button onClick={addTransaction}>Add Transaction</button>
<div>
<h2>Weekly Report:</h2>
<ul>
{calculateWeeklyReport().map((item) => (
<li key={item.category}>
<h3>Category: {item.category}</h3>
<p>Income: {item.income}</p>
<p>Expense: {item.expense}</p>
</li>
))}
</ul>
</div>
</div>
);
};
function App() {
return (
<div className="App">
lOMoARcPSD|20362530
<ExpenseManager />
</div>
);
}
export default App;
OUTPUT:
Result:
The cross platform application for a income-expense displayer using react-native was
built successfully.