I am new to Java (and asking questions on this site.)and am trying to change the itemList variable from inputs.Items.itemlist1 every time the for loop runs from itemlist1 to itemList2 then itemList3.
Here is my code:
items.java
public class Items {
public static Object[][] itemList1 = new Object[][]{
{"book", 12.49f, "BOOK"},
{"Music CD", 14.99f, "OTHERS"},
{"chocolate bar", 0.85f, "FOOD"},};
public static Object[][] itemList2 = new Object[][]{
{"imported box of chocolates", 10.00f, "IMPORTED_FOOD"},
{"imported bottle of perfume", 47.50f, "IMPORTED_OTHER"},};
public static Object[][] itemList3 = new Object[][]{
{"imported bottle of perfume", 27.99f, "IMPORTED_OTHER"},
{"bottle of perfume", 18.99f, "OTHERS"},
{"packet of headache pills", 9.75f, "MEDICAL"},
{"box of imported chocolates", 11.25f, "IMPORTED_FOOD"}
};
public static Object[] possibleListLength = new Object[]{itemList1.length, itemList2.length, itemList3.length};
public static Object[] possibleList = new Object[][]{itemList1, itemList2, itemList3};
}
DetermineItem.java
package tax;
import java.util.Arrays;
import java.util.ArrayList;
public class DetermineItem {
public static String itemPriceString = "";
public static void main(String[] args) {
//System.out.println(Arrays.deepToString(inputs.Items.itemList1));
Object arrayLength = inputs.Items.possibleList.length;
int arrayLengthInt = (Integer) arrayLength + 1;
for (int j = 1; j < 4; j++) {
System.out.println("Output " + j + ":");
for (int i = 0; i < arrayLengthInt; i++) {
Object[][] itemList = inputs.Items.itemList1;
Object itemTypeObject = itemList[i][2];
String itemTypeString = itemTypeObject.toString();
if (itemTypeString.equals("BOOK") || itemTypeString.equals("FOOD") || itemTypeString.equals("MEDICAL")) {
System.out.println("1 " + itemList[i][0] + ": " + itemList[i][1]);
} else if (itemTypeString.equals("IMPORTED_FOOD") || itemTypeString.equals("IMPORTED_OTHER")) {
Object itemPriceObject = itemList[i][1];
itemPriceString = itemPriceObject.toString();
CalculateImportTax.calculateImportTax();
System.out.println("1 " + itemList[i][0] + ": " + CalculateImportTax.price);
} else {
Object itemPriceObject = itemList[i][1];
itemPriceString = itemPriceObject.toString();
CalculateSalesTax.calculateTax();
System.out.println("1 " + itemList[i][0] + ": " + CalculateSalesTax.price);
}
}
}
}
}
Thanks.