Results 1 to 3 of 3
  1. #1
    toppcon is offline Member
    Join Date
    May 2011
    Rep Power

    Default methods that won't return 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:

    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
    Then the Invoice Class:

    Java Code:
    public static String getCustType(String sCustomerType, double subtotal){
    		Scanner sc = new Scanner(;
           		String choice = "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 =;
    		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";
    	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;
                discountPercent = .05;
            return discountPercent;

  2. #2
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Rep Power


    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.

  3. #3
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Blog Entries
    Rep Power


    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

  1. Replies: 11
    Last Post: 02-03-2011, 02:42 AM
  2. return multiple values from class methods
    By exdox77 in forum New To Java
    Replies: 0
    Last Post: 01-29-2011, 08:08 PM
  3. Method to return values
    By puchatek in forum New To Java
    Replies: 4
    Last Post: 11-11-2010, 09:27 AM
  4. Methods, JOptionPane, Return Values
    By Cubba27 in forum New To Java
    Replies: 2
    Last Post: 12-04-2009, 02:46 AM
  5. how to return values from hashmap
    By oregon in forum New To Java
    Replies: 2
    Last Post: 08-01-2007, 04:56 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts