Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 10

/*

* To change this license header, choose License Headers in Project Properties.

* To change this template file, choose Tools | Templates

* and open the template in the editor.

*/

package id.myprogram.oop_mid;

/**

* @author ASus

*/

public interface Nilai {

void setNilai(Nilai2 n);

Nilai2 getNilai();

int getHasil(int gg);

/*

* To change this license header, choose License Headers in Project Properties.

* To change this template file, choose Tools | Templates

* and open the template in the editor.

*/

package id.myprogram.oop_mid;

/**

* @author ASus

*/

public class Nilai2 {


int[] nilais;

/*

* To change this license header, choose License Headers in Project Properties.

* To change this template file, choose Tools | Templates

* and open the template in the editor.

*/

package id.myprogram.oop_mid;

/**

* @author ASus

*/

public class MenentukanBesarKecil implements Nilai{

Nilai2 n;

public MenentukanBesarKecil()

public MenentukanBesarKecil(Nilai2 n)

this.n=n;

@Override

public void setNilai(Nilai2 n) {


this.n=n;

@Override

public Nilai2 getNilai() {

return n;

@Override

public int getHasil(int gg) {

int[] nilais= null;

if(gg==1)

nilais=(int[])n.nilais;

else

nilais=(int[])n.nilais;

int max,min;

int i;

if(gg==1)

max=nilais[0];

for (i=0; i<nilais.length; i++){

if(nilais[i] > max){

max = nilais[i];

}
return max;

else

min=nilais[0];

for (i=0; i<nilais.length; i++){

if(nilais[i] < min){

min = nilais[i];

return min;

/*

* To change this license header, choose License Headers in Project Properties.

* To change this template file, choose Tools | Templates

* and open the template in the editor.

*/

package id.myprogram.oop_mid;

import java.util.Arrays;
/**

* @author ASus

*/

public class FormBesarKecil extends javax.swing.JFrame {

/**

* Creates new form FormBesarKecil

*/

public FormBesarKecil() {

initComponents();

/**

* 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() {

jLabel1 = new javax.swing.JLabel();

jButton1 = new javax.swing.JButton();

lhasil1 = new javax.swing.JLabel();

lhasil2 = new javax.swing.JLabel();

vN = new javax.swing.JTextField();

jLabel4 = new javax.swing.JLabel();


setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

jLabel1.setText("Menentukan Nilai Terbesar dan Terkecil");

jButton1.setText("Hasil");

jButton1.addActionListener(new java.awt.event.ActionListener() {

public void actionPerformed(java.awt.event.ActionEvent evt) {

jButton1ActionPerformed(evt);

});

lhasil1.setText("Nilai Terbesar : ");

lhasil2.setText("Nilai Terkecil : ");

vN.addActionListener(new java.awt.event.ActionListener() {

public void actionPerformed(java.awt.event.ActionEvent evt) {

vNActionPerformed(evt);

});

jLabel4.setText("Nilai");

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(22, 22, 22)

.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

.addGroup(layout.createSequentialGroup()

.addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 45,


javax.swing.GroupLayout.PREFERRED_SIZE)

.addGap(18, 18, 18)

.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

.addComponent(jButton1)

.addComponent(jLabel1)

.addComponent(vN, javax.swing.GroupLayout.PREFERRED_SIZE, 145,


javax.swing.GroupLayout.PREFERRED_SIZE)))

.addComponent(lhasil2)

.addComponent(lhasil1))

.addContainerGap(128, Short.MAX_VALUE))

);

layout.setVerticalGroup(

layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

.addGroup(layout.createSequentialGroup()

.addContainerGap()

.addComponent(jLabel1)

.addGap(28, 28, 28)

.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)

.addComponent(vN, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)

.addComponent(jLabel4))

.addGap(76, 76, 76)

.addComponent(jButton1)

.addGap(30, 30, 30)

.addComponent(lhasil1)

.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(lhasil2)

.addContainerGap(59, Short.MAX_VALUE))

);

pack();

}// </editor-fold>

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {

// TODO add your handling code here:

String inputNilai;

inputNilai = vN.getText();

int[] n1 = Arrays.stream(inputNilai.split(",")).mapToInt(Integer::parseInt).toArray();

Nilai2 n=new Nilai2();

n.nilais=n1;

MenentukanBesarKecil MBK=new MenentukanBesarKecil();

MBK.setNilai(n);

lhasil1.setText("Nilai Terbesar : "+String.valueOf(MBK.getHasil(1)));

lhasil2.setText("Nilai Terkecil : "+String.valueOf(MBK.getHasil(2)));

private void vNActionPerformed(java.awt.event.ActionEvent evt) {

// TODO add your handling code here:

/**
* @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(FormBesarKecil.class.getName()).log(java.util.logging.Level.SEVERE,
null, ex);

} catch (InstantiationException ex) {

java.util.logging.Logger.getLogger(FormBesarKecil.class.getName()).log(java.util.logging.Level.SEVERE,
null, ex);

} catch (IllegalAccessException ex) {

java.util.logging.Logger.getLogger(FormBesarKecil.class.getName()).log(java.util.logging.Level.SEVERE,
null, ex);

} catch (javax.swing.UnsupportedLookAndFeelException ex) {

java.util.logging.Logger.getLogger(FormBesarKecil.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 FormBesarKecil().setVisible(true);

});

// Variables declaration - do not modify

private javax.swing.JButton jButton1;

private javax.swing.JLabel jLabel1;

private javax.swing.JLabel jLabel4;

private javax.swing.JLabel lhasil1;

private javax.swing.JLabel lhasil2;

private javax.swing.JTextField vN;

// End of variables declaration

You might also like