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 5 of 5

Thread: Cannot get to compile

  1. #1
    Junior Member
    Join Date
    Apr 2011
    Posts
    6
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Cannot get to compile

    This one works just fine

    public class Brand
    {
    	private String name;
    	private String city;
     
    	public Brand()
    	{
    		setName("");
    		setCity("");
    	}
     
    	public Brand(String n, String c)
    	{
    		setName(n);
    		setCity(c);
    	}
     
    	//SETS
     
    	public void setName(String name)
    	{
    		this.name = name;
    	}
     
    	public void setCity(String city)
    	{
    		this.city = city;
    	}
     
    	//GETS
     
    	public String getName()
    	{
    		return name;
    	}
     
    	public String getCity()
    	{
    		return city;
    	}
     
    	public String toString()
    	{
    		return("Name" + name + "City" + city);
    	}
    }

    This is the one that wont compile and I'm not sure what I have done wrong, everything looks the same as I have it in my notes.

    public class Computer
    {
    	private Brand brand;
    	private double price;
    	private int quantity;
    	private double totalCharge;
     
    	public Computer()
    	{
    		setBrand(new Brand());
    		setPrice(0.0);
    		setQuantity(0);
    		setTotalCharge(0.0);
    	}
     
    	public Computer(String n, String c, double p, int q, double tc)
    	{
    		setBrand(new Brand(n, c));
    		setPrice(p);
    		setQuantity(q);
    		setTotalCharge(tc);
    	}
     
     
    	//SETS
     
    	public void setPrice(double price)
    	{
    		this.price = price;
    	}
     
    	public void setQuantity(int quantity)
    	{
    		this.quantity = quantity;
    	}
     
    	public void setTotalCharge(double totalCharge)
    	{
    		this.totalCharge = totalCharge;
    	}
     
    	//GETS
     
    	public double getPrice()
    	{
    		return price;
    	}
     
    	public int getQuantity()
    	{
    		return quantity;
    	}
     
    	public double getTotalCharge()
    	{
    		return totalCharge;
    	}
     
    	public String toString()
    	{
    		return(brand.toString() + "Price" + price + "Quantity" + quantity + "Toatl Charge" + totalCharge);
    	}
    }

    Any help would be great, thanks in advance.


  2. #2
    Super Moderator helloworld922's Avatar
    Join Date
    Jun 2009
    Posts
    2,896
    Thanks
    23
    Thanked 619 Times in 561 Posts
    Blog Entries
    18

    Default Re: Cannot get to compile

    What doesn't work? Could you post the compile error(s)?

  3. #3
    Member
    Join Date
    Feb 2011
    Posts
    55
    My Mood
    Tolerant
    Thanks
    1
    Thanked 16 Times in 15 Posts

    Default Re: Cannot get to compile

    Where is the setBrand method?

  4. #4
    Junior Member
    Join Date
    Apr 2011
    Posts
    6
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Cannot get to compile

    Quote Originally Posted by JJeng View Post
    Where is the setBrand method?

    Sorry I'm new to java, didn't realize I needed a set and get for that. All is well again, thanks again helloworld922 and JJeng.

  5. #5
    Grand Poobah
    Join Date
    Mar 2011
    Posts
    1,511
    My Mood
    Grumpy
    Thanks
    0
    Thanked 165 Times in 156 Posts

    Default Re: Cannot get to compile

    Nothing to do with being new to Java. It is the same for any language. You cannot call a method/function/procedure/sub-routine that does not exist.

Similar Threads

  1. [SOLVED] I CANT COMPILE
    By savvas in forum What's Wrong With My Code?
    Replies: 3
    Last Post: March 31st, 2011, 11:34 AM
  2. class wont compile
    By waspandor in forum What's Wrong With My Code?
    Replies: 3
    Last Post: January 15th, 2011, 03:40 PM
  3. *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
  4. [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
  5. need help to compile
    By hardwarewizard in forum Java Theory & Questions
    Replies: 0
    Last Post: February 14th, 2010, 09:03 AM