Results 1 to 3 of 3
- 07-13-2011, 06:44 AM #1
Member
- Join Date
- May 2011
- Posts
- 46
- Rep Power
- 0
methods that won't return values...help plse
I have cleaned up my code and my output is not printing to the screen. I ran a dummy out.print in the getCustType and the values of sCustomerType and subtotal were 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:
Then the Invoice Class:Java Code: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 //get customer type Invoice.getCustType(sCustomerType, subtotal); //get invoice output Invoice.getInvoice(sCustomerType, customerType, discountPercent, discountAmount, total, subtotal);//get formatted output in a string for printing } }
Java Code:public static 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"; } System.out.print("Continue? (y/n): "); choice = sc.next(); System.out.println(); } return sCustomerType; } //output formatted invoice public static String getInvoice(String sCustomerType, String customerType, double discountPercent, double discountAmount, double total, double subtotal){ // calculate the discount amount and total discountPercent = getDiscountPercent(subtotal, customerType); discountAmount = subtotal * discountPercent; total = subtotal - discountAmount; System.out.println("D%: "+discountPercent+"D$: "+discountAmount+"ST: "+subtotal+"T: "+total); // 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); return message; } static 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; } }
- 07-13-2011, 06:46 AM #2
Please do not start another thread on the same topic. If you are patient then someone will eventually provide an answer in your original thread. Remember: we are not being paid to do this. If you don't get an answer within your acceptable time frame (or maybe no answer at all) too bad.
-
I agree with Junky that you're not being fair to the volunteers of this forum by needlessly dividing the discussion of your problem. Let's lock this thread and continue discussion in your original thread. If in the future you have an unrelated question to your original question, it's OK to start a new thread, but don't ask it in two places -- both your original thread and the new thread. Thanks for your cooperation.
Similar Threads
-
Help with modularity? Declaring methods and return values
By hiei_yasha in forum New To JavaReplies: 11Last Post: 02-03-2011, 02:42 AM -
return multiple values from class methods
By exdox77 in forum New To JavaReplies: 0Last Post: 01-29-2011, 08:08 PM -
Method to return values
By puchatek in forum New To JavaReplies: 4Last Post: 11-11-2010, 09:27 AM -
Methods, JOptionPane, Return Values
By Cubba27 in forum New To JavaReplies: 2Last Post: 12-04-2009, 02:46 AM -
how to return values from hashmap
By oregon in forum New To JavaReplies: 2Last Post: 08-01-2007, 04:56 PM


LinkBack URL
About LinkBacks

Bookmarks