Need help coding this. Use the sample output (below) to determine the logic of y
ID: 3859876 • Letter: N
Question
Need help coding this.
Use the sample output (below) to determine the logic of your method calls in the main(). using the void, value-receiving, and/or value-returning methods
Call the overloaded shippingInvoice method as an argument in the printf statement that prints the final output. E.g.: method1(method2(arg1, arg2), method3(arg1));
Sample output:
Enter the invoice number: 1829387
What's the name of the business? The Barbecue Pitt What's the price of the item? 5.72
How many items were purchased? 5
Enter the sales tax rate without the % sign: 8.25
Customer Name: The Barbecue Pitt Invoice No: 1829387
Subtotal: $28.60
Tax: 2.36
Total: $30.96
This is what i have so far, but its not working properly. Thanks:
public class Methods
{
private static Scanner input = new Scanner(System.in);
public static void main(String[] args)
{
String customerName = "";
int invoiceNo = 0;
double subTotal = 0.0;
double salesTax = 0.0;
double total = 0.0;
double noOfItem = 0.0;
double price = 0.0;
double taxRate = 0.0;
String header = "";
System.out.printf("%nEnter the invoice number: ");
invoiceNo = input.nextInt();
System.out.printf("%nWhat's the name of the business? ");
customerName = input.nextLine();
input.nextLine();
System.out.printf("%nWhat's the price of the Item?");
price = input.nextDouble();
System.out.printf("%nHow many items were purchased? ");
noOfItem = input.nextDouble();
input.nextLine();
System.out.printf("%nEnter the sales tax rate without the %% sign: ");
taxRate = input.nextDouble();
shippingInvoice(customerName, invoiceNo);
printAll(subTotal, salesTax, total);
System.exit(0);
}//END main
public static double calcSubTotal(double noOfItem, double price)
{
return (noOfItem * price);
}
public static double calcSalesTax(double subTotal, double taxRate)
{
return (subTotal * taxRate);
}
public static double calcTotal(double subTotal, double salesTax)
{
return (subTotal + salesTax);
}
public static void shippingInvoice(String customerName, int invoiceNo)
{
System.out.printf("%nCustomer Name: %s "
+ "%nInvoice No: %s ", customerName, invoiceNo);
}
public static double printAll(double subTotal, double salesTax, double total)
{
double printAll = 0.0;
System.out.printf("%nSubtotal: $ %s "
+ "%nTax: %s "
+ "%nTotal: $ %s ", subTotal, salesTax, total);
return printAll;
}//END pintAll
}//End class
Explanation / Answer
Please find the required solution: import java.util.Scanner; public class Methods { public static void main( String[] args ) { Scanner input = new Scanner(System.in); String customerName = ""; int invoiceNo = 0; double subTotal = 0.0; double salesTax = 0.0; double total = 0.0; double noOfItem = 0.0; double price = 0.0; double taxRate = 0.0; String header = ""; System.out.printf("%nEnter the invoice number: "); invoiceNo = input.nextInt(); System.out.printf("%nWhat's the name of the business? "); customerName = input.nextLine(); input.nextLine(); System.out.printf("%nWhat's the price of the Item?"); price = input.nextDouble(); System.out.printf("%nHow many items were purchased? "); noOfItem = input.nextDouble(); System.out.printf("%nEnter the sales tax rate without the %% sign: "); taxRate = input.nextDouble(); shippingInvoice(customerName, invoiceNo, (subTotal = calcSubTotal(noOfItem, price)), (salesTax = calcSalesTax(subTotal, taxRate)), calcTotal(subTotal, salesTax)); input.close(); }//END main public static double calcSubTotal( double noOfItem, double price ) { return (noOfItem * price); } public static double calcSalesTax( double subTotal, double taxRate ) { return (subTotal * taxRate); } public static double calcTotal( double subTotal, double salesTax ) { return (subTotal + salesTax); } public static void shippingInvoice( String customerName, int invoiceNo, double subTotal, double salesTax, double total ) { System.out.printf("%nCustomer Name: %s " + "%nInvoice No: %s ", customerName, invoiceNo); System.out.printf("%nSubtotal: $ %f " + "%nTax: %f " + "%nTotal: $ %f ", subTotal, salesTax, total); } }//End class Sample output screenshot: Enter the invoice number: 1829387 What's the name of the business? The Barbecue Pitt What's the price of the Item?5.72 How many items were purchased? 5 Enter the sales tax rate without the % sign: 8.25 Customer Name: Invoice No: 1829387 Subtotal: $ 28.600000 Tax: 235.950000 Total: $ 264.550000
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.