好的,所以我試圖創建一個「銷售稅計劃」,用戶可以在其中輸入項目並將其添加到數組中,名爲「costArray」。如何做到這一點,幾乎與一個字符串(因爲我需要costArray.length爲循環),但我有點失落。任何人都可以幫助我指出正確的方向,所以我可以:採取數組(數字雙)並應用乘數它(0.08銷售稅的百分比)和輸出總數(雙)?以下是我到目前爲止,你能告訴我,如果我關閉?謝謝!:Java對數組中的每個項目應用乘法
public class Input { private Scanner keybd; private String item; private double cost; private String[] costArray; private String[] itemArray; /** * Constructor for objects of class Scanner */ public Input(int anyAmountofItems) { keybd = new Scanner(System.in); costArray = new String[anyAmountofItems]; itemArray = new String[anyAmountofItems]; } /** * Mutator method to set the item names and costs */ public void setArray(){ for(int index=0; index < itemArray.length; index++){ System.out.println("Enter the item name: "); itemArray[index] = keybd.next();} for(int indexa=0; indexa < itemArray.length; indexa++){ System.out.println(itemArray[indexa]); } for(int indexb=0; indexb < costArray.length; indexb++){ System.out.println("Enter the item cost: "); costArray[indexb] = keybd.next();} for(int indexc=0; indexc < costArray.length; indexc++){ System.out.println(costArray[indexc]); } } /** * Accessor method to return the items cost with tax */ public double getTax(){ return costArray.length; } // /** // * Mutator method to calculate tax on each item // */ // public void calculateTax(){ // for(int index=0; index < costArray.length; index++){ // System.out.println(0.08 * costArray[index]); // } // } }