Object and Classes error: cannot find symbol

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • darkseeker
    New Member
    • Mar 2012
    • 1

    Object and Classes error: cannot find symbol

    Hi guys,
    I'm working on my java assignment but I don't know what did I do wrong. I successfully compile the file Book.java but got the error cannot find symbol while compiling BookTest.java . Thank you very much for any help.

    Here's my Book.java

    Code:
    package question_1;
        public class Book {
        private String title; // Title of the book
        private String author; // Author of book :
        private String isbn; // International Standard Book Number 0-13-213198-7
        private float cost; // Cost of the book in U.S. dollars
        public Book() {
        title = "UnKnown";
        author = "UnKnown";
        isbn = "UnKnown";
        cost = 0;
        }
        public Book(String _title, String _author, String _isbn, float _cost) {
        title = _title;
        author = _author;
        isbn = _isbn;
        cost = _cost;
        }
        public String getTitle() {
        return title;
        }
        public String getAuthor() {
        return author;
        }
        public String getIsbn() {
        return isbn;
        }
        public float getCost() {
        return cost;
        }
        public void setTitle(String _title) {
        title = _title;
        }
        public void setAuthor(String _author) {
        author = _author;
        }
        public void setIsbn(String _isbn) {
        isbn = _isbn;
        }
        public void setCost(float _cost) {
        cost = _cost;
        }
        public double convertUsToEuro() {
        double euroconverted = 0;
        euroconverted = .73 * cost;
        return euroconverted;
        }
        }
    And here's my BookTest.java:

    Code:
    package question_1;
    
        import javax.swing.JFrame;
        import javax.swing.JOptionPane;
        import java.*;
        public class BookTest {
        public void test() {
        System.out.println("Begin test");
        Book book1 = new Book("Programing Java", "Sun System", "001", 86);
        Book book2 = new Book("Programing C#", "MS", "002", 89);
        /// print output for user
        JOptionPane.showMessageDialog(new JFrame(), "Book 1nTitle: " + book1.getTitle() + "nAuthor: " + book1.getAuthor() + "nISBN: " + book1.getIsbn() + "nCost in USD: " + book1.getCost() + "nCost in Euro: " + book1.convertUsToEuro());
        JOptionPane.showMessageDialog(new JFrame(), "Book 2nTitle: " + book2.getTitle() + "nAuthor: " + book2.getAuthor() + "nISBN: " + book2.getIsbn() + "nCost in USD: " + book2.getCost() + "nCost in Euro: " + book2.convertUsToEuro());
        }
        public static void main(String[] args) {
        BookTest obj = new BookTest();
        obj.test();
        }
        }
    Errors:

    Code:
     BookTest.java:14: cannot find symbol
        symbol : class Book
        location: class question_1.BookTest
        Book book1 = new Book("Programing Java", "Sun System", "001", 86);
        ^
        BookTest.java:14: cannot find symbol
        symbol : class Book
        location: class question_1.BookTest
        Book book1 = new Book("Programing Java", "Sun System", "001", 86);
        ^
        BookTest.java:15: cannot find symbol
        symbol : class Book
        location: class question_1.BookTest
        Book book2 = new Book("Programing C#", "MS", "002", 89);
        ^
        BookTest.java:15: cannot find symbol
        symbol : class Book
        location: class question_1.BookTest
        Book book2 = new Book("Programing C#", "MS", "002", 89);
        ^
        4 errors
    Thank you very much for any help.
  • neeraj0708
    New Member
    • Feb 2012
    • 21

    #2
    hi Darkseeker,

    Just remove your package name from both the classes, then it will work fine... :-)

    Comment

    • r035198x
      MVP
      • Sep 2006
      • 13225

      #3
      Not really, putting classes in the default package is discouraged. The OP should rather move the files into a folder structure that matches their package declarations.

      Comment

      • abhishekbrave
        New Member
        • Dec 2007
        • 79

        #4
        try importing the book class in the booktest.java file
        Code:
        import question_1.book;

        Comment

        Working...