PDA

Click to See Complete Forum and Search --> : class help


knlu
Jul 27th, 2000, 02:41 PM
Hi,
I'm working on a class architecture for a shopping system. I'm working with Java JDK 1.1.8 of a windows console. And I'm having a problem with linking my two classes together. Any help would be great.

PS. I know this is a easy prob. Sorry I'm a newbie to java

The error I recieve is :

C:\jdk1.1.8\bin>javac Book.java
Book.java:3: Superclass Orderable.Orderable of class Orderable.Book not found.
public class Book extends Orderable
^
1 error

----------------------------------------------------------

The two classes I'm working with are

Orderable.java -------

package Orderable;

public abstract class Orderable
{

public int itemNumber, itemQuantity;
public String itemName;
public double itemPrice;

public Orderable(int anItemNumber, String anItemName, double anItemPrice, int anItemQuantity)
{
this.itemNumber = anItemNumber;
this.itemName = anItemName;
this.itemPrice = anItemPrice;
this.itemQuantity = anItemQuantity;
}

public Orderable()
{
this.itemNumber = 0;
this.itemName = null;
this.itemPrice = 0;
this.itemQuantity = 1;
}
public int getItemNumber() { return itemNumber; }

public void setItemNumber ( int anItemNumber )
{
this.itemNumber = anItemNumber;
}

public String getItemName() { return itemName; }

public void setItemName ( String anItemName )
{
this.itemName = anItemName;
}

public double getItemPrice() { return itemPrice; }

public void setItemPrice( double anItemPrice )
{
this.itemPrice = anItemPrice;
}

public int itemQuantity() { return itemQuantity; }

public void setItemQuantity ( int anItemQuantity )
{
this.itemQuantity = anItemQuantity;
}

public boolean isLessThan(Orderable anOrderable)
{
return true;
}

public abstract void print();

}

Book.java -----------

package Orderable;

public class Book extends Orderable
{
protected String author;
protected int edition;

public Book(int anItemNumber, String anItemName, double anItemPrice, int anItemQuantity, String anAuthor, int anEdition)
{
super(anItemNumber, anItemName, anItemPrice, anItemQuantity);
this.author = anAuthor;
this.edition = anEdition;
}

public Book()
{
super();
this.author = null;
this.edition = 0;
}

public String getAuthor() {return author;}

public void setAuthor (String anAuther)
{
this.author = anAuthor;
}

public int getEdition() {return edition;}

public void setEdition (String anEdition)
{
this.edition = anEdition;

}

public void print()
{
System.out.println("Item Number: "+super.itemNumber);
System.out.println("Item Name: "+super.itemName);
System.out.println("Item Price: "+super.itemPrice);
System.out.println("Item Quantity: "+super.itemQuantity);
System.out.println("Author: "+author);
System.out.println("Edition: "+edition);
}

}



[Edited by knlu on 07-31-2000 at 01:20 PM]

parksie
Jul 30th, 2000, 03:12 PM
Make sure that Orderable is compiled and in the classpath BEFORE you try and compile Book.

HarryW
Jul 31st, 2000, 07:13 AM
And use code tags, makes things easier to read. There's a link at the top of this page to see how to use code tags - where it says 'vB code is ON'.

knlu
Jul 31st, 2000, 12:24 PM
Thank you for your replies. But I think that my problem extends from my packaging techniques. I have all the .java files in the same directory and yes i did compile Orderable first. It compiled fine. I still recieve the same error. Thank you for your help. But i still need some more. Any extra help would be great.

parksie
Jul 31st, 2000, 12:35 PM
The Java package system works this way: You must have packages corresponding to folders. As in:

CLASSPATH = C:\Java\Classes

C:\Java\Classes\uk\co\katisha\Orderable.java is in package uk.co.katisha

If there is not a folder to correspond to the package, it will die.

Dillinger4
Nov 6th, 2000, 12:38 PM
Hey parksie im having trouble to and if anyone on this post can help it would probably be you. If i have another class called Rectangle in another file how do i compile SomethingIsWrong so it can link to or whatever it does to
Rectangle. I keep getting Package doesnot exist compile time errors.


import java.Rectangle.*; // This doesnt seem to work

public class SomethingIsWrong {
public static void main(String[] args) {
Rectangle myRect = new Rectangle();
myRect.width = 40;
myRect.height = 50;
System.out.println("myRect's area is " + myRect.area());
}
}


thanks................

parksie
Nov 6th, 2000, 12:41 PM
If you don't specify a package anywhere, then they go into the local package, which is basically the current folder. So, if Rectangle.java does not define a package, you don't need to import it into SomethingIsWrong as long as they're in the same folder.

Dillinger4
Nov 6th, 2000, 12:53 PM
This is the code i have, but it keeps generating compile time errors.If i take out import java.Rectangle.*; and
package Rectangle; I get cannot resolve symbol
Rectangle myRect = new Rectangle();
^
If i leave them in like i have here Rectangle compiles fine
but SomethingIsWrong generates package Rectangle doesnot exist import Rectangle.*;
^


import Rectangle.*;

public class SomethingIsWrong {
public static void main(String[] args) {
Rectangle myRect = new Rectangle();
myRect.width = 40;
myRect.height = 50;
System.out.println("myRect's area is " + myRect.area());
}
}

//Then this class is in another file call Rectangle

package Rectangle;

public class Rectangle {
public int width = 0;
public int height = 0;

// a method for computing the area of the rectangle
public int area() {
return width * height;
}
}

parksie
Nov 6th, 2000, 12:57 PM
If it's in package Rectangle, then it would need to be under a folder:

%CLASSPATH%\Rectangle\Rectangle.class

Confusing, I know, but once you've got it sussed there's no problem.

Dillinger4
Nov 6th, 2000, 01:04 PM
Ahhhhhhhhhh ok. I got it. I always want to say thanks but i dont want people to think i like to get my post count up by posting thanks all of the time....... {{{laughing}}} But thanks!! anyway.

parksie
Nov 6th, 2000, 02:51 PM
It's always nice to get a thankyou, as has been shown with the many threads started by people saying how nice it was.

Anyway, for more info on packages, http://www.java.sun.com has lots of info.