Results 1 to 11 of 11

Thread: class help

  1. #1

    Thread Starter
    New Member
    Join Date
    Jul 2000
    Posts
    2

    Talking class help

    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 :
    Code:
    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 -------
    Code:
    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 -----------
    Code:
    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]

  2. #2
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    Make sure that Orderable is compiled and in the classpath BEFORE you try and compile Book.
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  3. #3
    Frenzied Member HarryW's Avatar
    Join Date
    Jan 2000
    Location
    Heiho no michi
    Posts
    1,827
    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'.
    Harry.

    "From one thing, know ten thousand things."

  4. #4

    Thread Starter
    New Member
    Join Date
    Jul 2000
    Posts
    2

    Talking

    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.


  5. #5
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    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.
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  6. #6
    Dazed Member
    Join Date
    Oct 1999
    Location
    Ridgefield Park, NJ
    Posts
    3,418
    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................

  7. #7
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    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.
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  8. #8
    Dazed Member
    Join Date
    Oct 1999
    Location
    Ridgefield Park, NJ
    Posts
    3,418
    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;
    }
    }



  9. #9
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    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.
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  10. #10
    Dazed Member
    Join Date
    Oct 1999
    Location
    Ridgefield Park, NJ
    Posts
    3,418

    Talking

    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.

  11. #11
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169

    Thumbs up King of the useless posters returns...

    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.
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width