Fraction game code in java

Asked By 60 points N/A Posted on -
qa-featured

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:
prog.java:1: error: ‘package’ does not name a type
prog.java:3: error: expected unqualified-id before ‘public’
SHARE
Answered By 0 points N/A #137207

Fraction game code in java

qa-featured

Since you are starting to learn Java programming, I would recommend you to use NetBeans (https://netbeans.org/downloads/index.html). 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 Fraction.java 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.

Related Questions