Results 1 to 2 of 2
Thread: invoiceApp help with coding
- 09-13-2012, 01:43 AM #1
Member
- Join Date
- Sep 2012
- Posts
- 1
- Rep Power
- 0
invoiceApp help with coding
I am simply trying to calculate the number of invoices: the average invoice: and the average discount:, the code i have been working with is at the bottom. I appreciate any help with this.
import java.text.DecimalFormat;
import java.util.Scanner;
public class InvoiceApp
{
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 isn't equal to "y" or "Y"
String choice = "y";
while (choice.equalsIgnoreCase("y")) {
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 >= 200) {
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();
// display the score count, score total, and average score
double numberInvoices = total += 1;
double averageInvoice = total /= invoiceCount;
double averageDiscount = discountAmount /= numberofInvoices;
System.out.println( + "Number of invoices: " + numberofInvoices + "\n");
System.out.println( + "Average invoice: " + averageInvoice + "\n");
System.out.println( + "Average discount: " + averageDiscount + "\n");
System.out.println(message);
}
}}
- 09-13-2012, 01:53 AM #2
Re: invoiceApp help with coding
Please edit the post and wrap the code in code tags. See: BB Code List - Java Programming Forum
Can you post the program's output and explain what is wrong with it and show what it should be.If you don't understand my response, don't ignore it, ask a question.
Similar Threads
-
Need Help Coding IO
By loopsnhoops in forum New To JavaReplies: 1Last Post: 05-18-2011, 03:44 PM -
does gui coding in netbeans is just the same with coding without nebeans?
By maizuddin35 in forum NetBeansReplies: 4Last Post: 10-25-2010, 03:49 PM -
Need help coding
By ace_03 in forum New To JavaReplies: 2Last Post: 11-25-2009, 05:16 PM -
Coding help
By Java_Fanatic in forum New To JavaReplies: 7Last Post: 10-15-2009, 04:37 AM -
coding help
By accies76 in forum New To JavaReplies: 5Last Post: 11-12-2008, 08:15 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks