Sunteți pe pagina 1din 14

JAVA

CODING FOR PLUS:


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

// TODO add your handling code here:

l1.setText("+");

double num1=Double.parseDouble(t1.getText());

double num2=Double.parseDouble(t2.getText());

double num3 = num1 + num2;

t3.setText(""+num3);

CODING FOR MINUS:


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

// TODO add your handling code here:

l1.setText("-");

double num1=Double.parseDouble(t1.getText());
double num2=Double.parseDouble(t2.getText());

double num3 = num1 - num2;

t3.setText(""+num3);

CODING FOR MULTIPLICATION:


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

// TODO add your handling code here:

l1.setText("*");

double num1=Double.parseDouble(t1.getText());

double num2=Double.parseDouble(t2.getText());

double num3 = num1 * num2;

t3.setText(""+num3);

CODING FOR DIVISION:


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

// TODO add your handling code here:

l1.setText("/");

double num1=Double.parseDouble(t1.getText());

double num2=Double.parseDouble(t2.getText());

double num3 = num1 / num2;

t3.setText(""+num3);

CODING FOR %:
private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {

// TODO add your handling code here:

l1.setText("%");

double num1=Double.parseDouble(t1.getText());

double num2=Double.parseDouble(t2.getText());
double num3 = num1 % num2;

t3.setText(""+num3);

CODING FOR RADIO BUTTONS:


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

// TODO add your handling code here:

double r=0;

if(r1.isSelected())

r=10;

if(r2.isSelected())
r=5;

if(r3.isSelected())

r=8.5;

double amt, iamt;

amt=Double.parseDouble(t1.getText());

iamt=amt*r/100;

t2.setText(""+r);

t3.setText(""+iamt);

CODING FOR CALCULATE BUTTON:


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

// TODO add your handling code here:

double amt,iamt,disc = 0,net;

amt=Double.parseDouble(t1.getText());

if(amt<=1000000)

disc=0.20*amt/100;

if(amt>=1000000)

disc=0.25*amt/100;

iamt=Double.parseDouble(t3.getText());

iamt=iamt-disc;

net=amt+iamt;

t3.setText(""+iamt);

t4.setText(""+disc);

t5.setText(""+net);

}
CODING FOR CLOSE BUTTON:
private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {

// TODO add your handling code here:

t1.setText("");

t2.setText("");

t3.setText("");

t4.setText("");

t5.setText("");

r1.setSelected(false);

r2.setSelected(false);

r3.setSelected(false);

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

// TODO add your handling code here:

System.exit(0);

QUESTION 4: UNDERSTANDING AND USE OF NESTED LOOPS AND TEXT AREA


CONTROL. TASK: DEVELOP A JAVA APPLICATION TO PRINT A PATTERN FOR
GIVEN CHARACTER AND STEPS, AS PER GIVEN SCREEN SHOT.
OUTPUT:
CODING:
private void jButton1ActionPerformed(java.awt.event.ActionEvent
evt) {
// TODO add your handling code here:
String ch=jTextField1.getText();
int st=Integer.parseInt(jTextField2.getText());
for(int i=1;i<=st;i++) {
for (int j = 1; j <= i; j++) {
jTextArea1.append(ch); }
jTextArea1.append(""+'\n');
} }
5)

CODING:

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

//TODO add your handling code here:

String txt = Selection.getText();

String dur = (String)DaysCB.getSelectedItem( );

Selection.setText(txt +" \t Selected duration :" + dur);

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

// TODO add your handling code here:

String txt = (String) CityCB.getSelectedItem();

int i=0;

int length = CityCB.getItemCount();

boolean exists = false;


for (;i<length; ++i) {

String item = (String) CityCB.getItemAt(i);

if (item.equals(txt)){

exists = true;

break;

if (exists == false)

CityCB.addItem(txt);

Selection.setText("Selected city:" + txt);

6)
CODING:

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

// TODO add your handling code here:

int total=0;

if (jList1.isSelectedIndex(0)==true)

total=total+150;

JOptionPane.showMessageDialog(null,"PIZZA prize=150");

if (jList1.isSelectedIndex(1)==true)

total=total+99;

JOptionPane.showMessageDialog(null,"BURGER prize=99");

if (jList1.isSelectedIndex(2)==true)

{
total=total+49;

JOptionPane.showMessageDialog(null,"FRENCH FRIES prize=49");

if (jList1.isSelectedIndex(3)==true)

total=total+250;

JOptionPane.showMessageDialog(null,"RISE BOWL prize=250");

if (jList1.isSelectedIndex(4)==true)

total=total+45;

JOptionPane.showMessageDialog(null,"PEPSI prize=45");

if (jList1.isSelectedIndex(5)==true)

total=total+55;

JOptionPane.showMessageDialog(null,"Coke prize=55");

jTextField1.setText("The Total value is "+ total);

7)

S-ar putea să vă placă și