← Unit 3 · all exercises
Saved in this browser only

A fraction

Write a Fraction with a numerator and a denominator. toDouble returns the value as a decimal, and show returns it as text like "3/4".

class Fraction { Fraction(int n, int d); double toDouble(); String show(); }

Fraction.java
Loading editor…
Results

Examples

  • new Fraction(3, 4).show() → 3/4
  • new Fraction(1, 2).toDouble() → 0.5

There are also 3 hidden tests you can't see. Solve the problem, not the examples.