0

I need to make a program that displays a receipt for any company. So, the user should enter the company name, date, time, name and price of four items purchased and the program should add the prices to arrive at the total and should display like the pic below.

enter image description here

Here's what I have till now:-

import javax.swing.*;

public class Receipt {

    public static void main(String[] args) {

        String companyName;
        String itemName1;
        String itemName2;
        String itemName3;
        String itemName4;
        double item1;
        double item2;
        double item3;
        double item4;
        double total;
        double subTotal;
        double hst;
        String date;
        String time;

        date = JOptionPane.showInputDialog(null, "Please enter the date of the transaction in MM/DD/YYYY");
        time = JOptionPane.showInputDialog(null, "Please enter the time of the transaction");
        companyName = JOptionPane.showInputDialog(null, "Please enter the name of company you wish to make the reciept for");
        itemName1 = JOptionPane.showInputDialog(null, "What is your first item?");
        item1 = Double.parseDouble(JOptionPane.showInputDialog(null, "Enter Price."));
        itemName2 = JOptionPane.showInputDialog(null, "What is your second item?");
        item2 = Double.parseDouble(JOptionPane.showInputDialog(null, "Enter Price."));
        itemName3 = JOptionPane.showInputDialog(null, "What is your third item?");
        item3 = Double.parseDouble(JOptionPane.showInputDialog(null, "Enter Price."));
        itemName4 = JOptionPane.showInputDialog(null, "What is your fourth item?");
        item4 = Double.parseDouble(JOptionPane.showInputDialog(null, "Enter Price."));

        subTotal = item1 + item2 + item3 + item4;

        hst = 0.13 * subTotal;

        total = 1.13 * subTotal;

    }
}
Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
Excali
  • 9
  • 1
  • 4
  • Use the `JTextArea`. Append the output just like you would do on console output screen. – Young Emil Sep 23 '16 at 01:10
  • 1
    On which component do you want to display the output: `console` or `GUI component`? – Young Emil Sep 23 '16 at 01:28
  • 2
    Can you form that into the correct look using an HTML table for the item/price? (I could, but I'm asking if *you* could.) Then you could use an HTML aware component such as a `JLabel` to display and print it. – Andrew Thompson Sep 23 '16 at 01:34
  • 2
    Alternatively, set the `JTextArea` to `Font. MONOSPACED`. – trashgod Sep 23 '16 at 01:51
  • I'm using the JOptionPane gui box to display the receipt and could you elaborate more on the HTML table think as well as the JTextArea – Excali Sep 23 '16 at 18:18
  • Tip: Add @trashgod (or whoever, the `@` is important) to *notify* the person of a new comment. *"could you elaborate more on the HTML table think as well as the JTextArea"* Sure I could, but I won't based on that vague request. What have you tried? What are you confused about? Now is a good time to be more specific rather than issuing vague statements that sound to me like *"Can you provide code?"*. – Andrew Thompson Sep 25 '16 at 01:47
  • 1
    I strongly endorse @AndrewThompson's suggestion; as suggested [here](http://stackoverflow.com/a/22259102/230513), you may want to try both ways to see which appeals more for your use case. – trashgod Sep 25 '16 at 04:08

0 Answers0