pleas help

public double getInvoiceAmuont(int q,double pric){
		System.out.println("ente the quantity and the peice"  );
		q=in.nextInt();
		pric=in.nextDouble();
		if (q<0)
			return 0;
		if (pric<0)
			return 0;
		
		return q*pric;
	}

is this answer correct for this question :

{{ -Provide a method named getInvoiceAmuont that calculates the invoice amount (i.e., multiplies the quantity by the price per item), then returns the amount as a double value. If the quantity is not positive, it should be set to 0. If the price per item is not positive, it should be set to 0.0. }}

Remove lines L2,L3,L4.
You can use them inside program before invoke the getInvoiceAmuont method.

As quuba said, your lines 2-4 are redundant. You're passing in values to the method, then completely ignoring them and getting values from the console instead!!

You should either remove lines 2-4, or remove the parameters - getInvoiceAmount() - up to you which one you do as the question isn't clear on that. It depends on how the rest of your program works.

Let's break the question up:

Provide a method named getInvoiceAmuont that calculates the invoice amount (i.e., multiplies the quantity by the price per item), then returns the amount as a double value.

Looks like you've got the basics of this done.

If the quantity is not positive, it should be set to 0.

You're not doing this properly. Don't use "return". I won't tell you how to do it... but it's not the way you're attempting to do it at the moment.

If the price per item is not positive, it should be set to 0.0

At the moment you're returning an int, not a double.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.