Revisi Tugas

 
Buatlah cecking eror untuk mengecek inputan dan inputan harus angka selain itu program akan menampilkan pesan eror dan akan meminta inputan lagi dari user, sedangkan inputannya itu berupa JOPtionpane…!!!!
 
Source codenya:
 
package pratikum5;
import javax.swing.JOptionPane;

 

public class Addition {

int number1, number2;

String firstNumber,secondNumber;

 

 

public void inputan() {

try{

firstNumber = JOptionPane.showInputDialog( null,”Press first integer”,”inputan”,JOptionPane.QUESTION_MESSAGE);

secondNumber = JOptionPane.showInputDialog( “Press second integer” );

number1 = Integer.parseInt( firstNumber );

number2 = Integer.parseInt( secondNumber );

 

int sum = number1 + number2;

JOptionPane.showMessageDialog( null, “The sum is ” + sum,

“Sum of Two Integers”, JOptionPane.QUESTION_MESSAGE);

int a = JOptionPane.showConfirmDialog(null,”pilih yang mana ??”);

System.out.println(“nilai dari confirm dialog = “+a);

}

catch(NumberFormatException x){

JOptionPane.showMessageDialog(null,”please input your number and not character”,”Warning”,JOptionPane.ERROR_MESSAGE);

inputan();

}

}

public static void main(String[] args) {

Addition oi= new Addition();

oi.inputan();

}

}

 

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s