Need to make a receipt which aligns item's prices (using javax.swing.* could import others if needed)

蹲街弑〆低调 提交于 2019-12-25 08:58:42

问题


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.

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;

    }
}

来源:https://stackoverflow.com/questions/39650927/need-to-make-a-receipt-which-aligns-items-prices-using-javax-swing-could-imp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!