Results 1 to 5 of 5
  1. #1
    doreilly15 is offline Member
    Join Date
    Feb 2012
    Posts
    2
    Rep Power
    0

    Default SetterGetter won't compile without errors?

    This is a simple program that is supposed to represent a car with only two parameters; year (1970-2011), and price (0-100000). Can somebody fix this code?

    First Class

    Java Code:
    Class Car
    {
    	private int Year;
    	private double Price;
    
    	public void setYear(int Y)
    	{
    		if(Y<=2011 && Y>=1970)
    		{
    		Year = Y;
    		}
    		else
    		{
    		Year = 0;
    		}
    	}
    
    	public void getYear()
    	{
    		return Year;
    	}
    
    	
    	public void setPrice(double P)
    	{
    		if(P <= 100000 && P >= 0)
    		{
    		Price = P;
    		}
    		else{
    		Price = 0;
    		{
    
    	}
    	public void getPrice()
    	{
    		return Price;
    	}
    }
    [B]Second Class[/B

    Java Code:
    import java.util.Scanner;
    Class Attributes
    {
    	public static void main(String[] args)
    	{
    		Scanner i = new Scanner(System.in);		
    
    		Car x = new Car;
    
    		System.out.println("What is the year of the car?");
    			x.setPrice(i.nextInt());
    
    		System.out.println("What is the price of the car?");
    			x.setYear(i.nextDouble());
    
    		System.out.println("The Price of the car is: " + x.getPrice() + ", and the year of the car is: " + x.getYear())
    	}
    }
    Last edited by pbrockway2; 02-08-2012 at 06:41 AM. Reason: code tags added

  2. #2
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,574
    Rep Power
    12

    Default Re: SetterGetter won't compile without errors?

    Hi doreilly15, welcome to the forums!

    I have added "code" tags to your post. The idea is you put [code] at the start of a section of code and [/code] at the end. That way the is properly formatted and more readable when it appears here.

    Can somebody fix this code?
    I begin from the assumption that you can! You may need some help though. In particular, does that code compile? If not, and you can't understand the compiler's messages post them and someone is sure to explain what they mean and what you might do about them etc.

  3. #3
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: SetterGetter won't compile without errors?

    We're not here to fix your code for you, but having said that, we'll be more than happy to help you fix it. Please first tell us what errors you're seeing. Best to post the whole error message, and indicate with comments where in the code the errors are being generated.
    Last edited by Fubarable; 02-08-2012 at 06:49 AM.

  4. #4
    doreilly15 is offline Member
    Join Date
    Feb 2012
    Posts
    2
    Rep Power
    0

    Default Re: SetterGetter won't compile without errors?

    Fixed it myself, thanks anyway.

  5. #5
    RichersooN is offline Senior Member
    Join Date
    Jan 2011
    Location
    Rizal Province, Philippiines
    Posts
    167
    Rep Power
    0

    Default Re: SetterGetter won't compile without errors?

    Java Code:
    public void getPrice()     {
             return Price;   
      }
    your getters will return nothing, because it is void.

Similar Threads

  1. help with compile errors
    By bzupnick in forum New To Java
    Replies: 1
    Last Post: 02-15-2011, 09:14 PM
  2. Replies: 4
    Last Post: 01-04-2011, 01:36 AM
  3. compile errors (how do I fix)
    By rhythmiccycle in forum New To Java
    Replies: 4
    Last Post: 01-03-2011, 11:33 PM
  4. Compile Errors and need to add a second static
    By lk1001 in forum New To Java
    Replies: 5
    Last Post: 03-05-2010, 12:58 AM
  5. Help with Compile time errors
    By bri1547 in forum New To Java
    Replies: 2
    Last Post: 08-25-2008, 12:22 AM

Posting Permissions

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