I was able to compile some code fine on ideone.com with only one import statement but when I try to compile the files on my local computer I get some errors. I'm not sure if I'm doing something wrong.
Here is some more info:
I copy and pasted the following two classes into the ideone.com web-based compiler and I didn't run into any problems upon compiling:
However after I pasted the code into two java files on my local computer and tried to compile them:Code:/**************************************** *****************************************/ /** * A class for numeric progressions. */ import java.math.BigInteger; // public class Progression { CHANGED IN ORDER TO COMPILE ON IDEONE.COM class Progression { /** First value of the progression. */ protected BigInteger first; /** Current value of the progression. */ protected BigInteger cur; /** Default constructor. */ Progression() { cur = first = BigInteger.ZERO; } /** Resets the progression to the first value. * * @return first value */ protected BigInteger firstValue() { cur = first; return cur; } /** Advances the progression to the next value. * * @return next value of the progression */ protected BigInteger nextValue() { cur = cur.add(BigInteger.ONE); return cur; // default next value } /** Prints the first n values of the progression. * * @param n number of values to print */ public void printProgression(int n) { System.out.print(firstValue()); for (int i = 2; i <= n; i++) System.out.print(" " + nextValue()); System.out.println(); // ends the line } } /**************************************** *****************************************/ /** * Arithmetic progression. */ class ArithProgression extends Progression { /** Increment. */ protected BigInteger inc; // Inherits variables first and cur. /** Default constructor setting a unit increment. */ ArithProgression() { this(BigInteger.ONE); } /** Parametric constructor providing the increment. */ ArithProgression(BigInteger increment) { inc = increment; } /** Advances the progression by adding the increment to the current value. * * @return next value of the progression */ protected BigInteger nextValue() { cur = cur.add(inc); return cur; } // Inherits methods firstValue() and printProgression(int). }
Progression.java
ArithProgression.javaCode:/** * A class for numeric progressions. */ import java.math.BigInteger; // public class Progression { CHANGED IN ORDER TO COMPILE ON IDEONE.COM class Progression { /** First value of the progression. */ protected BigInteger first; /** Current value of the progression. */ protected BigInteger cur; /** Default constructor. */ Progression() { cur = first = BigInteger.ZERO; } /** Resets the progression to the first value. * * @return first value */ protected BigInteger firstValue() { cur = first; return cur; } /** Advances the progression to the next value. * * @return next value of the progression */ protected BigInteger nextValue() { cur = cur.add(BigInteger.ONE); return cur; // default next value } /** Prints the first n values of the progression. * * @param n number of values to print */ public void printProgression(int n) { System.out.print(firstValue()); for (int i = 2; i <= n; i++) System.out.print(" " + nextValue()); System.out.println(); // ends the line } }
"javac Progression.java" compiles fine but "javac ArtihProgression.java" spits out the following problems:Code:/** * Arithmetic progression. */ class ArithProgression extends Progression { /** Increment. */ protected BigInteger inc; // Inherits variables first and cur. /** Default constructor setting a unit increment. */ ArithProgression() { this(BigInteger.ONE); } /** Parametric constructor providing the increment. */ ArithProgression(BigInteger increment) { inc = increment; } /** Advances the progression by adding the increment to the current value. * * @return next value of the progression */ protected BigInteger nextValue() { cur = cur.add(inc); return cur; } // Inherits methods firstValue() and printProgression(int). }
ArithProgression.java:13: cannot find symbol
symbol : class BigInteger
location: class ArithProgression
protected BigInteger inc;
^
ArithProgression.java:23: cannot find symbol
symbol : class BigInteger
location: class ArithProgression
ArithProgression(BigInteger increment) {
^
ArithProgression.java:31: cannot find symbol
symbol : class BigInteger
location: class ArithProgression
protected BigInteger nextValue() {
^
ArithProgression.java:19: cannot find symbol
symbol : variable BigInteger
location: class ArithProgression
this(BigInteger.ONE);
^
4 errors
Am I compiling this wrong or do I have to put "import java.math.BigInteger;" into every file that extends "Progression.java" as well?


Reply With Quote

Bookmarks