Question: this is my code: ///////////////////////////////////////////////////////////////// // Student name: Maggie Smith // Assignment: #3 - Metal Receipt // Purpose: Printing out a receipt for a customer
this is my code:
///////////////////////////////////////////////////////////////// // Student name: Maggie Smith // Assignment: #3 - Metal Receipt // Purpose: Printing out a receipt for a customer will all the // right calculations // Operating System: 64 bit/ Windows 10 // Integrated Development Environment (IDE): jGrasp // Date of Completion: 3/5/21 // Total time spent: ///////////////////////////////////////////////////////////////////
import java.util.Scanner; public class Bill{ public static void main (String[] args){
// declaring variables Scanner in = new Scanner(System.in); final double [] prices = {125.56, 327.48, 79.24, 452.14, 255.60}; int index; int number; double subtotal = 0; String fName; String lName; char first; char last; String Fcustomer; String Lcustomer; double salestax; double amount; //declaring the arrays to hold the metal types, and the ones the customaer purchased int[] items =new int[5]; double[] ounces = new double[5]; index = 0; //displaying the menu options for the customer while (true){ printMenu(); System.out.print("Enter the type of metal that was bought: "); number = in.nextInt(); if(number==0) break; else if(number>=1 && number <=5) { items [index] = number; System.out.print(" Enter how much of the type of metal that was bought: "); ounces[index] = in.nextDouble(); index++; } else { System.out.println(" Please enter the correct type number of metal"); continue; } } in.nextLine(); // getting employees name as well as the customer System.out.println(" Salesperson First Name: "); fName = in.nextLine(); first = fName.charAt(0); System.out.println(" Salesperson Last Name: "); lName = in.nextLine(); last = lName.charAt(0); System.out.println(" Please enter the Customers First Name: "); Fcustomer = in.nextLine(); System.out.println(" Please enter the Customers Last Name: "); Lcustomer = in.nextLine(); //printing the bill System.out.println(); System.out.println("Customer: "+ Lcustomer+ "," + Fcustomer + "\t" + " Salesperson: " + first + "," + last); System.out.println("-----------------------------------------------"); System.out.println("Ounces\t|Metal Type\t|Price/oz\t|Cost"); for(int i = 0; i < index; i++){ subtotal += prices[items[i] -1] * ounces[i]; System.out.printf(ounces[i] + "\t|" + "Type" + items[i] + "\t\t|$" + prices[items[i] -1] + "\t|$%.2f", prices[items[i] - 1] * ounces[i]); } System.out.println("-----------------------------------------------"); System.out.printf("Subtotal: $%.2f", subtotal); //calculating the sales tax from the method created salestax = salesTax(subtotal); System.out.printf("Sales Tax: $%.2f", salestax); System.out.println("-----------------------------------------------"); System.out.printf("Sales Total: $%.2f", (subtotal+salestax)); } //displaying the menu private static void printMenu(){ System.out.println("Type 1 --> $125.56"); System.out.println("Type 2--> $327.48"); System.out.println("Type 3--> $79.24"); System.out.println("Type 4--> $452.14"); System.out.println("Type 5--> $255.60"); System.out.println("Press 0 to exit"); } //method that calculates salestax private static double salesTax(double amount){ return amount * 0.0825; }
and i'm trying to figure out why the line dashes don't appear on a separate in the output?
it ends up looking like this:
Customer: jones,bill Salesperson: j,s ----------------------------------------------- Ounces |Metal Type |Price/oz |Cost 12.6 |Type2 |$327.48 |$4126.253.7 |Type1 |$125.56 |$464.57----------------------------------------------- Subtotal: $4590.82Sales Tax: $378.74----------------------------------------------- Sales Total: $4969.56
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
