Kelas Pengurangan dan Tampilan
script java kelas pengurangan :
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/Terbitkan Entri
package BigHitung;
/**
*
* @author bapake-aisyah
*/
public class BigKurang {
String aPertama;
String aKedua;
public void setPertama(String a) {
this.aPertama = a;
}
public void setKedua(String a) {
this.aKedua = a;
}
public String getPertama() {
return this.aPertama;
}
public String getKedua() {
return this.aKedua;
}
public String kurangBig(String x, String y) {
String sc[] = new String[2000];
int ax[] = new int[2000];
int ay[] = new int[2000];
int lx = x.length();
int ly = y.length();
int lmax = Math.max(lx, ly) + 1;
String n = "";
for (int i = 0; i < lmax - lx; i++) {
x = "0" + x;
}
for (int i = 0; i < lmax - ly; i++) {
y = "0" + y;
}
int sisa = 0;
int hs = 0;
for (int i = lmax - 1; i > -1; i--) {
ax[i] = Integer.parseInt(x.substring(i, i + 1));
ay[i] = Integer.parseInt(y.substring(i, i + 1));
}
for (int i = lmax - 1; i > -1; i--) {
if (ax[i] < ay[i]) {
hs = (ax[i] + 10) - ay[i];
ax[i - 1] = ax[i - 1] - 1;
} else {
hs = ax[i] - ay[i];
}
sc[i] = Integer.toString(hs);
}
if (sc[0] == null ? "0" == null : sc[0].equals("0")) {
sc[0] = "";
}
for (int i = 0; i < lmax; i++) {
n += sc[i];
}
return n;
}
public String kurang(String a, String b) {
int la = a.length();
int lb = b.length();
String n = "";
int ax[] = new int[2000];
int ay[] = new int[2000];
if (la < lb) {
n = "-" + this.kurangBig(b, a);
} else if (la > lb) {
n = this.kurangBig(a, b);
} else if (la == lb) {
for (int i = la - 1; i > -1; i--) {
ax[i] = Integer.parseInt(a.substring(i, i + 1));
ay[i] = Integer.parseInt(b.substring(i, i + 1));
}
if (ax[0] > ay[0]) {
n = this.kurangBig(a, b);
} else {
n = "-" + this.kurangBig(b, a);
if (n.substring(1, 2) == null ? "0" == null : n.substring(1, 2).equals("0")) {
String m = "";
n = n.replaceFirst("0", m);
}
}
}
return n;
}
}
script untuk kelas tampilan (dengan GUI drag n drop) :
script hanya untuk tombol saja :
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
BigJumlah tambah = new BigJumlah();
String a = jTextArea1.getText();
String b = jTextArea2.getText();
tambah.setPertama(a);
tambah.setKedua(b);
jTextArea3.setText(tambah.jumlahBig(tambah.getPertama(), tambah.getKedua()));
}
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
BigKurang kurang = new BigKurang();
String a = jTextArea1.getText();
String b = jTextArea2.getText();
kurang.setPertama(a);
kurang.setKedua(b);
jTextArea3.setText(kurang.kurang(kurang.getPertama(), kurang.getKedua()));
}
private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
System.exit(10);
}
private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
jTextArea1.setText(null);
jTextArea2.setText(null);
jTextArea3.setText(null);
}
0 komentar:
Posting Komentar