CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Dec 2011
    Posts
    4

    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);

    }
    }

  2. #2
    Join Date
    Apr 2007
    Posts
    442

    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.

  3. #3
    Join Date
    Dec 2011
    Posts
    4

    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 ..

  4. #4
    Join Date
    Apr 2007
    Posts
    442

    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

  5. #5
    Join Date
    Dec 2011
    Posts
    4

    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
  •  





Click Here to Expand Forum to Full Width

Featured