cara menghitung diskon
Hasil penghitungan diskon
Source Code.
public class harga extends javax.swing.JFrame {
/** Creates new form harga */
public harga() {
initComponents();
jTextField3.setText("");
}
public void diskon10 (){
int A;
double B = 10;
double C = 100;
int D;
int E;
A = Integer.parseInt(jTextField1.getText());
D = (int) (A * B / C);
jTextField2.setText(String.valueOf(D));
E = (int) (A - D);
jTextField3.setText(String.valueOf(E));
}
public void diskon20 (){
int A;
double B = 20;
double C = 100;
int D;
int E;
A = Integer.parseInt(jTextField1.getText());
D = (int) (A * B / C);
jTextField2.setText(String.valueOf(D));
E = (int) (A - D);
jTextField3.setText(String.valueOf(E));
}
public void diskon25 (){
int A;
double B = 25;
double C = 100;
int D;
int E;
A = Integer.parseInt(jTextField1.getText());
D = (int) (A * B / C);
jTextField2.setText(String.valueOf(D));
E = (int) (A - D);
jTextField3.setText(String.valueOf(E));
}
public void diskon30 (){
int A;
double B = 30;
double C = 100;
int D;
int E;
A = Integer.parseInt(jTextField1.getText());
D = (int) (A * B / C);
jTextField2.setText(String.valueOf(D));
E = (int) (A - D);
jTextField3.setText(String.valueOf(E));
}
public void diskon40 (){
int A;
double B = 40;
double C = 100;
int D;
int E;
A = Integer.parseInt(jTextField1.getText());
D = (int) (A * B / C);
jTextField2.setText(String.valueOf(D));
E = (int) (A - D);
jTextField3.setText(String.valueOf(E));
}
public void diskon50 (){
int A;
double B = 50;
double C = 100;
int D;
int E;
A = Integer.parseInt(jTextField1.getText());
D = (int) (A * B / C);
jTextField2.setText(String.valueOf(D));
E = (int) (A - D);
jTextField3.setText(String.valueOf(E));
}
public void diskon60 (){
int A;
double B = 60;
double C = 100;
int D;
int E;
A = Integer.parseInt(jTextField1.getText());
D = (int) (A * B / C);
jTextField2.setText(String.valueOf(D));
E = (int) (A - D);
jTextField3.setText(String.valueOf(E));
}
public void diskon70 (){
int A;
double B = 70;
double C = 100;
int D;
int E;
A = Integer.parseInt(jTextField1.getText());
D = (int) (A * B / C);
jTextField2.setText(String.valueOf(D));
E = (int) (A - D);
jTextField3.setText(String.valueOf(E));
}
public void diskon75 (){
int A;
double B = 75;
double C = 100;
int D;
int E;
A = Integer.parseInt(jTextField1.getText());
D = (int) (A * B / C);
jTextField2.setText(String.valueOf(D));
E = (int) (A - D);
jTextField3.setText(String.valueOf(E));
}
public void diskon80 (){
int A;
double B = 80;
double C = 100;
int D;
int E;
A = Integer.parseInt(jTextField1.getText());
D = (int) (A * B / C);
jTextField2.setText(String.valueOf(D));
E = (int) (A - D);
jTextField3.setText(String.valueOf(E));
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
buttonGroup1 = new javax.swing.ButtonGroup();
buttonGroup2 = new javax.swing.ButtonGroup();
buttonGroup3 = new javax.swing.ButtonGroup();
jPanel1 = new javax.swing.JPanel();
jLabel1 = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();
jLabel3 = new javax.swing.JLabel();
jTextField1 = new javax.swing.JTextField();
jTextField2 = new javax.swing.JTextField();
jTextField3 = new javax.swing.JTextField();
jLabel5 = new javax.swing.JLabel();
jPanel2 = new javax.swing.JPanel();
jLabel4 = new javax.swing.JLabel();
jRadioButton10 = new javax.swing.JRadioButton();
jRadioButton20 = new javax.swing.JRadioButton();
jRadioButton25 = new javax.swing.JRadioButton();
jRadioButton30 = new javax.swing.JRadioButton();
jRadioButton40 = new javax.swing.JRadioButton();
jRadioButton50 = new javax.swing.JRadioButton();
jRadioButton60 = new javax.swing.JRadioButton();
jRadioButton70 = new javax.swing.JRadioButton();
jRadioButton75 = new javax.swing.JRadioButton();
jRadioButton80 = new javax.swing.JRadioButton();
private void jRadioButton10ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
if (jRadioButton10.isSelected()){
diskon10();
}else{
int harga;
jTextField1.setText("");
jTextField2.setText("");
jTextField3.setText("");
}
}
private void jRadioButton20ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
if (jRadioButton20.isSelected()){
diskon20();
}
else
{
int harga;
jTextField1.setText("");
jTextField2.setText("");
jTextField3.setText("");
}
}
private void jRadioButton25ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
if (jRadioButton25.isSelected()){
diskon25();
}else{
int harga;
jTextField1.setText("");
jTextField2.setText("");
jTextField3.setText("");
}
}
private void jRadioButton30ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
if (jRadioButton30.isSelected()){
diskon30();
}else{
int harga;
}
}
private void jRadioButton40ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
if (jRadioButton40.isSelected()){
diskon40();
}else{
int harga;
jTextField1.setText("");
jTextField2.setText("");
jTextField3.setText("");
}
}
private void jRadioButton50ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
if (jRadioButton50.isSelected()){
diskon50();
}else{
int harga;
jTextField1.setText("");
jTextField2.setText("");
jTextField3.setText("");
}
}
private void jRadioButton60ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
if (jRadioButton60.isSelected()){
diskon60();
}else{
int harga;
jTextField1.setText("");
jTextField2.setText("");
jTextField3.setText("");
}
}
private void jRadioButton70ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
if (jRadioButton70.isSelected()){
diskon70();
}else{
int harga;
jTextField1.setText("");
jTextField2.setText("");
jTextField3.setText("");
}
}
private void jRadioButton75ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
if (jRadioButton75.isSelected()){
diskon75();
}else{
int harga;
jTextField1.setText("");
jTextField2.setText("");
jTextField3.setText("");
}
}
private void jRadioButton80ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
if (jRadioButton80.isSelected()){
diskon80();
}else{
int harga;
jTextField1.setText("");
jTextField2.setText("");
jTextField3.setText("");
}
}
private javax.swing.ButtonGroup buttonGroup1;
private javax.swing.ButtonGroup buttonGroup2;
private javax.swing.ButtonGroup buttonGroup3;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JLabel jLabel4;
private javax.swing.JLabel jLabel5;
private javax.swing.JPanel jPanel1;
private javax.swing.JPanel jPanel2;
private javax.swing.JRadioButton jRadioButton10;
private javax.swing.JRadioButton jRadioButton20;
private javax.swing.JRadioButton jRadioButton25;
private javax.swing.JRadioButton jRadioButton30;
private javax.swing.JRadioButton jRadioButton40;
private javax.swing.JRadioButton jRadioButton50;
private javax.swing.JRadioButton jRadioButton60;
private javax.swing.JRadioButton jRadioButton70;
private javax.swing.JRadioButton jRadioButton75;
private javax.swing.JRadioButton jRadioButton80;
private javax.swing.JTextField jTextField1;
private javax.swing.JTextField jTextField2;
private javax.swing.JTextField jTextField3;
}
ganteng
Senin, 02 Februari 2015
Jumat, 21 November 2014
tugas untuk uts
1. membuat kakkulator
berikut hasil run nya
package algoritma;
/**
*
* @author zaka
*/
public class kalkulator extends javax.swing.JFrame {
String angka;
Double Hasil,angka1,angka2;
int operator;
/** Creates new form kalkulator */
public kalkulator() {
initComponents();
angka="";
}
berikut source code untuk nomeric:
private void layarActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
layar.setText("");
}
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
angka+="1";
layar.setText(angka);
}
private void jButton18ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here: angka+="1";
angka+="2";
layar.setText(angka);
}
private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
angka+="3";
layar.setText(angka);
}
private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
angka+="4";
layar.setText(angka);
}
private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
angka+="5";
layar.setText(angka);
}
private void jButton6ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
angka+="6";
layar.setText(angka);
}
private void jButton7ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
angka+="7";
layar.setText(angka);
}
private void jButton8ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
angka+="8";
layar.setText(angka);
}
private void jButton9ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
angka+="9";
layar.setText(angka);
}
private void jButton10ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
angka+="0";
layar.setText(angka);
}
private void kaliActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
angka1=Double.parseDouble(angka);
layar.setText("x");
angka="";
operator=1;
}
private void bagiActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
angka1=Double.parseDouble(angka);
layar.setText("/");
angka="";
operator=2;
}
private void tambahActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
angka1=Double.parseDouble(angka);
layar.setText("+");
angka="";
operator=3;
}
private void kurangActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
angka1=Double.parseDouble(angka);
layar.setText("-");
angka="";
operator=4;
}
private void samadenganActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
switch (operator){
case 1:
angka2 = Double.parseDouble(angka);
Hasil = angka1 * angka2;
angka=Double.toString(Hasil);
layar.setText(angka);
break;
case 2:
angka2 = Double.parseDouble(angka);
Hasil = angka1 / angka2;
angka=Double.toString(Hasil);
layar.setText(angka);
break;
case 3:
angka2 = Double.parseDouble(angka);
Hasil = angka1 + angka2;
angka=Double.toString(Hasil);
layar.setText(angka);
break;
case 4:
angka2 = Double.parseDouble(angka);
Hasil = angka1 - angka2;
angka=Double.toString(Hasil);
layar.setText(angka);
break;
default:
break;
}
}
private void komaActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
angka1=Double.parseDouble(angka);
layar.setText(".");
angka="";
operator=5;
}
private void clearActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
layar.setText("");
angka1=0.0;
angka2=0.0;
Hasil=0.0;
angka="";
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
/* Set the Nimbus look and feel */
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
/* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
* For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
*/
try {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(kalkulator.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(kalkulator.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(kalkulator.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(kalkulator.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>
/* Create and display the form */
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new kalkulator().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JButton bagi;
private javax.swing.JButton clear;
private javax.swing.JButton jButton1;
private javax.swing.JButton jButton10;
private javax.swing.JButton jButton18;
private javax.swing.JButton jButton2;
private javax.swing.JButton jButton3;
private javax.swing.JButton jButton4;
private javax.swing.JButton jButton5;
private javax.swing.JButton jButton6;
private javax.swing.JButton jButton7;
private javax.swing.JButton jButton8;
private javax.swing.JButton jButton9;
private javax.swing.JButton kali;
private javax.swing.JButton koma;
private javax.swing.JButton kurang;
private javax.swing.JTextField layar;
private javax.swing.JButton samadengan;
private javax.swing.JButton tambah;
// End of variables declaration
}
berikut hasil run nya
hasil run untuk menyimpan
package algoritma;
/**
*
* @author zaka
*/
public class kalkulator extends javax.swing.JFrame {
String angka;
Double Hasil,angka1,angka2;
int operator;
/** Creates new form kalkulator */
public kalkulator() {
initComponents();
angka="";
}
berikut source code untuk nomeric:
private void layarActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
layar.setText("");
}
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
angka+="1";
layar.setText(angka);
}
private void jButton18ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here: angka+="1";
angka+="2";
layar.setText(angka);
}
private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
angka+="3";
layar.setText(angka);
}
private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
angka+="4";
layar.setText(angka);
}
private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
angka+="5";
layar.setText(angka);
}
private void jButton6ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
angka+="6";
layar.setText(angka);
}
private void jButton7ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
angka+="7";
layar.setText(angka);
}
private void jButton8ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
angka+="8";
layar.setText(angka);
}
private void jButton9ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
angka+="9";
layar.setText(angka);
}
private void jButton10ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
angka+="0";
layar.setText(angka);
}
private void kaliActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
angka1=Double.parseDouble(angka);
layar.setText("x");
angka="";
operator=1;
}
private void bagiActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
angka1=Double.parseDouble(angka);
layar.setText("/");
angka="";
operator=2;
}
private void tambahActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
angka1=Double.parseDouble(angka);
layar.setText("+");
angka="";
operator=3;
}
private void kurangActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
angka1=Double.parseDouble(angka);
layar.setText("-");
angka="";
operator=4;
}
private void samadenganActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
switch (operator){
case 1:
angka2 = Double.parseDouble(angka);
Hasil = angka1 * angka2;
angka=Double.toString(Hasil);
layar.setText(angka);
break;
case 2:
angka2 = Double.parseDouble(angka);
Hasil = angka1 / angka2;
angka=Double.toString(Hasil);
layar.setText(angka);
break;
case 3:
angka2 = Double.parseDouble(angka);
Hasil = angka1 + angka2;
angka=Double.toString(Hasil);
layar.setText(angka);
break;
case 4:
angka2 = Double.parseDouble(angka);
Hasil = angka1 - angka2;
angka=Double.toString(Hasil);
layar.setText(angka);
break;
default:
break;
}
}
private void komaActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
angka1=Double.parseDouble(angka);
layar.setText(".");
angka="";
operator=5;
}
private void clearActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
layar.setText("");
angka1=0.0;
angka2=0.0;
Hasil=0.0;
angka="";
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
/* Set the Nimbus look and feel */
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
/* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
* For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
*/
try {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(kalkulator.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(kalkulator.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(kalkulator.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(kalkulator.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>
/* Create and display the form */
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new kalkulator().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JButton bagi;
private javax.swing.JButton clear;
private javax.swing.JButton jButton1;
private javax.swing.JButton jButton10;
private javax.swing.JButton jButton18;
private javax.swing.JButton jButton2;
private javax.swing.JButton jButton3;
private javax.swing.JButton jButton4;
private javax.swing.JButton jButton5;
private javax.swing.JButton jButton6;
private javax.swing.JButton jButton7;
private javax.swing.JButton jButton8;
private javax.swing.JButton jButton9;
private javax.swing.JButton kali;
private javax.swing.JButton koma;
private javax.swing.JButton kurang;
private javax.swing.JTextField layar;
private javax.swing.JButton samadengan;
private javax.swing.JButton tambah;
// End of variables declaration
}
Kamis, 23 Oktober 2014
Tugas Algoritma STMIK ERESHA Kelas Malam
untuk mencari keterangan karyawan yang rajin masuk kerja selama setahun dengan cara fungsi else if
berikut printscreen hasil Run File:
berikut Source Codenya:
package javaapplication1;
/**
*
* @author aries
*/
import java.util.Scanner;
public class tugas {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
Scanner nilai=new Scanner(System.in);
System.out.println("masukan nilainya= ");
int grade=nilai.nextInt();
if(grade>=90){
System.out.println("Grade A");
System.out.println("Sangat Rajin");
}else if(grade>=80){
System.out.println("Grade B");
System.out.println("Rajin");
}else if(grade>=50){
System.out.println("Grade C");
System.out.println("Malas");
}else{
System.out.println("Grade D");
System.out.println("Sangat Malas");
}
}
}
Langganan:
Postingan (Atom)