Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: class wont compile

  1. #1
    Junior Member
    Join Date
    Jan 2011
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Exclamation class wont compile

    Hi everybody,

    this is literally the first time i have ever posted anything on a forum, i am hoping i enjoy it and looking forward to using regularly.

    if i provide the code then explain the nature of my problem

    class 1:
    import java.util.*;
     
    public class Item implements Comparable {
     
    	private String id;
    	private String name;
        private double retail;
        private int quantity;
        private double price;
     
    	Item(String idIn, String nameIn, String retailIn, String quanIn) {
            id = idIn;
            name = nameIn;
            retail = Double.parseDouble(retailIn);
            quantity = Integer.parseInt(quanIn);
     
    		if (quantity > 400)
                price = retail * .5D;
            else if (quantity > 200)
                price = retail * .6D;
            else
                price = retail * .7D;
            price = Math.floor( price * 100 + .5 ) / 100;
        }
     
    	public int compareTo(Object obj) {
            Item temp = (Item)obj;
            if (this.price < temp.price)
                return 1;
            else if (this.price > temp.price)
                return -1;
            return 0; 
        }
     
    	public String getId() {
            return id;
        }
     
    	public String getName() {
            return name;
        }
     
     
    	public double getRetail() {
            return retail;
        }   
     
    	public int getQuantity() {
            return quantity;
        }
     
     
    	public double getPrice() {
            return price;
        }
    }

    class 2:
    import java.util.*;
     
     public class Storefront {
     
    	 private LinkedList catalog = new LinkedList();
         public void addItem(String id, String name, String price,
             String quant) {
             Item it = new Item(id, name, price, quant);
             catalog.add(it);
         }
         public Item getItem(int i) {
             return (Item)catalog.get(i);
         }
         public int getSize() {
             return catalog.size();
         }
         public void sort() {
             Collections.sort(catalog);
         }
     }
    the first class compiles fine. the second class will not compile. i originally tried to put them in packages but gave up on that. now i just want the second class file to compile

    can anyone help
    will be much appreciated :-)
    Last edited by helloworld922; January 17th, 2011 at 05:03 AM.


  2. #2
    Forum Squatter newbie's Avatar
    Join Date
    Nov 2010
    Location
    North Wales
    Posts
    661
    My Mood
    Stressed
    Thanks
    28
    Thanked 115 Times in 106 Posts
    Blog Entries
    1

    Default Re: class wont compile

    Both Classes compile fine for me :<.
    There is a warning for the use of Collections.sort(catalog) but it should still work - (Unchecked Exception warnings wont stop program from starting)
    Paste exactly what you typed to try and compile the second class in-case it really is a basic spelling error .
    Last edited by newbie; January 15th, 2011 at 03:02 PM.
    Please use [highlight=Java]//code goes here...[/highlight] tags when posting your code

  3. #3
    Junior Member
    Join Date
    Jan 2011
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: class wont compile

    you don't know how much i appreciate your response :-)

    i still cant get the second class to compile, for some reason it is unable to locate the "Item class"
    something to do with the classpath (never had this issue before)

    below is exactly what appears when i try and compile the second class.. been on this for hours..

    C:\java\Item>javac Storefront.java
    Storefront.java:11: cannot find symbol
    symbol : class Item
    location: class Storefront
    public Item getItem(int i) {
    ^
    Storefront.java:8: cannot find symbol
    symbol : class Item
    location: class Storefront
    Item it = new Item(id, name, price, quant);
    ^
    Storefront.java:8: cannot find symbol
    symbol : class Item
    location: class Storefront
    Item it = new Item(id, name, price, quant);
    ^
    Storefront.java:12: cannot find symbol
    symbol : class Item
    location: class Storefront
    return (Item)catalog.get(i);
    ^
    Note: Storefront.java uses unchecked or unsafe operations.
    Note: Recompile with -Xlint:unchecked for details.
    4 errors

    its pretty clear it gets stuck whenever it needs the Item class..
    just not sure how to fix it..

  4. #4
    Junior Member
    Join Date
    Jan 2011
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: class wont compile

    GOT IT TO WORK!!!

    thanks again for your reply (if your reading this)

Similar Threads

  1. *why won't this compile?*
    By dcshoecousa in forum What's Wrong With My Code?
    Replies: 6
    Last Post: November 2nd, 2010, 07:18 PM
  2. Why wont the Button wrap?
    By Taylorleemusic in forum What's Wrong With My Code?
    Replies: 4
    Last Post: October 1st, 2010, 12:03 AM
  3. [SOLVED] help in java i cant compile this
    By timeline in forum What's Wrong With My Code?
    Replies: 5
    Last Post: April 15th, 2010, 02:11 PM
  4. Game of Craps: won't compile
    By FreeBird in forum What's Wrong With My Code?
    Replies: 9
    Last Post: February 15th, 2010, 05:12 PM
  5. need help to compile
    By hardwarewizard in forum Java Theory & Questions
    Replies: 0
    Last Post: February 14th, 2010, 10:03 AM

Tags for this Thread