-
December 20th, 2011, 03:31 AM
#1
Not getting any result..
Hi to all , I've started to learn Java a few weeks ago
and my home work was to create a car with license plate and speed as verables.
The speed need to be change by me and can't be more then 100 || less then 0
I've started to wright the program but the answer is always zero..
can any one help me pls..
thanks Guys.
the Code is:
public class Car {
private int Num;
private int Speed;
public Car (int x){
x=Num;
Speed=0;
}
public int SpeedC (){
return Speed;
}
public void SpeedUp (int x){
if (x >= 100)
x=100;
else
x=Speed;
}
public int SpeedUp (){
return Speed+1;
}
public void SpeedDo (int x ){
if (x <= 0)
x=0;
else
x=Speed;
}
public int SpeedDo(){
return Speed-1;
}
public void show(){
System.out.print(Num);
System.out.print(Speed);
}
}
public class Program {
public static void main(String[] args) {
Car car1 = new Car(12345);
car1.show();
Car car2 = new Car(12346);
car1.SpeedUp(5);
car2.SpeedUp(1);
car1.show();
car2.SpeedUp(30);
}
}
-
December 20th, 2011, 05:57 AM
#2
Re: Not getting any result..
Check your methods for adding / decreasing speed.
For the first thing, myint+1 does not add anything to your myint variable. Use myint+=1 (same as myint = myint+1). Also, you allow inifinite modification in the other method, any checking applies only to the the method with param.
-
December 20th, 2011, 07:05 AM
#3
Re: Not getting any result..
Hi Londbrok,
thanks for helping me, I've change the return type as you said ..
but what I don't understand is , why my variable doesn't received in any method ..
-
December 20th, 2011, 07:35 AM
#4
Re: Not getting any result..
but what I don't understand is , why my variable doesn't received in any method ..
Dont know what you mean by that? Show the changes you made, please use [Code] tags
-
December 20th, 2011, 09:04 AM
#5
Re: Not getting any result..
ok Londbrok I've got it ...
what I meant was that when I create new object the method doesn't recognize it
but i found the problem it was incorrect syntax...
Thanks very much Londbrock..
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|