0

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. }}

3
Contributors
2
Replies
3
Views
6 Years
Discussion Span
Last Post by leiger
0

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

0

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.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.