Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 5 of 5

Thread: Would someone please help?

  1. #1
    Junior Member
    Join Date
    Nov 2013
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Red face Would someone please help?

    I am in an intro Java Programming class. In the beginning Java seemed simple and easy until the class got to multiple methods and loops. I have an assignment that was due (I did not turn in because of frustration). Anyway, would anyone be able to help me? Thank you in advance!

    Here are the program specifications:

    Scanner Input specifications:
     Invoice Number
     Customer Name
     Customer Type - Limited to: "R" - retail, or "C" - commercial
     Customer State - Limited to:" PA", "OH", and "WV"
     Municipality Tax - Limited to: "Y" - yes, or "N" - no
     Type of Sale - Limited to: "G" - ground, "W" - web or online
     Merchandise Subtotal - Total of merchandise without Customer Type Discounts, Sales tax or Freight, and Other Charges
     Freight Charges
     Other Charges

    Output:
     Invoice Number - as entered as input
     Customer Name - as entered as input
     Type of Sale - as entered as input.
     Merchandise Subtotal
     Discount - to be conditionally calculated. Based on Customer Type
     Freight Charges - as entered as input
     Other Charges - as entered as input
     Sales Tax Percentage - to be determined
     Sales Tax - to be conditionally calculated
     Total Invoice - to be unconditionally calculated as: Merchandise Subtotal - Customer Discount + Freight + Other Charges + Sales Tax

    1. Declare and initialize variables and objects as class variables and objects. Class variables and object declaration must be outside a method. Most Java programmers declare class variables and objects immediately after the class header, but before the main method. Class variables and objects may be used by any method within class. This application modular design will require multiple methods.

    2. Main method - Use Scanner input requirements and the Console outputs. The Total Invoice equals Merchandise Subtotal - Customer Discount + Freight + Other Charges + Sales Tax. Apply the NumberFormat class as appropriate. Execute the application, enter sample data and review the console outputs for accuracy and format.

    3. Add a While Loop -Pre-loop test to enter zero or more invoices at the description of the user. Test the added pre-loop design. Execute the application and test the ability to process no invoices, multiple invoices and stop. Please add a console output message after the loop that the program has been completed, so that one can clearly determine that the program has stopped (not just hung up).

  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,140
    Thanks
    48
    Thanked 2,156 Times in 2,129 Posts

    Default Re: Would someone please help?

    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    4,778
    My Mood
    Mellow
    Thanks
    175
    Thanked 625 Times in 612 Posts

    Default Re: Would someone please help?

    I agree that this assignment is a bit harder than the average "connect the numbered dots" specification, because you have to read the whole thing and imagine how to structure the program to accomplish all tasks specified. You might start by jotting down your ideas with pencil on paper. Start with a class name. List the variables required; name them and describe their purpose. Decide what methods you'll need. There's a main(), of course. Describe what it does. Determine the other methods needed and describe what they do.

    Once you think you have a reasonable outline, as complete as you can, move your ideas to comments in source code with the class and method bodies roughed in. Add the variables. Then start coding.

    Or as Norm said, if you have your earlier efforts, post the best one of those, and let us know what frustrated you and made you give up. Ask questions, post errors.

  4. #4
    Junior Member
    Join Date
    Nov 2013
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Would someone please help?

    Below is what I have so far. I created my own values to see if my calculation will even work at all. It does seem to. Now, I need to start getting more input and creating loops depending on the answer, but not quite sure
    import java.util.Scanner;
     
    public class CustomerSalesInvoiceApplication
    {
    static int invoiceNumber;
    String getCustomerName;
    String customerType;
    String customerState;
    double municipalityTax;
    String typeOfSale;
     
    	public static void main(String[] args) 
    	{
    		double merchandiseSubtotal = 400;
    		double freightCharges = 20;
    		double otherCharges = 0;
    		double customerDiscount =40;
    		double salesTax = 14;
     
    		System.out.println("Welcome to the Invoice Calculaton Program!");
    		System.out.println();
    		Scanner sc = new Scanner(System.in);
    		System.out.print("Enter the number of invoices that you would like to process? ");
    		int count = sc.nextInt();
    		int invoiceCount=0;
    			while (invoiceCount < count)
    			{
    			double totalInvoice = (merchandiseSubtotal - customerDiscount + freightCharges + otherCharges + salesTax);	
    			System.out.println("The Total Invoioce = " + totalInvoice);	
    			invoiceCount++;
    			}
     
    		System.out.println("Program complete");
    	} // End Main Method
     
    }
    Attached Images Attached Images
    Last edited by Norm; November 11th, 2013 at 08:02 PM. Reason: Changed quote tags to code

  5. #5
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,140
    Thanks
    48
    Thanked 2,156 Times in 2,129 Posts

    Default Re: Would someone please help?

    What problems or questions do you have now?

    NOTE: The while statement should not be indented from the statement before it
    The code inside the while statement should be indented.

    The while() loop looks functionally like a for() loop. A for() would be the natural way to code that loop.
    If you don't understand my answer, don't ignore it, ask a question.