Sunteți pe pagina 1din 14

1. Concatenate two text entries and display the result.

//code for RESULT button

String S1=jTextField1.getText();

String S2=jTextField2.getText();

jTextField3.setText(S1+S2);

2.Perform a Simple arithmetic operation(+,-,*,/) and display the result in Message Dialog.

1
//code for Add button
double a,b,result;
a=Double.parseDouble(jTextField1.getText());
b=Double.parseDouble(jTextField2.getText());
result=a+b;
JOptionPane.showMessageDialog(this, Addition of two numbers is:"+result);

//code for Sub button


double a,b,result;
a=Double.parseDouble(jTextField1.getText());
b=Double.parseDouble(jTextField2.getText());
result=a-b;
JOptionPane.showMessageDialog(this, "Subtract of two numbers is:"+result);
//code for Mul button
double a,b,result;
a=Double.parseDouble(jTextField1.getText());
b=Double.parseDouble(jTextField2.getText());
result=a*b;
JOptionPane.showMessageDialog(this, "Multiply of two numbers is:"+result);
//code for Div button
double a,b,result;
a=Double.parseDouble(jTextField1.getText());A
b=Double.parseDouble(jTextField2.getText());
result=a/b;
JOptionPane.showMessageDialog(this, "divide of two numbers is:"+result);
//code for clear
jTextField1.setText( );
jTextField2.setText( );
jTextField3.setText( );
//code for exit
System.exit(0);

3.Design a GUI application.The Customer is given a discount on the Bill Amount depending upon the Customer Type
selected from the combo box.Discount is calculated as follows:
Customer Type Discount
Paltinum 30%
Gold 20%
Silver 10%
New Customer NoDiscount

2
//code for discount
double finalamount=0;
double billamount=Double.parseDouble(jTextField1.getText());
switch(jComboBox1.getSelectedIndex())
{
case 0 : finalamount=0.70*billamount;break;
case 1 : finalamount=0.80*billamount;break;

case 2 : finalamount=0.90*billamount;break;
default:finalamount=billamount;

}
jTextField2.setText(Double.toString(finalamount));

//code for stop


System.exit(0);

4.Create a GUI application to perform both arithmetic and logical operation together(Example-Total,Average and
Grade calculation for given Marks)

3
//code for total
double total = 0,cs,e,gk,avg;
cs=Double.parsedouble(jTextField1.getText());
e= Double.parsedouble (jTextField2.getText());

gk= Double.parsedouble (jTextField3.getText());

total=cs+e+gk;
jTextField4.setText(Double.toString(total)); }
//code for Avg
int total,avg;
total= Double.parsedouble (jTextField4.getText());
avg=total/3;
jTextField5.setText(Double.toString(avg));

//code for grade


int avg;
avg= Double.parsedouble (jTextField5.getText());
if(avg>=90)
jTextField6.setText("A");
else

if(avg>=75)

jTextField6.setText("B");
else
if(avg>=60)
4
jTextField6.setText("c");
else
if (avg>=50)
jTextField6.setText("D");
else
jTextField6.setText("E");

//code for eixt


System.exit(0);

5.Create a GUI applicatiomn to perform an operation based on the criteria input by the user in a CheckBox or a
RadioButton:
EX:-An electronic Shop has announced the following seasonal discounts on the purchase of certain items:
Purchase Amount In Rs Discount on TV Discount Music System
0-25000 5% 10%
25001-50000 10% 20%
More than 50000 15% 30%
Develop an application based on the above criteria,to input amount of purchase and the type of purchase(TV or Music
System using Jradio Button) by a customer.
Compute and print the net amount to be paid by a customer along with his name accepted in a text field.
[Hint: Discount=(Discount rate/100)*Amount of purchase
Net amount=amount of purchase-discount).]

5
//code for Calculate Button
double amt,total=0;
String n;
int d=0;
n=jTextField1.getText();

amt=Double.parseDouble(jTextField2.getText());
if(jRadioButton1.isSelected())
{
if(amt>+0 && amt<=25000)
d=5;
else if(amt>25001 && amt<=50000)
d=10;
else
d=15;
}
else if(jRadioButton2.isSelected())
{
if(amt>0 && amt<=25000)
d=10;
else if(amt>25001 && amt<=50000)
d=20;
else
d=30;
}
else JOptionPane.showMessageDialog(this,"Please select any one RadioButton");
if(jCheckBox1.isSelected())
d=d+5;
total=amt-amt*d/100;
jTextArea1.append("name :"+n);
jTextArea1.append("\nAmount :"+amt);
jTextArea1.append("\nTotal :"+total);

6.Design a GUI application for Reverse number.

//code for reverse


6
int n,r,sum=0,x;
n=Integer.parseInt(jTextField1.getText());
x=n;

while (n!=0)
{
r=n%10;
sum=sum*10+r;
n=n/10;

}
jLabel2.setText("reverse of"+x+"is");
jTextField2.setText(" "+sum);

7.Desgin an GUI application for using Multiple Check Boxes and Combo Box,The sports and there charges are shown
in the following table:-
Sport name Charges
Foot Ball 2500
Cricket 3000
Table Tennis 3500

//CODE FOR CHARGES


int pno;String city="";
String n=jTextField1.getText();
pno=Integer.parseInt(jTextField2.getText());
double a=0;
if(jCheckBox1.isSelected())
{
jTextField3.setText("2500");
a=a+2500; }
if(jCheckBox2.isSelected())
{
7
jTextField4.setText("3000");
a=a+3000;}
if(jCheckBox3.isSelected())
{ jTextField5.setText("3500");
a=a+3500;}
if(jComboBox1.getSelectedIndex()==0)
{
city="BANGALURE";
}
if(jComboBox1.getSelectedIndex()==1)

{
city="MUMBAI";
}
if(jComboBox1.getSelectedIndex()==2)
{
city="CHENNAI";
}
jTextArea1.append("CUSTOMER NAME:"+n);
jTextArea1.append("\nCUSTOMER PHONENO: "+pno);
jTextArea1.append("\nTOTAL CHARGES: "+a);
jTextArea1.append("\nCITY: "+city);
}

8.Develop an application to check whether a given year is Leap year or not. Leap
year are those years which are not exactly divisible by 100 and exactly divisible by
400 or exactly divisible by 4 only.

//code for Check

Int year=Integer.parseInt(jTextField1.getText());

If((year%4==0) && (year%100!=0 || year%400==0))

8
jTextField2.setText(year+is a leap Year);

else

jTextField2.setText(year+is Not a leap Year);

//code for Close

System.exit(0);

9.Develop a Table Generator Application which calculates and prints a table of


given number.

//code for Generate

Int n=Integer.parseInt(jTextField1.getText());

Int I,j;

String str=;

for(i=1;i<=10;i++)

{ j=n*I;

str=str+j+ ; }

jTextField2.setText((i);

10. Develop a Login screen as given below. A Message dialog with relevant
message is appears as per given valid or invalid password .The valid password is
abcd.

9
//code for Login
String s1=jTextField1.getText();
String s2=jPasswordField1.getText();
if(s2.equals("abcd"))
JOptionPane.showMessageDialog(this, "U HAVE LOGGED SUCCESSFUL");
else
JOptionPane.showMessageDialog(this, "IN VAILED PASSWORD");

11.To display the given text in selected color using List control.

//code for jList1ValueChanged

String c;

String t=jTextField1.getText();

If(jList1.isSelectedIndex(0)==true)
10
c=RED;

jTextField3.setForeground(Color.RED); }

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

{ c="GREEN";

jTextField3.setForeground(Color.GREEN)

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

{ c="BLUE";

jTextField3.setForeground(Color.BLUE); }

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

c="ORANGE";

jTextField3.setForeground(Color.ORANGE); }

jTextField2.setText(c);

jTextField3.setText(t);

12. Consider the following table named "Employee".

Empno Ename Job Mgr Hiredate Sal Comm Deptno


8369 Smith Clerk 8902 1990-12-18 800.00 Null 20
8499 Anya Salesman 8698 1991-02-20 1600.00 300.00 30
8521 Seth Salesman 8698 1991-02-22 1250.00 500.00 30
8566 Mahadevan Manager 8839 1991-04-02 2985.00 Null 20
8654 Momin Salesman 8698 1991-09-28 1250.00 1400.00 30
8698 Bina Manager 8839 1991-05-01 2850.00 Null 30
8882 Shivanh Manager 8839 1991-06-09 2450.00 Null 10
8888 Scott Analyst 8566 1992-12-09 3000.00 Null 20
8839 Amir President Null 1991-11-18 5000.00 Null 10
8844 Kuldeep Salesman 8698 1991-09-08 1500.00 0.00 30

11
Consider the Empl table and write SQL command to get the following.

1.Create the employee table with columns as shown in the above table.

2.Add a new row with appropriate data values in employee table.

3.Change the job name salesman to Marketing everywhere in the table.

4.Write a query to display EName and Sal of employee whose salary are greater than or
equal to 2200?

5.Write a query to display details of employee who are not getting commission?

6.Write a query to display employee name and salary of those employee who dont have
their salary in range of 2500 to 4000?

7.Write a query to display the name of employee whose name contains M as First and L as
third alphabet?

8.Write a query to display the name of employee whose length of of ename is 5.

9.Write a query to display the details of employee whose dayname of hiredate is tuesday.

10 .Increase the salary by 10% whose salary is less than 2000.

11.Displays the salary truncated to integer value(no decimal digits) of all the items.

13. Consider the following table named "products".

Prcode Pname Unitprice Manufacturer Date_Purchase


P101 Cross trainer 25000 Avonfitness 2010-02-01
P102 Treadmill 32000 Agfitline 2010-03-09
P103 Massagechair 20000 Fitexpress 2010-03-11
P104 Vibration trainer 22000 Avon fitness 2010-01-15
P105 Bike 13000 fitexpress 2011-08-10

1. Create the products table with column as shown in the above table .
2. Display the names of all the products in the store.
3. Display the names and unit price of all the products in the store
4. Display the names of all the products with unit price less than Rs.20000.00
5. Display the names of all the products whose names is not null.
6. Display all rows sorted in descending order of unit price.
7. Add one more column name as Quantity of the products table.
8. Change the Unit Price data of all the rows by applying a 10% discount
reduction on all the products.

12
9. Display details of all products with manufacturer name starting with "A"
10. Display the names and unitprice of all products whose unitprice is lessthan 22000 and manufactures is Fitness.
11. Display the all products who name has 4 letters.
12. Display names of all products that were purchased on Mondays or Tuesdays .
14. Create the following table named "Charity" and write SQL queries for the tasks
that follow:

Table: Charity

P_Id LastName FirstName Address City Contribution


1 Bindra Jaspreet 5B, Gomti Nagar Lucknow 3500.50
2 Rana Monica 21A, Bandra Mumbai 2768.00
3 Singh Jatinder 8, Punjabi singh Delhi 2000.50
4 Arora Satinder K/1, Shere Punjab Mumbai 1900.00
Colony
5 Krishnan Vineeta A-75, Adarsh Nagar NULL NULL

I. I. Display all first names in lowercase


II. Display all last names of people of Mumbai city in uppercase
III. Display Person Id along with First 3 characters of his/her name.
IV. Display first name concatenated with last name for all the employees.
V. Display length of address along with Person Id
VI. Display last 2 characters of City and Person ID.
VII. Display Last Names and First names of people who have "at" in the second or
third position in their first names.
VIII. Display the position of 'a' in Last name in every row.
IX. Display Last Name and First name of people who have "a" as the last character
in their First names.
X. Display the first name and last name concatenated after removing the leadingand trailing blanks.
XI. Display Person Id, last names and contribution rounded to the nearest rupeeof all the persons.
XII. Display Person Id, last name and contribution with decimal digits truncatedof all the persons.
XIII. Display Last name, contribution and a third column which has contributiondivided by 10. Round it
to two decimal points.

KEY FOR SQL QUERIES:-

12. I .CREATE TABLE EMPLOYEE(EMPNO INT,ENAME VARCHAR(20),JOB VARCHAR(20),MGR INT,HIREDATE DATE,SAL


DECIMAL(6,2),COMN DECIMAL(6,2),DEPTNO INT);

13
II. INSERT INTO EMPLOYEE VALUES(8845,XXXXX,SALESMAN,8699,1991-11-22,1600,NULL,30);
III. UPDATE EMPLOYEE SET WHERE JOB=MARKETING WHERE JOB=SALESMAN;
IV.SELECT ENAME,SAL FROM EMPLOYEE WHERE SAL>=2200;
V. SELECT *FROM EMPLOYEE WHERE COMM IS NULL;
VI. SELECT ENAME,SAL FROM EMPLOYEE WHERE SAL NOT BETWEEN 2500 AND 4000;
VII.SELECT ENAME FROM EMPLOYEE WHERE ENAME LIKE M__L%;
VIII.SELECT ENAME FROM EMPLOYEE where LENGTH(ename)=5;
IX. SELECT *FROM EMPOLYEE WHERE DAYNAME(HIREDATE)=TUESDAY;
X. UPDATE EMPLOYEE SET SAL=SAL+10 WHERE SAL<2000;
XI.SELECT SAL,TRUNCAT(SAL,0) FROM EMPLOYEE;
12.I. CREATE TABLE PRODUCT(PRCODE VARCHAR(10),PNAME VARCHAR(20),UNITPRICE INT,MANUFACTURE
VARCHAR(20),DATE_PURCHASE DATE);
II.SELECT PNAME FROM PRODUCTS;
III.SELECT PNAME,UNITPRICE FROM PRODEUCT;
IV.SELECT PNAME FROM PRODUCT WHERE UNITPRICE<20000;
V.SELECT PNAME FROM PRODUCTS WHERE PNAME IS NOT NULL;
VI.SELECT *FROM PRODUCTS ORDER BY UNITPRICE DESC;
VII.ALTER TABLE PRODUCTS ADD QUANTITY INT;
VIII.UPDATE PRODUCT SET UNITPRICE=UNITPRICE-UNITPRICE*10;
IX.SELECT *FROM PRODUCTS WHERE MANUFACTURER LIKEA%;
X.SELECT PNAME,UNITPRICE FROM PRODUCTS WHERE UNITPRICES<22000 && MANUFACTURER=FITNESS;
XI.SELECT *FROM PRODUCTS WHERE PNAME LIKE____;
XII.SELECT PNAME FROM PRODUCTS WHERE DAYNAME(DATE_PURCHASES)=MONDAY OR
DAYNAME(DATE_PURCHASES)=TUESDAY;

14 I.SELECT LOWER(FIRSTNAME) FROM CHARITY;


II.SELECT UPPER(LASTNAME) FROM CHARITY WHERE CITY=MUMBAI;
III.SELECT P_ID,SUBSTR(CONCAT(FIRSTNAME,LASTNAME),1,3) FROM CHARITY;
IV.SELECT CONCAT(FIRSTNAME,LASTNAME) FROM CHARITY;
V.SELECT P_ID,LENGTH(ADDRESS) FROM CHARITY;
VI.SELECT P_ID,SUBSTR(CITY,-2) FROM CHARITY;
VII.SELECT LASTNAME,FIRSTNAME FROM CHARITY WHERE SUBSTR(FIRSTNAME)=AT OR
SUBSTR(FIRSTNAME,3,2)=AT;
VIII.SELECT INSTR(LASTNAME,A) FROM CHARITY;
IX.SELECT LASTNAME,FIRSTNAME FROM CHAITY WHERE SUBSTR(FIRSTNAME,-1)=A;
OR
SELECT LASTNAME,FIRSTNAME FROM CHARITY WHERE RIGHT (FIRSTNAME,1)=A;
X.SELECT TRIM(CONCAT(FIRSTNAME,LASTNAME)) FROM CHARITY;
XI.SELECT P_ID,LASTNAME,ROUND(CONTRIBUTION) FROM CHARITY;
XII.SELECT P_ID,LASTNAME,TRUNCATE,ROUND(CONTRIBUTION/10,2) FROM CHARITY;

14

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