Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder Taro's Avatar
    Join Date
    Oct 2011
    Location
    Geraldton, Ontario
    Posts
    155
    Thanks
    1
    Thanked 1 Time in 1 Post

    Java integer declarations

    Hello,

    I was working on a project, and was experimenting on integer declarations.

    PHP Code:
        import bnv.jlk.cvu.Mechanics;
          public class 
    Project extends Base implements Colors
          
    {
        
        private 
    int redCars=0;
        
         public 
    Project()
          {
             
    super(hy50);
          }
    public 
    void test()
        {
        
    redCars++;
        
    redCars++;
        
    redCars++;
        
    blackCars--;
        }
        
        } 
    Notice that I have the number of redCars, which is a derivative of blackCars, the private variable located in the imported file. The imported file has made the specific integer private itself and cannot be declared in this class alone. My goal is to get the number of remaining black cars without declaring blackCars from the imported file. The important thing to know is that there are 50 blackCars, three of which are declared as redCars, hence redCars++. So, I would like to insert a function that would declare the remaining number of blackCars without putting an exact value, as I will need it as a model to be used for a repeated number of times.

    TO put it in a different way, this is a translation of what I would try to do:
    PHP Code:
    !redCars=x
    System
    .out.println(x); 
    Of course, that will not work since I can't add an operator to the data-type alone. Moreover, one possible alternative is just to declare all blackCars, then use a for-statement by counting the redCars, therefore highlighting the remaining value?

    *There may be a glitch or bug in this post.
    [IMG]http://www.codingforums.com/data:image/gif,GIF89a%12%00%12%00%B3%00%00%FF%FF%FF%F7%F7%EF%CC%CC%CC%BD%BE%BD%99%99%99ZYZRUR%00%00%00%FE%01%02 %00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00!%F9%04%04%14%00%FF%00%2C%00%00%00%00 %12%00%12%00%00%04X0%C8I%2B%1D8%EB%3D%E4%00%60(%8A%85%17%0AG*%8C%40%19%7C%00J%08%C4%B1%92%26z%C76%FE %02%07%C2%89v%F0%7Dz%C3b%C8u%14%82V5%23o%A7%13%19L%BCY-%25%7D%A6l%DF%D0%F5%C7%02%85%5B%D82%90%CBT%87%D8i7%88Y%A8%DB%EFx%8B%DE%12%01%00%3B[/IMG]
    Element ID

    Webs Support Helper

    Your friendly neighborhood Taroman.

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    Yep there definitely is. Did you do anything in particular with the upload there? Its not the first I've seen it, but haven't a clue the cause.

    I'm not sure I understand what you are doing here. The image *may* have provided more information lol.
    The use of private is done for this explicit reason. You do not want to allow direct manipulation of the variable by any extending classes. However, it is highly probable that the imported class has a method that allows manipulation (I haven't a clue what this is). I assume this only because you appear to intend to make use of the class itself which in turn needs to take any modifications you perform externally against it. Otherwise, there really is no purpose in linking them together at all.

    If you are interrelating the two classes together, perhaps extending the Mechanic class or writing a decorator for it would be warranted? Assuming it has at least a get method on it for the "black" cars, than you can respond accordingly with the "red" ones. I wouldn't recommend hard coding against the number being 50 if it can be avoided (as it sounds right now, if you have 50 its simply 50 - redCars to determine the number of black cars).

    Try getting that upload in; it may be easier to see what you are wanting to do with it.

  • #3
    Regular Coder Taro's Avatar
    Join Date
    Oct 2011
    Location
    Geraldton, Ontario
    Posts
    155
    Thanks
    1
    Thanked 1 Time in 1 Post
    Quote Originally Posted by Fou-Lu View Post
    Yep there definitely is. Did you do anything in particular with the upload there? Its not the first I've seen it, but haven't a clue the cause.

    I'm not sure I understand what you are doing here. The image *may* have provided more information lol.
    The use of private is done for this explicit reason. You do not want to allow direct manipulation of the variable by any extending classes. However, it is highly probable that the imported class has a method that allows manipulation (I haven't a clue what this is). I assume this only because you appear to intend to make use of the class itself which in turn needs to take any modifications you perform externally against it. Otherwise, there really is no purpose in linking them together at all.

    If you are interrelating the two classes together, perhaps extending the Mechanic class or writing a decorator for it would be warranted? Assuming it has at least a get method on it for the "black" cars, than you can respond accordingly with the "red" ones. I wouldn't recommend hard coding against the number being 50 if it can be avoided (as it sounds right now, if you have 50 its simply 50 - redCars to determine the number of black cars).

    Try getting that upload in; it may be easier to see what you are wanting to do with it.
    That could be a short-term solution; if the number in any of the extended classes associated with this file became false (implying that we were using Boolean checks), then the definite loop would fail.
    Element ID

    Webs Support Helper

    Your friendly neighborhood Taroman.


  •  

    Tags for this Thread

    Posting Permissions

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