Results 1 to 3 of 3
Thread: Did I compile this wrong?
- 04-17-2011, 06:11 PM #1
Member
- Join Date
- Apr 2011
- Posts
- 1
- Rep Power
- 0
Did I compile this wrong?
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:Java 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.javaJava 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 } }
"javac Progression.java" compiles fine but "javac ArtihProgression.java" spits out the following problems:Java 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?
- 04-17-2011, 06:18 PM #2
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,413
- Blog Entries
- 7
- Rep Power
- 17
When people rob a bank they get a penalty; when banks rob people they get a bonus.
-
Similar Threads
-
would this compile?
By stringkilla in forum New To JavaReplies: 10Last Post: 10-24-2010, 03:27 PM -
Can't Compile
By sidk47 in forum JavaServer Pages (JSP) and JSTLReplies: 7Last Post: 06-15-2010, 04:43 PM -
Wrong output (well.. the one who's wrong is probably me ;) )
By shacht1 in forum New To JavaReplies: 2Last Post: 11-22-2009, 03:48 PM -
doesn't compile?!
By jon80 in forum New To JavaReplies: 8Last Post: 06-14-2008, 05:42 PM -
Not able to compile
By bugger in forum New To JavaReplies: 2Last Post: 01-09-2008, 10:13 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks