Alright, so I'm trying to create a "sales tax program' where the user can input the items and it adds it to an array, called "costArray". I only know how to do it, almost, with a String (since I need costArray.length for the loop) but I'm kind of lost. Can anyone help point me in the right direction so I can: Take an array of numbers (doubles) and apply a multiplier to it (0.08 for sales tax percentage) and output a total number (double)? Here is what I have so far, can you tell me if I'm close? Thanks!:
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]); // } // } }