我需要制作一个显示任何公司收据的程序。因此,用户应输入购买的四件商品的公司名称,日期,时间,名称和价格,并且程序应添加价格以达到总数,并且应显示如下图。
这是我到现在所拥有的: -
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;
}
}