提倡獨立完成作業(yè),培養(yǎng)獨立思考能力。
創(chuàng)新互聯(lián)公司專注于中大型企業(yè)的網(wǎng)站設(shè)計制作、成都網(wǎng)站制作和網(wǎng)站改版、網(wǎng)站營銷服務(wù),追求商業(yè)策劃與數(shù)據(jù)分析、創(chuàng)意藝術(shù)與技術(shù)開發(fā)的融合,累計客戶近千家,服務(wù)滿意度達97%。幫助廣大客戶順利對接上互聯(lián)網(wǎng)浪潮,準(zhǔn)確優(yōu)選出符合自己需要的互聯(lián)網(wǎng)運用,我們將一直專注品牌網(wǎng)站建設(shè)和互聯(lián)網(wǎng)程序開發(fā),在前進的路上,與客戶一起成長!
思路:可以新建一個銀行卡類BankCard,內(nèi)部屬性包含一個私有的不可變常量卡號cardNo,私有的可變量密碼password,私有的可變量余額cardBalance。
參考代碼如下:(僅供參考)
代碼與你的電腦系統(tǒng)不兼容。
建議你用PHP的來做。
win7 64位。
import javax.swing.JOptionPane;
/**
*
* @author __USER__
*/
public class test extends javax.swing.JFrame {
/** Creates new form test */
public test() {
initComponents();
}
//GEN-BEGIN:initComponents
// editor-fold defaultstate="collapsed" desc="Generated Code"
private void initComponents() {
jButton1 = new javax.swing.JButton();
jLabel1 = new javax.swing.JLabel();
jTextField1 = new javax.swing.JTextField();
jTextField2 = new javax.swing.JTextField();
jLabel2 = new javax.swing.JLabel();
jTextField3 = new javax.swing.JTextField();
jLabel3 = new javax.swing.JLabel();
jLabel4 = new javax.swing.JLabel();
jTextField4 = new javax.swing.JTextField();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jButton1.setText("\u5f00\u59cb\u6d4b\u8bd5");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});
jLabel1.setText("\u8bf7\u8f93\u5165\u6d4b\u8bd5\u6b21\u6570\uff1a");
jTextField2.setEditable(false);
jLabel2.setText("\u6362\u5361\u80dc\u5229\u6b21\u6570\uff1a");
jTextField3.setEditable(false);
jLabel3.setText("\u4e0d\u6362\u80dc\u5229\u6b21\u6570\uff1a");
jLabel4.setText("\u603b\u8017\u65f6\uff08\u79d2\uff09\uff1a");
jTextField4.setEditable(false);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(
getContentPane());
getContentPane().setLayout(layout);
layout
.setHorizontalGroup(layout
.createParallelGroup(
javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(
layout
.createSequentialGroup()
.addGap(84, 84, 84)
.addGroup(
layout
.createParallelGroup(
javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(
layout
.createSequentialGroup()
.addGroup(
layout
.createParallelGroup(
javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(
layout
.createSequentialGroup()
.addComponent(
jLabel3)
.addGap(
26,
26,
26)
.addComponent(
jTextField3,
javax.swing.GroupLayout.DEFAULT_SIZE,
153,
Short.MAX_VALUE))
.addGroup(
layout
.createSequentialGroup()
.addComponent(
jLabel2)
.addGap(
26,
26,
26)
.addGroup(
layout
.createParallelGroup(
javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(
jTextField4,
javax.swing.GroupLayout.PREFERRED_SIZE,
97,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(
jTextField2,
javax.swing.GroupLayout.DEFAULT_SIZE,
153,
Short.MAX_VALUE))))
.addGap(
119,
119,
119))
.addGroup(
layout
.createSequentialGroup()
.addGroup(
layout
.createParallelGroup(
javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(
jLabel4)
.addComponent(
jLabel1))
.addPreferredGap(
javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(
jTextField1,
javax.swing.GroupLayout.PREFERRED_SIZE,
117,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(
18,
18,
18)
.addComponent(
jButton1)
.addContainerGap()))));
layout
.setVerticalGroup(layout
.createParallelGroup(
javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(
javax.swing.GroupLayout.Alignment.TRAILING,
layout
.createSequentialGroup()
.addGap(52, 52, 52)
.addGroup(
layout
.createParallelGroup(
javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel4)
.addComponent(
jTextField4,
javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(28, 28, 28)
.addGroup(
layout
.createParallelGroup(
javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(
jLabel2,
javax.swing.GroupLayout.PREFERRED_SIZE,
20,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(
jTextField2,
javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(32, 32, 32)
.addGroup(
layout
.createParallelGroup(
javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(
jLabel3,
javax.swing.GroupLayout.PREFERRED_SIZE,
20,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(
jTextField3,
javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(
javax.swing.LayoutStyle.ComponentPlacement.RELATED,
67, Short.MAX_VALUE)
.addGroup(
layout
.createParallelGroup(
javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(
jLabel1,
javax.swing.GroupLayout.PREFERRED_SIZE,
20,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(
jTextField1,
javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jButton1))
.addGap(76, 76, 76)));
pack();
}// /editor-fold
//GEN-END:initComponents
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
long time = System.currentTimeMillis();
String number = jTextField1.getText();
if (number.matches("^[1-9]{1}\\d*$")) {
long count1 = 0;
long count2 = 0;
int[] cards = { 0, 0, 1 };
long times = Long.parseLong(number);
for (long i = 0L; i times; i++) {
int random = (int) (Math.random() * 3);
//表示第一次抽取的牌
int card1 = cards[random];
count1 += card1;
//表示第二次如果換牌之后的牌
int card2 = Math.abs(card1 - 1);
count2 += card2;
}
time = System.currentTimeMillis() - time;
jTextField2.setText("" + count2);
jTextField3.setText("" + count1);
jTextField4.setText("" + time/1000.0);
} else {
JOptionPane.showMessageDialog(null, "輸入有誤!");
}
}
/**
* @param args
* the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new test().setVisible(true);
}
});
}
//GEN-BEGIN:variables
// Variables declaration - do not modify
private javax.swing.JButton jButton1;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JLabel jLabel4;
private javax.swing.JTextField jTextField1;
private javax.swing.JTextField jTextField2;
private javax.swing.JTextField jTextField3;
private javax.swing.JTextField jTextField4;
// End of variables declaration//GEN-END:variables
}