Untitled

 avatar
chamanEiqbal
java
a year ago
2.9 kB
4
Indexable
Never
```java
public static void printReceipt(Customer customer, Vehicle vehicle) {
    System.out.println("\n\n\n");
    System.out.println("******************************************************************************************************************");
    System.out.printf("%75s","KARACHI AUTOSERVICES PVT. LTD.\n");
    System.out.println("******************************************************************************************************************");
    System.out.printf("Customer Name: %-40s", customer.getName());
    System.out.printf("%40s\n", "Vehicle No.: " + vehicle.getVehNo());
    System.out.printf("Contact No.: %-40s", customer.getContactNo());
    System.out.printf("%40s\n", "Vehicle Model: " + vehicle.getModel());
    System.out.println("******************************************************************************************************************");
    System.out.printf("%65s", "BILL DESCRIPTION: \n");
    System.out.println("******************************************************************************************************************");
    System.out.printf("%-20s%-40s%-20s%-20s%-20s\n", "Type", "Name", "Price", "Quantity", "Discount");
    System.out.println("------------------------------------------------------------------------------------------------------------------");
    float totalAmount = 0.0f;
    float totalPartsAmount = 0.0f;
    float totalLabourAmount = 0.0f;
    for(int i = 0; i < PartsItems; i++) {
        float partsTotal = (priceList.get(i) * quantityList.get(i) - discountList.get(i));
        totalPartsAmount += partsTotal;
    }
    for(int i = PartsItems; i < bItems; i++) {
        float labourTotal = priceList.get(i) * quantityList.get(i);
        totalLabourAmount  += labourTotal;
    }
        for(int i=0;i<bItems;i++) {
        if(typeList.get(i).equalsIgnoreCase("Labour")) {
        System.out.printf("%-20s%-40s%15.2f%15.2f%15.2s\n", typeList.get(i), nameList.get(i), priceList.get(i), quantityList.get(i), "-");
        }
        else {
         System.out.printf("%-20s%-40s%15.2f%15.2f%15.2f\n", typeList.get(i), nameList.get(i), priceList.get(i), quantityList.get(i), discountList.get(i));
        }
        }
        totalAmount = totalPartsAmount + totalLabourAmount;
     
    System.out.println("------------------------------------------------------------------------------------------------------------------");
    System.out.printf("%-80s%20.2f\n", "Parts Total:", totalPartsAmount);
    System.out.printf("%-80s%20.2f\n", "Service Tax (5%):", totalPartsAmount * 0.05);
    System.out.printf("%-80s%20.2f\n", "Labour Total:", totalLabourAmount);
    System.out.printf("%-80s%20.2f\n", "Grand Total:", totalAmount - (totalPartsAmount * 0.05));
    
    System.out.println("******************************************************************************************************************");
}```