Fraction game code in java

Asked By 60 points N/A Posted on -

I'm only starting to learn and code in Java programming language. I have conquered simple programming constructs like branching and looping constructs, but I am having troubles with coding a simple game with a Fraction class.

Here's what I've come up with so far:

package test;

public class Fraction {
    long denominator;
    long numerator
    public Fraction(long pnumerator, long pdenominator) {
        this.numerator = pnumerator;
        this.denominator = pdenominator;
    public long getNumerator() {
        return numerator;
    public long getDenominator() {
        return denominator;
Error I get: error: ‘package’ does not name a type error: expected unqualified-id before ‘public’
Answered By 0 points N/A #137207

Fraction game code in java


Since you are starting to learn Java programming, I would recommend you to use NetBeans ( Like Visual Studio, you can automatically complete your line of code with an array of options.

Here are the solutions to the two errors generated from your source code:

1. Place under a folder named test. This will solve the first error. The Java keyword “package” designates where the file’s class or classes will be compiled.

2. Place a semi-colon after you numerator (line 5). This will solve the second error.

Login/Register to Answer

Related Questions