0% found this document useful (0 votes)
34 views63 pages

Home Work

The document contains code snippets that demonstrate the use of conditional (if-else) statements in Java to evaluate conditions and display corresponding outputs. The code samples show evaluating numeric inputs from text fields to display day of week, eligibility status, temperature readings and more by comparing the values using relational and logical operators in if-else blocks.

Uploaded by

Aabhaas Gupta
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
34 views63 pages

Home Work

The document contains code snippets that demonstrate the use of conditional (if-else) statements in Java to evaluate conditions and display corresponding outputs. The code samples show evaluating numeric inputs from text fields to display day of week, eligibility status, temperature readings and more by comparing the values using relational and logical operators in if-else blocks.

Uploaded by

Aabhaas Gupta
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 63

Pg_60_W_4_1

float a=Float.parseFloat(jTextField1.getText());
float b=Float.parseFloat(jTextField2.getText());
float c=a+b;
jLabel4.setText(""+c);

float a=Float.parseFloat(jTextField1.getText());
float b=Float.parseFloat(jTextField2.getText());
float c=a-b;
jLabel4.setText(""+c);

float a=Float.parseFloat(jTextField1.getText());
float b=Float.parseFloat(jTextField2.getText());
float c=a*b;
jLabel4.setText(""+c);

float a=Float.parseFloat(jTextField1.getText());
float b=Float.parseFloat(jTextField2.getText());
float c=a/b;
jLabel4.setText(""+c);

float a=Float.parseFloat(jTextField1.getText());
float b=Float.parseFloat(jTextField2.getText());
float c=a%b;
jLabel4.setText(""+c);

--------------------------------------END OF QUESTION------------------------------------

Pg_115_Q_14

float a=Float.parseFloat(jTextField1.getText());
float b=Float.parseFloat(jTextField2.getText());
float c=a+b;
jLabel4.setText(""+c);

--------------------------------------END OF QUESTION------------------------------------

Pg_118_Q_9

int a=Integer.parseInt(jTextField1.getText());
int b=a+11;
jLabel2.setText("Your age in 2021 will be "+ b);

--------------------------------------END OF QUESTION------------------------------------

Pg_135_Eg_4_1

int hoursworked=Integer.parseInt(jTextField1.getText());
float payrate=Float.parseFloat(jTextField2.getText());
float taxrate=Float.parseFloat(jTextField3.getText());
float paymentamount = payrate * hoursworked;
float taxamount = paymentamount * taxrate;
jLabel7.setText(""+paymentamount); jLabel8.setText(""+taxamount);

--------------------------------------END OF QUESTION------------------------------------

Pg_151_Eg_4_4

float a=Float.parseFloat(jTextField1.getText());
float b=Float.parseFloat(jTextField2.getText());
float c=Float.parseFloat(jTextField3.getText());
int d;
if(a>b) {
if(a>c) {
jLabel7.setText(""+a);
} else {
jLabel7.setText(""+c);
}
}

else if(b>a)

{
if(b>c)
{
jLabel7.setText(""+b);
}

else

jLabel7.setText(""+c); }

--------------------------------------END OF QUESTION------------------------------------

Pg_168_Q_21

jLabel2.setText(""+jTextField1.getText());

jTextField1.setText("");
jLabel2.setText("");

--------------------------------------END OF QUESTION------------------------------------

Pg_176_Eg_5_2

int a=Integer.parseInt(jTextField1.getText());
if(a>=18)
{
jLabel2.setText("You are an eligible voter");

// TODO add your handling code here:

else
{
jLabel2.setText("You are not an eligible voter");
}

--------------------------------------END OF QUESTION------------------------------------

Pg_177_P_1

int hoursworked=Integer.parseInt(jTextField1.getText());
float payrate=Float.parseFloat(jTextField2.getText());
float taxrate=Float.parseFloat(jTextField3.getText());
float paymentamount = payrate * hoursworked;
float taxamount = paymentamount * taxrate;
jLabel7.setText(""+paymentamount);
jLabel8.setText(""+taxamount);

--------------------------------------END OF QUESTION------------------------------------

Pg_178_Eg_5_3

float a=Float.parseFloat(jTextField1.getText());
if(a>0)
{

jLabel2.setText("The Number is Positive");

}
else if(a<0)
{
jLabel2.setText("The Number is Negative");
}
else
{
jLabel2.setText("The Number is Zero");
}

--------------------------------------END OF QUESTION------------------------------------

Pg_179_Eg_5_4

int a=Integer.parseInt(jTextField1.getText());
if(a>=18)
{
jLabel2.setText("You are an eligible voter");

// TODO add your handling code here:

else
{
jLabel2.setText("You are not an eligible voter");
}

--------------------------------------END OF QUESTION------------------------------------

Pg_179_Eg_5_5

float a=Float.parseFloat(jTextField1.getText());
float b=Float.parseFloat(jTextField2.getText());
double r;
double n;

if(a>=10000)
{
jLabel6.setText("6%");
r=0.06;
n=a*b*r;
jLabel5.setText(""+n);

}
else
{
jLabel6.setText("5%");
r=0.05;
n=a*b*r;
jLabel5.setText(""+n); }

--------------------------------------END OF QUESTION------------------------------------

Pg_181_P_5_2

int a=Integer.parseInt(jTextField1.getText());
if(a==100)
{
jLabel3.setText("You are right. It is 100 C");
}
else jLabel3.setText("No it is 100 C");

--------------------------------------END OF QUESTION------------------------------------

Pg_182_Eg_5-6

float a=Float.parseFloat(jTextField1.getText());
if(a>0) {
jLabel2.setText("The Number is Positive");
}

else if(a<0) {
jLabel2.setText("The Number is Negative");
}

Else {
jLabel2.setText("The Number is Zero");}

--------------------------------------END OF QUESTION-----------------------------------

Pg_183_Eg_5_7

int a=Integer.parseInt(jTextField1.getText());
if(a==1)
{
jLabel2.setText("Sunday");
}
else if(a==2)
{
jLabel2.setText("Monday");
}else if(a==3) {
jLabel2.setText("Tuesday");
}else if(a==4) {
jLabel2.setText("Wednesday");
}else if(a==5) {
jLabel2.setText("Thursday");
}else if(a==6) {
jLabel2.setText("Friday");
} else if(a==7) {
jLabel2.setText("Saturday");
} Else {
jLabel2.setText("No such day"); }

--------------------------------------END OF QUESTION-----------------------------------

Pg_184_Eg_5_8

int a=Integer.parseInt(jTextField1.getText());
if(a==0)
{jLabel3.setText("Zero");// TODO add your handling code here:
}
else if(a==1)
{jLabel3.setText("One");// TODO add your handling code here:
}

else if(a==2)
{jLabel3.setText("Two");// TODO add your handling code here:
}
else if(a==3)
{jLabel3.setText("Three");// TODO add your handling code here:
}
else if(a==4)
{jLabel3.setText("Four");// TODO add your handling code here:

}
else if(a==5)
{jLabel3.setText("Five");// TODO add your handling code here:
}else if(a==6)
{jLabel3.setText("Six");// TODO add your handling code here:
}else if(a==7)
{jLabel3.setText("Seven");// TODO add your handling code here:
}
else if(a==8)
{jLabel3.setText("Eight");// TODO add your handling code here:
}
else if(a==9)
{jLabel3.setText("Nine");// TODO add your handling code here:
}

--------------------------------------END OF QUESTION-----------------------------------

Pg_186_P_5_3

int a=Integer.parseInt(jTextField1.getText());
double rate=0;
if(a>30001)
{
rate=0.15;
}
if(a>22001 && a<30001)
{
rate=0.10;
}
if(a>12001 && a<22001)
{
rate=0.07;
}
if(a>5001 && a<12001)

{
rate=0.03;
}
if(a>0 && a<5001)
{
rate=0.00;
}
double b=a*rate;
jLabel3.setText(""+b);

--------------------------------------END OF QUESTION-----------------------------------

Pg_188_W_5_1

double a=Double.parseDouble(jTextField1.getText());
if(a>32)
{
jLabel3.setText("This temprature is not freezing");

}
else
{
jLabel3.setText("This temprature is freezing");

double a=Double.parseDouble(jTextField1.getText());
if(a>0)
{
jLabel3.setText("This temprature is not freezing");

}
else
{
jLabel3.setText("This temprature is freezing");
}

--------------------------------------END OF QUESTION-----------------------------------

Pg_192_Eg_5_9

int a=Integer.parseInt(jTextField1.getText());
if(a==1)
{
jLabel2.setText("Sunday");
}
else if(a==2)
{
jLabel2.setText("Monday");
}else if(a==3) {
jLabel2.setText("Tuesday");
}else if(a==4) {
jLabel2.setText("Wednesday");
}else if(a==5) {
jLabel2.setText("Thursday");
}else if(a==6) {
jLabel2.setText("Friday");
} else if(a==7) {
jLabel2.setText("Saturday");
} Else {
jLabel2.setText("No such day"); }

--------------------------------------END OF QUESTION-----------------------------------

Pg_192_W_5_2

int a=Integer.parseInt(jTextField1.getText());
int b=Integer.parseInt(jTextField2.getText());
int c=Integer.parseInt(jTextField3.getText());// TODO add your handling code here:
if(((b==1 || b==3 || b==5 || b==7 || b==8 || b==10 || b==12) && a>31)|| (b==2 && a>28) || ((b==4 ||
b==6 || b==9 || b==11) && a>30))
{
jLabel5.setText("Invalid Date");
}
else{
switch(b)
{
case 1:jLabel5.setText(""+a+"-"+"JAN"+"-"+c);break;
case 2:jLabel5.setText(""+a+"-"+"FEB"+"-"+c);break;
case 3:jLabel5.setText(""+a+"-"+"MAR"+"-"+c);break;
case 4:jLabel5.setText(""+a+"-"+"APR"+"-"+c);break;
case 5:jLabel5.setText(""+a+"-"+"MAY"+"-"+c);break;

case 6:jLabel5.setText(""+a+"-"+"JUN"+"-"+c);break;
case 7:jLabel5.setText(""+a+"-"+"JUL"+"-"+c);break;
case 8:jLabel5.setText(""+a+"-"+"AUG"+"-"+c);break;
case 9:jLabel5.setText(""+a+"-"+"SEP"+"-"+c);break;
case 10:jLabel5.setText(""+a+"-"+"OCT"+"-"+c);break;
case 11:jLabel5.setText(""+a+"-"+"NOV"+"-"+c);break;
case 12:jLabel5.setText(""+a+"-"+"DEC"+"-"+c);break;
default:jLabel5.setText("Invalid Date");break;
}

--------------------------------------END OF QUESTION-----------------------------------

Pg_198_Q_4

float a=Float.parseFloat(jTextField1.getText());
float b=Float.parseFloat(jTextField2.getText());
float c=Float.parseFloat(jTextField3.getText());
float d=a*b*c;
jLabel6.setText(""+d);

--------------------------------------END OF QUESTION-----------------------------------

Pg_199_P_5_4

int a=Integer.parseInt(jTextField1.getText());
int b=0;

switch(a)
{
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12: b=31;break;
case 4:
case 6:
case 9:
case 11:b=30;break;
case 2:b=28;
break;

default:break;
}
if(b==0)
{
jLabel3.setText("Invalid Month");
}
else
{
jLabel3.setText(""+b+" Days.");
}

--------------------------------------END OF QUESTION-----------------------------------

Pg_200_W_5_3

float a=Float.parseFloat(jTextField1.getText());
float b=Float.parseFloat(jTextField2.getText());
double r;
double n;

if(b<=7)
{
jLabel6.setText("7%");
r=0.07;
n=a*b*r;
jLabel5.setText(""+n);

}
else if(b<=10 && b>7)
{
jLabel6.setText("8.5%");

r=0.085;
n=a*b*r;
jLabel5.setText(""+n);

}
else if(b<=15 && b>10)
{
jLabel6.setText("9.5%");
r=0.095;
n=a*b*r;
jLabel5.setText(""+n);

}
else if(b>=15)
{
jLabel6.setText("12.5%");
r=0.125;
n=a*b*r;
jLabel5.setText(""+n);

--------------------------------------END OF QUESTION-----------------------------------

Pg_235_Q_22

double a=Double.parseDouble(jTextField1.getText());
double b;
double c;
b=0.1*a;
c=a-b;
if(a<1000)
{
jLabel4.setText("0");
jLabel6.setText(""+a);

}
else
{
jLabel4.setText(""+b);
jLabel6.setText(""+c);
}

--------------------------------------END OF QUESTION-----------------------------------

Pg_236_Q_23

int a=Integer.parseInt(jTextField1.getText());
if(a==0)
{jLabel3.setText("Zero");// TODO add your handling code here:
}
else if(a==1)
{jLabel3.setText("One");// TODO add your handling code here:
}

else if(a==2)
{jLabel3.setText("Two");// TODO add your handling code here:
}
else if(a==3)
{jLabel3.setText("Three");// TODO add your handling code here:
}
else if(a==4)
{jLabel3.setText("Four");// TODO add your handling code here:

}
else if(a==5)
{jLabel3.setText("Five");// TODO add your handling code here:
}else if(a==6)
{jLabel3.setText("Six");// TODO add your handling code here:
}else if(a==7)
{jLabel3.setText("Seven");// TODO add your handling code here:
}
else if(a==8)
{jLabel3.setText("Eight");// TODO add your handling code here:
}
else if(a==9)
{jLabel3.setText("Nine");// TODO add your handling code here:
}

--------------------------------------END OF QUESTION-----------------------------------

Pg_243_Q_1

int a=Integer.parseInt(jTextField1.getText());
if(a==1)
{
jLabel2.setText("Sunday");
}
else if(a==2)
{
jLabel2.setText("Monday");
}else if(a==3) {
jLabel2.setText("Tuesday");
}else if(a==4) {
jLabel2.setText("Wednesday");
}else if(a==5) {
jLabel2.setText("Thursday");
}else if(a==6) {
jLabel2.setText("Friday");
} else if(a==7) {
jLabel2.setText("Saturday");
} Else {
jLabel2.setText("No such day"); }

--------------------------------------END OF QUESTION-----------------------------------

Pg_243_Q_2

double a=Double.parseDouble(jTextField1.getText());
double b=Double.parseDouble(jTextField2.getText());
if(a>b)
{
jLabel4.setText("The First number is larger");
}
else
{
jLabel4.setText("The Second number is larger");
}

double c=Double.parseDouble(jTextField3.getText());
if(c>=0.0 && c<=4.0)
{
jLabel7.setText("This is a valid grade.");

}
else
{
jLabel7.setText("This is not a valid grade.");
}

--------------------------------------END OF QUESTION-----------------------------------

Pg_244_Q_4

float a=Float.parseFloat(jTextField1.getText());
if(a>=90 && a<=100)
{
jLabel2.setText("Your grade is A++.");
// TODO add your handling code here:
}
else if(a>=80 && a<90)
{
jLabel2.setText("Your grade is A+.");
// TODO add your handling code here:
}
else if(a>=70 && a<80)
{
jLabel2.setText("Your grade is A.");
// TODO add your handling code here:
}
else if(a>=60 && a<70)

{
jLabel2.setText("Your grade is B.");
// TODO add your handling code here:
}
else if(a>=50 && a<60)
{
jLabel2.setText("Your grade is C.");
// TODO add your handling code here:
}
else if(a>=40 && a<50)
{
jLabel2.setText("Your grade is D.");
// TODO add your handling code here:
}
else if(a<=40 && a>=0)
{
jLabel2.setText("Sorry you have failed.");
// TODO add your handling code here:
}

else
{
jLabel2.setText("Sorry you Mistyped.");
// TODO add your handling code here:
}

--------------------------------------END OF QUESTION-----------------------------------

Pg_280_W_6_1

jTextArea1.setText("");
jLabel3.setIcon(new ImageIcon("C:\\Users\\Aayushi
Gupta\\Documents\\NetBeansProjects\\Project\\Pics\\kboard.png"));
jLabel2.setText("My new keyboard 110 keys, with one year warranty.");
jTextArea1.append('\n'+"

Offer available"+'\n');

jTextArea1.append("----------------------------------------------------------------------"+'\n');
jTextArea1.append("Offer Price

:Rs 400/-"+'\n');

jTextArea1.append("Maximum Retail Price :Rs 500/-");

jTextArea1.setText("");
jLabel3.setIcon(new ImageIcon("C:\\Users\\Aayushi
Gupta\\Documents\\NetBeansProjects\\Project\\Pics\\mouse.jpg"));
jLabel2.setText("USB 800 dpi Mouse with 5 buttonsand title wheel."+'\n');
jTextArea1.append('\n'+"

Offer available"+'\n');

jTextArea1.append("----------------------------------------------------------------------"+'\n');
jTextArea1.append("Offer Price

:Rs 845/-"+'\n');

jTextArea1.append("Maximum Retail Price :Rs 1000/-");


// TODO add your handling code here:
}

jTextArea1.setText("");
jLabel3.setIcon(new ImageIcon("C:\\Users\\Aayushi
Gupta\\Documents\\NetBeansProjects\\Project\\Pics\\monitor.jpg"));
jLabel2.setText("LCD 15',resolution upto 1280 x 1024; Contrast ratio 450:1."+'\n');
jTextArea1.append('\n'+"

Offer available"+'\n');

jTextArea1.append("----------------------------------------------------------------------"+'\n');
jTextArea1.append("Offer Price

:Rs 6000/-"+'\n');

jTextArea1.append("Maximum Retail Price :Rs 7500/-");


// TODO add your handling code here:
}

jTextArea1.setText("");
jLabel3.setIcon(new ImageIcon("C:\\Users\\Aayushi
Gupta\\Documents\\NetBeansProjects\\Project\\Pics\\printer.jpg"));
jLabel2.setText("USB laserjet xyz printer 32ppm with 1 year warranty."+'\n');
jTextArea1.append('\n'+"

Offer available"+'\n');

jTextArea1.append("----------------------------------------------------------------------"+'\n');
jTextArea1.append("Offer Price

:Rs 10200/-"+'\n');

jTextArea1.append("Maximum Retail Price :Rs 12499/-");


// TODO add your handling code here:
}

jTextArea1.setText("");
jLabel3.setIcon(new ImageIcon("C:\\Users\\Aayushi
Gupta\\Documents\\NetBeansProjects\\Project\\Pics\\modem.jpg"));
jLabel2.setText("USB modem with 1024 kbps download speed and 512 kbps upload speed."+'\n');
jTextArea1.append('\n'+"

Offer available"+'\n');

jTextArea1.append("----------------------------------------------------------------------"+'\n');
jTextArea1.append("Offer Price

:Rs 1200/-"+'\n');

jTextArea1.append("Maximum Retail Price :Rs 1490/-");


}

--------------------------------------END OF QUESTION-----------------------------------

Pg_188_Q_19

String name=jTextField1.getText();
jLabel2.setText("Hello "+ name+".");

String name1=jTextField1.getText();
jLabel2.setText("Bye "+ name1+".");

--------------------------------------END OF QUESTION-----------------------------------

Pg_290_Q_20

String title=jTextField1.getText();
String fname=jTextField2.getText();
String lname=jTextField3.getText();
jLabel4.setText("Happy Divali "+title+" "+fname+" "+lname);

--------------------------------------END OF QUESTION-----------------------------------

Pg_296_Q_9

jLabel2.setText("Non Resident Indian");

jLabel2.setText("Central Board of Secondary Education");

--------------------------------------END OF QUESTION-----------------------------------

Pg_306_W_7_1

--------------------------------------END OF QUESTION-----------------------------------

Pg_320_W_7_2

String pwd=new String(pwdPF.getPassword());


String name=UidTF.getText();
if(pwd.equals("my_password"))
{
msgLabel.setText(name +", you have loged in successfully");
}
else
{
msgLabel.setText(name +", you enterd invalid password.\n Either try again or leave.");
}
Alert.setVisible(true);

--------------------------------------END OF QUESTION-----------------------------------

You might also like