scripter73
Programmer
Hi,
I'm new to Java (somewhat), and I'm running on a Java 2 Platform. I wrote the following class, and ran it:
class Box{
//instance variables
double width;
double length;
double height;
//constructors
Box(double w, double l, double h){
width = w;
length = l;
height = h;
}
Box(double side){
width = side;
length = side;
height = side;
}
//methods
public double volume(){
return (width * length * height);
}
public double area(){
return (2*(width * height + width *length + height * length));
}
} //class Box
Now I want to implement the following in another file:
import Box;
class BoxTester{
public static void main(String[] args){
Box box = new Box(2.5, 5.0, 6.0);
System.out.println("Area:" + box.area() + " volume: " + box.volume() );
System.out.println("length:" + box.length + " height: " + box.height +
"width: " + box.width );
}
} //class BoxTester
I always get the same thing when I try to compile BoxTester.java:
BoxTester.java:2: '.' expected
import Box;
^
I haven't put these into "packages" because I'm not that far on my training yet, but this should work, right?
I've tried variations like:
Import Box.class;
Import Box
Import Box.*;
And nothing works. Any help is appreciated.
Thanks,
scripter73
Change Your Thinking, Change Your Life.
I'm new to Java (somewhat), and I'm running on a Java 2 Platform. I wrote the following class, and ran it:
class Box{
//instance variables
double width;
double length;
double height;
//constructors
Box(double w, double l, double h){
width = w;
length = l;
height = h;
}
Box(double side){
width = side;
length = side;
height = side;
}
//methods
public double volume(){
return (width * length * height);
}
public double area(){
return (2*(width * height + width *length + height * length));
}
} //class Box
Now I want to implement the following in another file:
import Box;
class BoxTester{
public static void main(String[] args){
Box box = new Box(2.5, 5.0, 6.0);
System.out.println("Area:" + box.area() + " volume: " + box.volume() );
System.out.println("length:" + box.length + " height: " + box.height +
"width: " + box.width );
}
} //class BoxTester
I always get the same thing when I try to compile BoxTester.java:
BoxTester.java:2: '.' expected
import Box;
^
I haven't put these into "packages" because I'm not that far on my training yet, but this should work, right?
I've tried variations like:
Import Box.class;
Import Box
Import Box.*;
And nothing works. Any help is appreciated.
Thanks,
scripter73
Change Your Thinking, Change Your Life.