0

I have been working on a Simple Console Application, which lets to build your own PC. In the end, It prints your receipt which lists all the parts you choose

This is the Output I'm getting

This is the Output I'm getting

The Code for the output above.


public static void printReceipt() {
        System.out.println("=================================");
        System.out.println("          Your Receipt           ");
        System.out.println("=================================");

        System.out.println("1) " + mbName + "             " + mbPrice);
        System.out.println("2) " + proName + "             " + proPrice);
        System.out.println("8) " + gpuName + "             " + gpuPrice);
        System.out.println("3) " + ramName + "             " + ramPrice);
        System.out.println("4) " + stoName + "             " + stoPrice);
        System.out.println("5) " + coolName + "             " + coolPrice);
        System.out.println("6) " + psuName + "             " + psuPrice);
        System.out.println("7) " + cabName + "             " + cabPrice);

        double total = subtotal(mbPrice, proPrice, ramPrice, stoPrice, coolPrice, psuPrice, cabPrice, gpuPrice);

        System.out.println("=================================");
        System.out.println("GRAND TOTAL:       " + total + "/-");
        System.out.println("=================================");

        System.out.println(" =================================");
        System.out.println("|            Thank you            |");
        System.out.println(" =================================");

    }

Is there a way to format the output above into something like shown below?

=================================
          Your Receipt           
=================================

  Item                   Price
 ------                 -------

1) Asus                  20000.0
2) INTEL                 45000.0
8) Nvidia gtx 1050ti     17000.0
3) Asus                  18000.0
4) Samsung               20000.0
5) Coolermaster          20000.0
6) Ortis                  4000.0
7) Asus                   4000.0
=================================
GRAND TOTAL:            148000.0/-
================================= 
2
  • 1
    Cant reach the image. could you post it another way or share the output? Commented Mar 21, 2023 at 15:42
  • 1
    You can try String.format with padding. See for example here developer.com/java/java-string-format-method Commented Mar 21, 2023 at 15:43

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.