Ch3 XII Solutions
Ch3 XII Solutions
1. Design a GUI application in which the user enters a number in the text field and on
clicking the button the sum of the digits of the number should be displayed in a label.
Hint : Suppose user enters 123 the output should be 6(1+2+3).
A) Design;
2. Design a GUI application to accept a String from the user in a text field and print using
JOptionPane whether it is a palindrome or not. Hint ABBA is a palindrome.
A) Design;
3. Design a GUI application to accept the cost price and selling price form the user in two
text fields then calculate the profit or loss incurred.
A) Design;
Output;
4. Design a GUI application to accept a character in a text field and print in a label if that
character is a vowel: a, e, i, o, or u. The application should be case sensitive.
A) Design view;
Coding for jButton1 (“Check if it is a vowel”);
String in;
in=jTextField1.getText();
switch (in){
case "a":
case "e":
case "i":
case "o":
case "u":
case "A":
case "E":
case "I":
case "O":
case "U":
jLabel4.setText(in+" is a vowel.");
break;
default:
jLabel4.setText(in+" is not a vowel. It is a consonent.");}
}
Output;
5. Design a GUI application that repeatedly accepts numbers in a JOptionPane and once
the typed number is 0 the maximum and minimum of all numbers typed are displayed.
A)
6. Design a GUI application in java to convert temperature from Celsius to Fahrenheit or
vice versa using radio buttons and two text fields.
A) Design view;
Output;
7. Design a GUI application in java to convert kilograms into grams, litres into milliliters,
rupees into paisa using combobox and text fields.
A)
Coding for jButton1 (‘Convert now’);
double in,r;
in=Double.parseDouble(jTextField1.getText());
r=0;
if (jComboBox1.getSelectedItem().equals("Kilograms to grams")){
r=in*1000;}
if (jComboBox1.getSelectedItem().equals("Litres to mililitres")){
r=in*1000;}
if (jComboBox1.getSelectedItem().equals("Rupees to paisa (INR)")){
r=in*100;}
jTextField2.setText(Double.toString(+r));
Output;
A)