Project BE2 — Android App: Calculator or Converter
S7 Inf A3 — Java for Graphical and Mobile Programming
Stéphane Derrode — Centrale Lyon
Part 3 — Android
Prerequisite: TD6 (Android Studio setup + first Activity) and TD7 (RecyclerView + navigation).
Duration: 2h autonomous session + personal work.
Submission: Moodle — zip of the Android project + PDF report (see Section 5).
1. Choose Your Project
Pick the subject that interests you most. Both use the same Android skills from CM6–8.
Option A — Calculator
Build a four-operation calculator for the Android platform.
Minimum requirements:
- A display showing the current input and result
- Digit buttons 0–9 and a decimal point
- Operator buttons + − × ÷
- An = button that computes and displays the result
- A C button that clears the current input
- Division by zero is handled gracefully (show "Error")
- The last result is saved with SharedPreferences and restored on next launch
Suggested layout:
┌─────────────────────────────┐
│ 0 │ ← result display (large TextView)
│ 0 + 0 │ ← expression display (small TextView)
├──────┬──────┬──────┬────────┤
│ C │ ← │ % │ ÷ │
├──────┼──────┼──────┼────────┤
│ 7 │ 8 │ 9 │ × │
├──────┼──────┼──────┼────────┤
│ 4 │ 5 │ 6 │ − │
├──────┼──────┼──────┼────────┤
│ 1 │ 2 │ 3 │ + │
├──────┼──────┴──────┼────────┤
│ +/− │ 0 │ = │
└──────┴─────────────┴────────┘
Suggested implementation approach:
Use a state machine with three variables:
private double operand1 = 0;
private String operator = ""; // "+", "-", "×", "÷"
private boolean newNumber = true;
Each digit button appends to the display. Each operator button stores operand1 and operator. The = button computes the result.
Option B — Currency Converter
Build a currency converter that converts between at least 4 currencies.
Minimum requirements:
- An EditText for the amount to convert
- A Spinner (drop-down) to select the source currency
- A Spinner to select the target currency
- A Convert button that displays the result
- At least 4 currencies: EUR, USD, GBP, JPY (or your choice)
- Exchange rates are hardcoded (no internet required)
- The last conversion (amount + currencies) is saved with SharedPreferences and restored on next launch
- Invalid input (empty, non-numeric) is handled with a Toast or Snackbar
Suggested layout:
┌─────────────────────────────┐
│ Currency Converter │
├─────────────────────────────┤
│ Amount: [ ] │
│ From: [ EUR ▼ ] │
│ To: [ USD ▼ ] │
│ │
│ [ Convert ] │
│ │
│ Result: 1 EUR = 1.08 USD │
│ 100 EUR = 108 USD │
└─────────────────────────────┘
2. Architecture Requirements
Whichever option you choose, your app must:
- Be built with Java and Android SDK API 26+, targeting API 33
- Use at least one custom layout designed in XML
- Handle button clicks with
setOnClickListener(lambda) - Persist at least one value across sessions with
SharedPreferences - Handle at least one error case (empty input, division by zero, etc.) with Toast or Snackbar
- Run correctly on the Pixel 6a API 33 emulator
3. Advanced Ideas (optional — appreciated)
These ideas are not required but will be noted positively:
For both projects:
- Dark mode support (use ?attr/ color references in your theme)
- Landscape layout variant in res/layout-land/
- Multi-language support (values-fr/strings.xml + values-en/strings.xml)
- Custom app icon designed in Android Studio's Image Asset wizard
- History screen: a second Activity showing previous calculations/conversions using RecyclerView
Calculator extras: - Backspace button to delete the last digit - Percentage button (x % of y) - Memory buttons (M+, M−, MR, MC) - Scientific functions (√, x², 1/x) in a second layout or scrollable panel
Converter extras: - Swap button to invert source and target currencies instantly - More conversion categories: temperature (°C/°F/K), distance (km/mi/m), weight (kg/lb/oz) - Live exchange rates from a public API (advanced — requires network permission and Retrofit)
4. Minimum Requirements Checklist
To obtain a passing grade, all of the following must work on the emulator:
Calculator: - [ ] Display shows digits as they are typed - [ ] Addition, subtraction, multiplication and division all produce correct results - [ ] Division by zero shows an error (no crash) - [ ] C button clears the display - [ ] Last result is restored on app restart
Converter: - [ ] Amount can be entered in the EditText - [ ] Both Spinners show at least 4 currencies - [ ] Convert button shows a correct result - [ ] Invalid input (empty/non-numeric) is handled gracefully - [ ] Last conversion settings are restored on app restart
5. Deliverable
Submit on Moodle before the deadline a single zip containing:
- The complete Android Studio project (all source files)
- A PDF report (1–2 pages) including:
- A screenshot of your running app on the emulator
- Your layout XML structure (a diagram or the XML itself)
- A brief description of your implementation choices and any difficulties encountered
- If you implemented advanced features, describe them
Zip naming: BE2_NomPrenom1_NomPrenom2.zip
Tips
- Start with the layout — get the UI right before writing any logic.
- For the calculator: implement one operator at a time and test thoroughly before adding the next.
- For the converter: define your exchange rates as constants at the top of the Activity — easy to update later.
- Use
Log.d(TAG, ...)liberally during development — Logcat is your best friend. - Test edge cases: what happens if the user taps
=twice? What if the first digit is the operator?