cannot be applied to (double,java.lang.String)

I am working on a small and simple program but are stuck and need help I know that it's simple but hard to find the way for it to compile if any one out there is helpfull I would really appreciate it very much.

import java.text.NumberFormat;

import java.util.Scanner;

public class CodedInvoiceApp

{

public static void main(String[] args)

{

Scanner sc = new Scanner(System.in);

String choice = "y";

while (!choice.equalsIgnoreCase("n"))

{

// get the input from the user

System.out.print("Enter customer type (r/c/t): ");

String customerType = sc.next();

if (customerType.equalsIgnoreCase ("R"))

if (customerType.equalsIgnoreCase ("C"))

if (customerType.equalsIgnoreCase ("T"))

//call the coded invoice method

System.out.print("Enter subtotal:");

double subtotal = sc.nextDouble();

//call the discountPecent method

double discountPercent = getDiscountPercent(subtotal,customerType);

if (customerType.equalsIgnoreCase("R"))

{

if (subtotal < 250)

discountPercent = 0;

else if (subtotal >= 250 && subtotal < 500)

discountPercent = .25;

else if (subtotal >= 500)

discountPercent = .30;

}

else if (customerType.equalsIgnoreCase("C"))

discountPercent = .2;

else if (customerType.equalsIgnoreCase("T"))

if (subtotal < 500)

discountPercent = .4;

else if (subtotal >= 500)

discountPercent = .5;

// calculate the discount amount and total

double discountAmount = subtotal * discountPercent;

double total = subtotal - discountAmount;

// format and display the results

NumberFormat currency = NumberFormat.getCurrencyInstance();

NumberFormat percent = NumberFormat.getPercentInstance();

System.out.println(

"Discount percent: " + percent.format(discountPercent) + "\n" +

"Discount amount: " + currency.format(discountAmount) + "\n" +

"Total:" + currency.format(total) + "\n");

// see if the user wants to continue

System.out.print("Continue? (y/n): ");

choice = sc.next();

System.out.println();

}

}

// a static method that requires three arguments and returns a double

private static double getDiscountPercent(double subtotal,double customerType)

{

double discountPercent = 0.0;

double discountAmount = subtotal * discountPercent;

return subtotal;

}

}

java:28: getDiscountPercent(double,double) in CodedInvoiceApp cannot be applied to (double,java.lang.String)

double discountPercent = getDiscountPercent(subtotal,customerType);

Again thanks very much in advance

[2769 byte] By [emartinez1980@gmail.coma] at [2007-11-27 8:12:34]
# 1

The error message is telling you exactly what's wrong.

At line 28 of whatever java file it named that you cut off, you're passing a double and a String to a method that requires a double and a double. So either change the signature of the message to take a String, or change the second arg that you're passing to a double.

jverda at 2007-7-12 19:56:57 > top of Java-index,Java Essentials,Java Programming...
# 2

It's telling you what the problem is -- you're trying to pass a String in where a double is required. Java is a strongly typed language, which means that you can't expect types to change automatically into other types as needed.

You could, I suppose, parse the string, assuming that it holds a representation of a double. But if you look at the method in question, you'll see that it doesn't even use its second (double) argument.

So you should ask yourself:

1) should that method really take two arguments?

2) what is the second argument for, if I did use it?

3) what is the best type to represent the second argument?

(hint: with a name like "customerType", then an enum seems likely)

[add]

Too slow again.

Though I'll also add: please wrap any code you post in [code][/code] tags. It makes your code much easier to read.

Message was edited by:

paulcw

paulcwa at 2007-7-12 19:56:57 > top of Java-index,Java Essentials,Java Programming...