Results 1 to 5 of 5
- 02-08-2012, 05:33 AM #1
Member
- Join Date
- Feb 2012
- Posts
- 2
- Rep Power
- 0
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
[B]Second Class[/BJava 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; } }
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 05:41 AM. Reason: code tags added
- 02-08-2012, 05:45 AM #2
Moderator
- Join Date
- Feb 2009
- Location
- New Zealand
- Posts
- 4,546
- Rep Power
- 11
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.
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.Can somebody fix this code?
-
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 05:49 AM.
- 02-08-2012, 06:00 AM #4
Member
- Join Date
- Feb 2012
- Posts
- 2
- Rep Power
- 0
Re: SetterGetter won't compile without errors?
Fixed it myself, thanks anyway.
- 02-08-2012, 06:51 AM #5
Senior Member
- Join Date
- Jan 2011
- Location
- Rizal Province, Philippiines
- Posts
- 167
- Rep Power
- 0
Similar Threads
-
help with compile errors
By bzupnick in forum New To JavaReplies: 1Last Post: 02-15-2011, 08:14 PM -
First Java Program-Compile Errors (errors are posted)-simple GUI
By cc11rocks in forum AWT / SwingReplies: 4Last Post: 01-04-2011, 12:36 AM -
compile errors (how do I fix)
By rhythmiccycle in forum New To JavaReplies: 4Last Post: 01-03-2011, 10:33 PM -
Compile Errors and need to add a second static
By lk1001 in forum New To JavaReplies: 5Last Post: 03-04-2010, 11:58 PM -
Help with Compile time errors
By bri1547 in forum New To JavaReplies: 2Last Post: 08-24-2008, 11:22 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks