问题
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