Say
Code: Select all
final double int[] array = {1, 3};
double int[] newArray = {2, 48};
//This doesn't work
//array = newArray
//This works.
array[0] = 2;
array[1] = 48;
Personal computing discussed
Moderators: renee, SecretSquirrel, just brew it!
final double int[] array = {1, 3};
double int[] newArray = {2, 48};
//This doesn't work
//array = newArray
//This works.
array[0] = 2;
array[1] = 48;
Zoomastigophora wrote:No. What you can do is wrap the array in another class and then provide only a getter for the values. Why do you want to prevent the elements in the array from being changed?
wibeasley: Java's equivalent of const is final, although it's not usable in all the places const can be used in C++. Java also doesn't have the concept of properties; if you need to access a private variable inside a class, the class needs to provide a function for you to call to get what you need.
Zoomastigophora wrote:No. What you can do is wrap the array in another class and then provide only a getter for the values. Why do you want to prevent the elements in the array from being changed?
final double STUDENT = 395.00;
final double BUSINESS = 595.00;
final double COMPLIMENTARY = 0.00;
double cost = 0.0;
int selected = list.getSelectedIndex();
if (selected == 0)
cost += STUDENT;
else if (selected == 1)
cost += BUSINESS;
else if (selected == 2)
cost += COMPLIMENTARY;
switch(selected)
{
case 1 : result = BUSINESS; break;
case 2 : result = STUDENT; break;
case 3 : result = COMPLIMENTARY; break;
}
cost += array[list.getSelectedIndex()];