Error - message is already defined in main
Hi - I think I've got the code right, I just keep getting this one last error. Here is the code;
import java.util.Scanner;
public class ModifiedInvoiceApp
{
public static void main(String[] args)
{
// welcome the user to the program
System.out.println("Welcome to the Invoice Total Calculator");
System.out.println(); // print a blank line
// create a Scanner object named sc
Scanner sc = new Scanner(System.in);
// perform invoice calculations until choice is equal to "n" or "N"
String choice = "y";
int InvoiceCount = 0;
while (!choice.equalsIgnoreCase("n"))
{
// get the invoice subtotal from the user
System.out.print("Enter subtotal: ");
double subtotal = sc.nextDouble();
// calculate the discount amount and total
double discountPercent= 0.0;
if (subtotal >= 500)
discountPercent = .25;
else if (subtotal >= 100)
discountPercent = .1;
else
discountPercent = 0.0;
double discountAmount = subtotal * discountPercent;
double total = subtotal - discountAmount;
// display the discount amount and total
String message = "Discount percent: " + discountPercent + "\n"
+ "Discount amount: " + discountAmount + "\n"
+ "Invoice total: " + total + "\n";
System.out.println(message);
// see if the user wants to continue
System.out.print("Continue? (y/n): ");
choice = sc.next();
System.out.println(message);
// display the number of invoices, average invoice amount, and average discount amount
InvoiceCount = InvoiceCount + 1;
double averageDiscountAmount = discountAmount / InvoiceCount;
double averageInvoiceAmount = total / InvoiceCount;
String message = "\n" +
"Number Of Invoices: " + "\n"
+ "Average Invoice Amount: " + averageInvoiceAmount + "\n"
+ "Average Discount Amount: " + averageDiscountAmount + "\n";
System.out.println(message);
}
}
}
It is an invoice calculator, the application ends only when the user enters "n" or "N" (I think this part is right?), and it is supposed to display the number of invoices, average invoice amount, and average discount amount but of course I can't test all that out until I fix the error.
Here is the error: C:\Murach\Java6\Exercises\java1.6\ch02\ModifiedInv oiceApp.java:49: message is already defined in main(java.lang.String[])
String message = "\n" +