package Dialogs;
import java.text.DecimalFormat;
import java.util.Scanner;

public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    Scanner newdata =new Scanner(System.in);
    DecimalFormat df = new DecimalFormat(".00");
    int newprogram;
    int count = 0;
    double Total1;

    System.out.print("How many items in a counter? : ");
        int Item = sc.nextInt();
        String new1 [] = new String [Item];
        int new2 [] = new int [Item];
        double new3 [] = new double [Item];

        double Totalnew1, Totalnew2, value;
        System.out.println();

    for(int i = 0; i< new1.length; i++){
        count++;
        System.out.println("\nDrug Item "+count);

        System.out.print("Enter The Drug Name : ");
        new1 [i] = sc.next();
        System.out.print("Enter Quantity: ");
        new2 [i] = sc.nextInt();
        System.out.print("Enter Price   : ");
        new3 [i]  = sc.nextDouble();
        System.out.println("");
        }

    System.out.println("\n====================  [ SUMMARY OF ORDERS  ]  ===================");
    System.out.println("Drug Name      Quantity       Item Price        Total Price");

    for(int i = 0; i < new1.length; i++){
        System.out.print(new1[i]);
        System.out.print("         "+new2[i]);
        System.out.print("             "+df.format(new3[i])+"          ");

        Total1 = new2[i]*new3[i];
        System.out.println(df.format(Total1));
    }
    }
    }
    // I want to know How to get this?
    [  TOTAL SUMMARY  ]

Total Price 450.00
After Tax 484 // 450 + Vat
VAT Tax ( 12% ) 54 // 450 .12
Discount ( 20% ) 96.8 // after tax
.20
=============================

Total Price Tax
With VAT /Discount 96.8 // Discount

======================================================
[1]Cash
[2]Credit Card
Choose Type Are : 1

======================================================
Amount of Pay
387.2 // After Tax - Discount

Cash
400 //

Exchange
12.8 // Cash - Amount

Dani AI

Generated

Nice starting point — is right that the post formatting could be cleaned up, and gave the right idea about summing line totals and using conventional names. A couple of focused, practical suggestions to finish the receipt logic and make the program safer and easier to maintain:

Use a small object model instead of parallel arrays (for example, a DrugItem with name, qty, price). Accumulate a single subtotal from each item, then apply tax and discount in a clear order (decide whether discount is on pre-tax or post-tax amount and document it). Validate inputs (no negative quantities or prices) and check for insufficient payment before computing change.

For money, prefer BigDecimal and explicit rounding. Example of the core arithmetic:

BigDecimal subtotal = BigDecimal.ZERO;
// add each line: subtotal = subtotal.add(price.multiply(new BigDecimal(qty)));

BigDecimal vatRate = new BigDecimal("0.12");
BigDecimal vatAmount = subtotal.multiply(vatRate).setScale(2, RoundingMode.HALF_UP);
BigDecimal afterTax = subtotal.add(vatAmount);

BigDecimal discountRate = new BigDecimal("0.20");
BigDecimal discountAmount = afterTax.multiply(discountRate).setScale(2, RoundingMode.HALF_UP);
BigDecimal finalTotal = afterTax.subtract(discountAmount);

BigDecimal payment = new BigDecimal("500.00");
BigDecimal change = payment.subtract(finalTotal).max(BigDecimal.ZERO);

Finally, format output with NumberFormat.getCurrencyInstance() for user-facing amounts, use constants for rates, and keep business rules (tax-first vs discount-first) explicit in code comments. These steps will make totals correct, readable, and robust for real-world money handling.

Recommended Answers

All 2 Replies

The formatting seems off here. Those first three lines of your post seem to belong in the code.

What exactly is your question? How to get the total prize at the bottom?

You can add something like this:

double sum = 0.0;

for(int i = 0; i < new1.length; i++){
        System.out.print(new1[i]);
        System.out.print("         "+new2[i]);
        System.out.print("             "+df.format(new3[i])+"          ");

        Total1 = new2[i]*new3[i];
        sum += Total1;
        System.out.println(df.format(Total1));
    }

    System.out.println("\n Total: \t" + sum);

I would recommend respecting naming conventions, though: don't start variable names (like Total1) with a capital.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.