我的Java静态销售点(POS)系统出现问题。
我在for循环和if语句的帮助下使用2D数组,但是在接收POS时显示数组列存在问题。
public static void productdata(){
for(int row = 0; row < Product.length; row++) {
for (int col = 0; col < 4 ; col++){
Product[row][col] = "";
}
}
for(int row = 0; row < POS.length; row++){
for (int col = 0; col < 3 ; col++){
if(col == 0){
POS[row][col] = "0";
} else{
POS[row][col] = "";
}
}
}
// Product [x] [y] x = row; y = col //
Product [0] [0] = "PP1"; // PRODUCT CODE //
Product [0] [1] = "\t9350"; // PRODUCT PRICE //
Product [0] [2] = "FVP PowerPack Guyabano\t\t\t\t"; // PRODUCT NAME //
Product [0] [3] = "12"; // PRODUCT QUANTITY //
在所附的图像中,我显示了用于产品数据的数组。存在的问题是,所购买产品的收据显示产品代码( PP1 )[-请参见红色小框-]而不是产品名称( FVP PowerPack Guyabano < / em>)[-见紫罗兰色的盒子-],我不知道如何更改它或显示产品名称...
System.out.print("\n============================================================================");
System.out.print("\n POS SYSTEM");
System.out.print("\n FIRST VITA PLUS");
System.out.print("\n 2/F Suntree Tower,");
System.out.print("\n No. 13 Meralco Avenue,");
System.out.print("\n Ortigas Center, Pasig City");
System.out.print("\n 1605 Philippines\n");
if (TryAgain == 'n' || TryAgain == 'N'){
System.out.print("\n \t\t\t\t****PRODUCT PURCHASED****\n\n");
stop4:
for(int row = 0; row < POS.length; row++){
for(int col = 0; col < 3; col++){
if((POS[row][col].equals("0")) || (POS[row][col].equals(""))){
break stop4;
} else{
System.out.print(POS[row][col] + "\t");
}
}
System.out.println();
Double totalprice = Double.parseDouble(POS[row][2]);
TOTAL = totalprice + TOTAL;
}
System.out.print("\n============================================================================");
...在这一部分,我展示了输出以及如何创建客户收据的方法(带有产品代码(应该是产品名称),购买了产品的价格和数量)。
答案 0 :(得分:0)
似乎您正在尝试打印二维数组数据。
您可以尝试以下方法:
for (int row = 0; row < rowLength; row++)
{
for (int col = 0; col < colLength; col++)
{
System.out.print(arrayName[row][col]+" ");
}
System.out.print("\n");
}