Professional Documents
Culture Documents
Design a GUI application having student details data form as shown below.
Code:
1
PROGRAM NO - 2
Design an application for a Football Match’s Scoreboard. Each team’s score should be
maintained. Whenever a team scores a goal, it should be reflected on the Scoreboard. When
the result is declared, depending upon the scoreboard, the winning team should be declared.
Code:
Double click on Declare Result button and write the following code…..
String res = (ga>gb ? "Team A wins" : (ga<gb) ? "Team B wins" : "Match Draw");
result.setText(res);
2
PROGRAM NO - 3
3
PROGRAM NO – 4
Design a special sale at a store, a 10% discount is taken on purchases over Rs. 1000/-. Write
a program that asks for the amount of purchases, then calculate the discounted price.
Code:
// Calculate Discount
//display result
4
PROGRAM NO - 5
Code:
5
PROGRAM NO - 6
Subtract , Multiplication, Divide, Mod BUTTONS copy and paste the same block of code
and change the desired operator to get the result.
Clear Button:
num1TF.setText(null);
num2TF.setText(null);
num3TF.setText(null);
Exit Button:
System.exit(0);
6
PROGRAM NO - 7
Design a GUI application having interface as having if statements check to find the largest of
3 numbers.
Code:
Double click on Find Largest button and write the following code…….
//setting output
largeResult.setText(""+max);
7
PROGRAM NO - 8
Design a GUI application interface for creating “multiplication table” of a given number.
Code:
output.setText("");
input.setText("");
8
PROGRAM NO - 9
Design a GUI application having interface, the loop for the frame should print numbers from
lowest to highest on the basis of given two numbers, upon clicking at “Count” button.
Code:
Double click on the Count Button and write the following code……..
Double click on the Reset Button and write the following code…….
startNumber.setText(null);
endNumber.setText(null);
textArea.setText(null);
Double click on the Exit Button and write the following code…….
System.exit(0);
9
PROGRAM NO - 10
Design a GUI application having interface for the percentage marks are to be entered in the
text box and upon clicking at the button, corresponding grade (as per the following rules)
should be displayed in the picture box below command button.
Marks % Grade
>=90 A++
80 – 90 A+
75 – 80 A
60 – 75 B
50 – 60 C
40 – 50 D
<40 Fail
Code:
Double click on Calculate Final Grade Button and write the following code…………..
int per = Integer.parseInt(TextField1.getText());
if(per>=90)
result.setText(" A++");
else if(per>=80 && per<90)
result.setText(" A+ ");
else if(per>=75 && per<80)
result.setText(" A ");
else if(per>=60 && per<75)
result.setText(" B ");
else if(per>=50 && per<60)
result.setText(" C ");
else if(per>=50 && per<60)
result.setText(" D ");
else
result.setText(" Fail ");
10
PROGRAM NO – 11
Design a GUI application that has a list and a few controls such as a Label, a button and a
text field. The list displays some colors. When a user selects a color from the list, the
background of the appropriate control (depending upon user’s choice) should be changed.
Code:
Since we need to work with colors, thus we need to import Color class of java.awt.
Thus, in the source editor, at the top of all the code, type…………….
import java.awt.Color;
int i;
Color x = Color.WHITE;
i = colorsLst.getSelectedIndex();
switch(i)
{
case 0: x = Color.RED;
break;
case 1: x = Color.BLUE;
break;
case 2: x = Color.GREEN;
break;
case 3: x = Color.MAGENTA;
break;
case 4: x = Color.CYAN;
break;
case 5: x = Color.YELLOW;
break;
case 6: x = Color.GRAY;
break;
}
11
if (lblChk.isSelected())
Lbl.setBackground(x);
else
Lbl.setBackground(Color.WHITE);
if(btnChk.isSelected())
Btn.setBackground(x);
else
Btn.setBackground(Color.WHITE);
if(tfChk.isSelected())
TF.setBackground(x);
else
TF.setBackground(Color.WHITE);
12
PROGRAM NO – 12
Design the GUI interface for the ComBox. The user should enter a city name in text field.
After entering the city name in the text field, when the user press a button to add city to
combox, the list of city names to be added to the combox.
Code:
Double click on the Add to Com Box button and the write the following code……………
13
PROGRAM NO - 13
Design a GUI application that obtains the price and quantity of an item, calculates the sale-
value, discount and net payable amount. Discount is calculated as 10% of the sale-value.
Code:
Double click on the Calculate Button and write the following code…………………..
saleAmtTextField.setText(""+salAmt);
discTextField.setText(""+disc);
netAmtTextField.setText(""+netAmt);
14
PROGRAM NO – 14
Code:
15
PROGRAM NO - 15
FRX Consultancy is registering job seekers for placement. Their basic entry form has the
following features.
(a) All the characters entered in text field should be converted into uppercase characters.
(b) When submit button SubmitBtn is clicked the following things should happen:
1) If checkbox PgtCB is selected checkboxes GrandCB and InterCB should also get
selected.
2) If GrandCB is selected InterCB should also be selected.
3) A message box should display “Hello Mr……….. you are registered” for male and
“Hello Miss ………. You are selected”.
(c) When clear button ClearBtn is clicked the textbox, checkboxes and the option button
should be set to Male.
Code:
(a) Right Click NameTF text field - Events - Focus - FocusLost and write the
following code to convert input text in to UpperCase as given in question.
(b) Double click on the SubmitBtn and write the following code……
if(PgtCB.isSelected() == true)
{
GrandCB.setSelected(true);
InterCB.setSelected(true);
}
if(GrandCB.isSelected() == true)
{
InterCB.setSelected(true);
}
String str = null;
if(MaleRB.isSelected())
{
str = "Hello Mr. " + NameTF.getText() + " you are registered.";
}
else if(FemaleRB.isSelected())
{
str = "Hello Miss. " + NameTF.getText() + " you are selected.";
}
JOptionPane.showMessageDialog(null, str);
16
(c) Double click on the ClearBtn and write the following code……
GrandCB.setSelected(false);
InterCB.setSelected(false);
PgtCB.setSelected(false);
NameTF.setText(null);
MaleRB.setSelected(true);
FemaleRB.setSelected(false);
17
PROGRAM NO – 16
The given form calculates the GCD(HCF) of two numbers. Write code for the command button
(cmdGcd) to print the GCD in the label (lblGcd).
Code:
int n1 = Integer.parseInt(Num1TF.getText().toString());
int n2 = Integer.parseInt(Num2TF.getText().toString());
int t;
while (n2!=0)
{
t = n2;
n2 = n1%t;
n1 = t;
}
gcdTF.setText("" + n1);
18
PROGRAM NO – 17
Code:
19
PROGRAM NO - 18
Code:
20
PROGRAM NO - 19
Code:
int factorial = 1;
factorial = factorial * i;
OUTPUT
21
PROGRAM NO - 20
Write a program to retrieve data from the database using JDBC. Design a GUI for table to
retrieve the data.
package jdbc;
import java.sql.*;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;
DefaultTableModel model=(DefaultTableModel)employee12.getModel();
try
{
Class.forName("java.sql.Driver");
Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/prasad", "root",
"");
Statement st=con.createStatement();
ResultSet rs=st.executeQuery("select * from employee12");
while(rs.next())
{
model.addRow(new Object[ ]
{
rs.getInt(1),rs.getString(2),rs.getString(3),rs.getString(4)}
);
}
rs.close();
st.close();
con.close();
}
catch(Exception e)
{
JOptionPane.showMessageDialog(null, "Error in Connectivity" +e);
22
OUTPUT
23
PROGRAM NO - 21
<HTML>
<HEAD>
<STYLE>
TD,TH,TABLE
{
BORDER:2PX SOLID red;
}
</STYLE>
</HEAD>
<img align = "right" border = 5px solid
src = "C:\Users\Chaitanya\Desktop\sclogo.jpg" width = 100 height = 100>
</img>
<H1><CENTER>MY STUDY TIME TABLE FOR THE WEEK </CENTER></H1>
<H2><CENTER>SRI CHAITANYA COLLEGE</CENTER></H2>
<TABLE STYLE="WIDTH:1200PX">
<TR>
<TH>DAYS</TH>
<TH>08:20 - 09:10</TH>
<TH>09:10 - 10:00</TH>
<TH>10:10 - 11:00</TH>
<TH>11:00 - 11:50</TH>
<TH>11:50 - 12:40</TH>
<TH>01:10 - 02:00</TH>
<TH>02:00 - 02:50</TH>
<TH>03:00 - 03:50</TH>
<TH>03:50 - 04:40</TH>
<TH>04:40 - 05:20</TH>
</TR>
<TR>
<TH>Monday</TH>
<TH>ENGLISH</TH>
<TH>MATH</TH>
<TH>PHYSICS</TH>
<TH>CHEMISTRY</TH>
<TH>BIOLOGY</TH>
<TH>COMP.SCIENCE</TH>
24
<TH>LANG</TH>
<TH>IP</TH>
<TH>LAB-PHY</TH>
<TH>LAB-CHEM</TH>
</TR>
<TR>
<TH>Tuesday</TH>
<TH>ENGLISH</TH>
<TH>MATH</TH>
<TH>PHYSICS</TH>
<TH>CHEMISTRY</TH>
<TH>BIOLOGY</TH>
<TH>COMP.SCIENCE</TH>
<TH>LANG</TH>
<TH>IP</TH>
<TH>LAB-PHY</TH>
<TH>LAB-CHEM</TH>
</TR>
</TABLE>
<MARQUEE DIRECTION="right"> ENJOY THE LIFE AS A STUDENT!!!</MARQUEE>
</BODY>
</HTML>
25
PROGRAM NO - 22
<html>
<head>
<title> forms creation </title>
</head>
<img align = "right" border = 5px solid src = "C:\Users\Chaitanya\Desktop\sclogo.jpg"
width = 100 height = 100>
</img>
<center> <h1> APPLICATION FORM </h1> </center>
Password:
<input type="password" name="pass" size="30" maxlength="15"> <br> <br>
Address:
<textarea name="add" rows="3" cols="20" maxlength=250>
</textarea> <br> <br>
<input type="checkbox" name="paper1" value="paper1">
<label for="paper1"> I LANG </label>
<input type="checkbox">
<label for="paper2"> II LANG </label> <br>
Examination Centers
<select name="Examination Centers" size="1">
<option value="Bng"> BANGLORE
<option value="Tpt"> TIRUPATHI
<option value="mas"> CHENNAI
<option value="cst"> MUMBAI
26
</select> <br> <br>
Location
<select name="Examination Centers" size="1">
<optgroup label="Bangalore">
<option value="seshadripuram"> Seshadripuram
<option value="rt nagar"> R.T.Nagar
<option value="hebbal"> Hebbala
<option value="Bangsouth"> Koramangala
<option value="Jayanagar"> Jayanagar
<optgroup label="Tirupathi"> TIRUPATHI
<option value="tptcity"> City
<option value="outcuts"> Outcuts
<optgroup label="chennai"> CHENNAI
<option value="Adayar"> Adayar
<option value="T.Nagar"> T.Nagar
<optgroup label="Hyderabad"> HYDERABAD
<option value="Hitech City"> Hitechs
<option value="Dsnr"> Dilsukhnagar
</select> <br>
<center>
<input type="submit" value="SUBMIT">
<br>
<br>
<input type="reset" value="CLEAR">
</form>
</body>
</html>
27
PROGRAM NO - 23
8) Display the details of all the loans with less than 40 installments
Mysql> select * from loans where installments < 40;
9) Display the accno, loan_amount of all the loans started before 2009-01-04
Mysql> select accno, loan_amount from loans where start_date < ’2009-01-04’;
28
10) Display the int_rate of all the loans started after 2009-01-04
Mysql> select int_rate from loans where start_date > ‘2009-01-04’;
11) Display the details of all the loans whose rate of interest is NULL
Mysql> select * from loans where int_rate is null;
12) Display the details of all the loans whose rate of interest is not NULL
Mysql> select * from loans where int_rate is not null;
13) Display the amounts of various loans from the table loans. Only a loan amount should
appear
Mysql> select distinct(loan_amount) from loans;
14) Display the details of all the loans started after 2008-12-31 for which the number of
installments are more than 36.
Mysql> select * from loans where start_date > ‘2008-12-31’ AND installments > 36;
15) Display the cust_Name and loan_amount for all the loans which don’t have number of
installments 36
Mysql> select cust_name, loan_amount from loans where installments < > 36;
16) Display the details of all the loans whose rate of interest is in the range of 11% to 12%
Mysql> select * from loans where int_rate >=11.00 AND int_rate <=12.00;
17) Display the cust_name and loan_amount for all the loans for which the number of
installments are 24,36 or 48 (using IN )
Mysql> select cust_name, loan_amount from loans where installments IN (24,36,48);
18) Display the details of all the loans whose loan_amount is in the range of 400000 to 500000
using(BETWEEN)
Mysql> select * from loans where loan_amount BETWEEN(400000 AND 500000);
19) Display the details of all the loans whose rate of interest is in the range of 11% to 12% (using
BETWEEN)
Mysql> select * from loans where int_rate BETWEEN (11 AND 12);
20) Display the accno, cust_name and loan_amount for all the loans for which the cust_name
ends with sharma
Mysql> select accno, cust_name, loan_amount from loans where cust_name LIKE ‘%sharma’;
29
21) Display the accno, cust_name and loan_amount for all the loans for which the cust_name
contains letter ‘a’
Mysql> select accno, cust_name, loan_amount from loans where cust_name LIKE ‘% a %’;
22) Display the accno, cust_name and loan_amount for all the loans for which the cust_name
does not contain letter ‘p’
Mysql> select accno, cust_name, loan_amount from loans where cust_name NOT LIKE
‘ % p %’;
23) Display the details of all the loans in the ascending order of their loan_amount
Mysql> select * from loans ORDER BY loan_amount ASC;
24) Display the details of all the loans in the descending order of their start_date
Mysql> select * from loans ORDER BY start_date DESC;
25) Change the interest rate as 11.50% for the loans which interest rate is NULL
Mysql> update loans SET int_rate = 11.50 where int_rate is NULL;
26) Increase the interest rate by 0.5% for all the loans for which the loan amount is more than
400000
Mysql> update loans SET int_rate = int_rate + 0.5 where loan_amount > 400000;
27) Delete the records of all the loans whose start date is before 2007
Mysql> delete from loans where year (start_date) < 2007;
28) Add the column category of type char(2) in the loan table
Mysql> alter table loans add(category char(2));
30
PROGRAM NO - 24
31
PROGRAM NO – 25
Consider the following two table’s items and bills and write the SQL statements for the
following queries
ITEMS TABLE
ICode Name Category Rate
1001 Masala Dosa South Indian 60
1002 Vada Sambar South Indian 40
1003 Idly Sambar South Indian 40
2001 Chowmein Chinese 80
2002 Dimsum Chinese 60
2003 Soup Chinese 50
3001 Pizza Italian 240
3002 Pasta Italian 125
BILLS TABLE
Bill No Date Item code Qty
1 2010-04-01 1002 2
1 2010-04-01 3001 1
2 2010-04-01 1001 3
2 2010-04-01 1002 1
2 2010-04-01 2003 2
3 2010-04-02 2002 1
4 2010-04-02 2002 4
4 2010-04-02 2003 2
5 2010-04-03 2003 2
5 2010-04-03 3001 1
5 2010-04-03 3002 3
32
1) Display the average rate of south Indian items
Mysql> select AVG(rate) from items where category = ‘south indian’;
4) Display total quantity of each item sold but do not display this data for the items whose total
quantity sold is less than 3
Mysql> select name, SUM(Qty) from items I, bills B where I.icode=B.icode GROUP BY name
HAVING SUM(Qty) > 3;
5) Display the details of bill records along with name of each corresponding item
Mysql> select name, billno, billcode, date, qty from items I, bills B where I.icode=B.icode;
6) Display the details of the bill records for which the item is ‘dosa’
Mysql> select name, billno, billcode, date, qty from items I, bills B where I.icode=B.icode AND
name=’dosa’;
33