• Post Reply Bookmark Topic Watch Topic
  • New Topic

Is it possible to create an element with two parameters an index and a value inside a bigger class?  RSS feed

 
alb albai
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have created a class with several parameters...but one of the parameters i want to have an index and a value ..i down want to create an array becouse i cant change it's length and i have to put it's length in begging..instead i want to create a database , to put it from the keqboard.

One of these parameters i want to have an index and a value:

import java.util.ArrayList;
public class street {

private String streetName;
private int Noside;
private int Noslot ;
private int Valid;





public street() {
this.streetName = null;
this.Noside = -1;
this.Noslot = -1;
this.Valid = 0;
} ;


public street(String nName, int nNum, int nYr, int Val) {
this.streetName = nName;
this.Noside = nNum;
this.Noslot = nYr;
this.Valid = Val;


}


public void setstreetName(String newstreetName) {
this.streetName = newstreetName;
}

public void setValid(int Validate) {
this.Valid = Validate;
}

public void setNoside(int newNoside) {
this.Noside = newNoside;
}


public int getValid() {
return Valid;
}

public String getstreetName() {
return streetName;
}

public int getNoside() {
return Noside;
}

public int getNoslot() {
return Noslot;
}


@Override
public String toString() {
return "streetName=" + streetName + ", Noside="
+ Noside + ", Noslot=" + Noslot ;}

}


Thanks in advance!
Albani
 
Chan Ag
Rancher
Posts: 1090
14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch, Alb Albai.

I have created a class with several parameters.


In Java, methods have parameters. A class only has variables and methods.

Also you should use code tags while posting Java code which makes it readable. It's quite easy to do so.
All you need do is select your code and click the code button.

Another thing I noticed is your class name street starts with a small letter. It is a standard convention/practice in Java to start the class name with a capital letter and to use camelCase for variables.
So you might want to change 'public class street' to 'public class Street' and variables Noside, Noslot, and Valid to noSide, noSlot, and valid.

You might also want to consider formatting your code with proper indentations to make it more readable for you and for others. Also it helps in figuring blocks' scope easily.

one of the parameters i want to have an index and a value


So do you mean you want the array like functionality ( an aggregate variable ) but you don't know in advance the number of elements this variable will hold, and hence you want to collect this value from the user? Is it going to be a fixed size variable or is it something that can grow and shrink in size?
How about you also tell us what kind of data this variable will hold. There might be more than one way to achieve what you want but depending on the usage, the suitability of the options could vary.

Chan.


 
alb albai
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the quick reply.

The idea is that i want to creat a CityParkingManager.
The variabels are StreetName, SetDirection and NumberSlot.
I have to modify a slot..i mean i have to delete/close/valide a certain number of slot based on a index.
But since number of slot is an int I cannot do it.
If i made it an array i have to put in the begininng the size but there and thats no good.
 
Chan Ag
Rancher
Posts: 1090
14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have to modify a slot..i mean i have to delete/close/valide a certain number of slot based on a index.
But since number of slot is an int I cannot do it.


I can't understand that. I can't even make a guess cause I don't know what a Parking manager's slot means functionally.
But if you want the user to supply the number of elements the array can hold, you can use the Scanner class. Something like this -



Is this what you were looking for? If not, then you could wait for someone else to provide you the required help. Sorry.

Chan.
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!