import java.util.Scanner; import java.text.DecimalFormat; public class Proj3 { public static void main(String[] args) { Scanner kb = new Scanner(System.in); String strCustomerName; String strPhoneNumber; String strShippingCode; String strTaxCode; char cShippingCode; char cTaxCode; int iDiscountCode; int iNumberOfGadgets; int iNumberOfWidgets; DecimalFormat df1 = new DecimalFormat("###-####"); CustomerOrder order1 = new CustomerOrder(); System.out.print("What is the name of your customer? Must be four letters long, if it is not four letters long please add X's to the end to correct this"); strCustomerName = kb.nextLine(); order1.setCustomerName(strCustomerName); System.out.print("What is the phone number of the customer? Please input in the format ###-####:"); strPhoneNumber = kb.nextLine(); order1.setPhoneNum(strPhoneNumber); System.out.print("How many gadgets does your customer want to order?"); iNumberOfGadgets = kb.nextInt(); order1.setNumGadgets(iNumberOfGadgets); System.out.print("How many widgets does your customer want to order?"); iNumberOfWidgets = kb.nextInt(); order1.setNumWidgets(iNumberOfWidgets); System.out.print("What shipping option would your customer prefer?"); System.out.println("For overnight shipping: O or o. For priority shipping: P or p. For standard shipping, s or S."); strShippingCode = kb.nextLine(); cShippingCode = strShippingCode.charAt(0); order1.setShippingCode(cShippingCode); System.out.print("Which tax code would your customer prefer?"); System.out.println("For non taxable: N or n. For taxable: T or t."); strTaxCode = kb.nextLine(); cTaxCode = strTaxCode.charAt(0); order1.setTaxCode(cTaxCode); System.out.print("Which discount code would your customer prefer?"); System.out.println("For no discount: 0. For loyalty discount: 1. For employee discount: 2."); iDiscountCode = kb.nextInt(); order1.setDiscountCode(iDiscountCode); }//end of main }//end of Proj3
In class, we are calling private methods from a class. The shipping and tax codes have to be set to a character. I would appreciate help on how to convert a string to a character. Foe example, when asked which tax code the customer would prefer, if they choose N or n it would give non taxable, if they choose T or t, it would give taxable, otherwise it would give taxable. However, when it gets to line 44, where you have to input the shipping code, it crashes with the error "String index out of range: 0". Any help would be appreciate, thanks again.