0Pricing
Java Academy · Lesson

Mini Project: Console Calculator

Build a small calculator function using switch without console input. Handle +, -, *, /, validate division by zero, and design clean tests.

Project Brief

Goal: Implement a reusable calculator method without console input. The method takes two numbers and an operator, returns the result, and validates division by zero.

API Design

API

static double calc(double a, double b, char op)
  • op: '+', '-', '*'/'x', '/'
  • Invalid operator: throw IllegalArgumentException
  • No user input inside the method

All lessons in this course

  1. Comparison & Logical Operators Deep Dive
  2. Switch Statements
  3. Mini Project: Console Calculator
← Back to Java Academy