Go Back   CodingForums.com > :: Server side development > Java and JSP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 01-09-2013, 01:42 AM   PM User | #1
Taro
Regular Coder

 
Taro's Avatar
 
Join Date: Oct 2011
Location: Geraldton, Ontario
Posts: 155
Thanks: 1
Thanked 1 Time in 1 Post
Taro is an unknown quantity at this point
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.
Taro is offline   Reply With Quote
Old 01-09-2013, 03:54 AM   PM User | #2
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,650
Thanks: 4
Thanked 2,451 Times in 2,420 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
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.
Fou-Lu is offline   Reply With Quote
Old 01-16-2013, 04:54 AM   PM User | #3
Taro
Regular Coder

 
Taro's Avatar
 
Join Date: Oct 2011
Location: Geraldton, Ontario
Posts: 155
Thanks: 1
Thanked 1 Time in 1 Post
Taro is an unknown quantity at this point
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.
Taro is offline   Reply With Quote
Reply

Bookmarks

Tags
declaration, integer, type

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 05:27 AM.


Advertisement
Log in to turn off these ads.