My output is not printing to the screen, I only get zero's. I ran a dummy out.print in the getCustType and the values of sCustomerType and subtotal were printing right. But when I call the getInvoice method, the values do not follow. Can someone help me figure this out? do I need to use a setter method?
Here is my code:
Main method:
public class InvoiceApp { public static void main(String[] args) { String message; double discountPercent=0; double discountAmount=0; double total=0; String customerType=""; double subtotal=0; String sCustomerType=""; // display a welcome message System.out.println("Welcome to the Invoice Total Calculator"); System.out.println(); // print a blank line Invoice myInvoice = new Invoice; //get customer type myInvoice.getCustType(sCustomerType, subtotal); //get invoice output myInvoice.getInvoice(sCustomerType, customerType, discountPercent, discountAmount, total, subtotal);//get formatted output in a string for printing } }
Then the Invoice Class:
public class Invoice{ double percent; double currency; String sSubtotal; String sCustomerType; public String getCustType(String sCustomerType, double subtotal){ Scanner sc = new Scanner(System.in); String choice = "y"; while(choice.equalsIgnoreCase("y")) { // get user entries String customerType = Validator.getString(sc, "Enter customer type (r/c): "); subtotal = Validator.getDouble(sc, "Enter subtotal: ", 0, 10000); if (customerType.equalsIgnoreCase("r")) sCustomerType = "Retail"; else if (customerType.equalsIgnoreCase("c")) sCustomerType = "College"; //dummy line to check output System.out.println("Customer Type: " + sCustomerType); System.out.println("subtotal: "+subtotal); System.out.print("Continue? (y/n): "); choice = sc.next(); System.out.println(); } return sCustomerType; } public void getInvoice(String sCustomerType, String customerType, double subtotal){ // output formatted invoice double discountPercent; //double subtotal; // customerType; double discountAmount; //double discountPercent; double total; // calculate the discount amount and total discountPercent = getDiscountPercent(subtotal, customerType); discountAmount = subtotal * discountPercent; total = subtotal - discountAmount; // format the values NumberFormat currency = NumberFormat.getCurrencyInstance(); NumberFormat percent = NumberFormat.getPercentInstance(); String sDiscountPercent = percent.format(discountPercent); String sDiscountAmount = currency.format(discountAmount); String sTotal = currency.format(total); String sSubtotal = currency.format(subtotal); // format and display the results String message = "Subtotal: " + sSubtotal + "\n" + "Customer type: " + sCustomerType + "\n" + "Discount percent: " + sDiscountPercent + "\n" + "Discount amount: " + sDiscountAmount + "\n" + "Total: " + sTotal + "\n"; System.out.println(); System.out.println(message); } public double getDiscountPercent(double subtotal, String type) { double discountPercent = 0.0; if (type.equalsIgnoreCase("r")) { if (subtotal >= 500) discountPercent = .2; else if (subtotal >= 250 && subtotal < 500) discountPercent =.15; else if (subtotal >= 100 && subtotal < 500) discountPercent =.1; else if (subtotal < 100) discountPercent =.0; } else if (type.equalsIgnoreCase("c")) { discountPercent = .2; } else discountPercent = .05; return discountPercent; } }