2. INDEX
S.NO. TOPIC
1 Create a GUI application to calculate
commission of salesman.
2 Create a GUI application for a simple
calculator
3 Create Java application to calculate the result
of student (Total and percentage) out of five
subject
4 Create a GUI application to compute and
display payment amount and tax payable .
5 Create GUI application to calculate the
salary of employee details are shown on
respective page.
6 Create Java application to calculate the total
amount of purchasing ,it will accept
payment through three type of credit card.
The discount is given according to given
criteria (Platinum card : 20% discount, Gold:
15%, Silver: 10% of amount)
7 Write a Java program to calculate the
factorial of number by using method.
8 Create a Java application to find greater
number out of two numbers by using
method.
9. Design a GUI application to compute the
sum of digits of a number by using method
10 Design a GUI application using methods to
check the eligibility for voting .
11 Write a program to check whether a string is
palindrome or not?
12 Write a program that displays the swapping
of 2 numbers using:
a) Call By Value
b) Call By Reference
3. 13 Write a program that uses a class to
implement the following for a rectangle class:
a) Calculate area of Rectangle
b) Calculate perimeter of Rectangle
14 Write a program that finds the area of circle
and cylinder using java overriding method
15 Write a program to demonstrate the
abstract class concept for the class
declaration to print the message
16 Create a GUI application using connectivity
that can retrive data from dept table from
my sql database
17 Create a GUI application that obtains record
from tables (say empl) based on three
different criteria .It then display all retrived
records based on all the criteria together in
one table.
18 create a GUI application that computes
calories in meal.
19 Write JAVA application that input number &
find
-number of days in that month
-Table of input number
-First ten evennumbers
20 Write JAVA application that input number
and show the week day
21 SQL QUERIES (20 QUESTIONS)
4. Q1 Calculate the commission for the salesman according to the following rates:
Sales Commission
Rate
30001
onwards
15%
22001-
30000
10%
12001-
22000
7%
5001-
12000
3%
0-5000 0%
SOLUTION: The GUI for sales commission calculator is as follows:
CODING:
private void CalcButtonActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
// obtain input
String txt = SalesTF.getText();
double sales;
sales = Double.parseDouble(txt);
double comm;
// calculate commission
if(sales > 30000)
comm = sales*0.15;
5. else
if(sales > 22000)
comm = sales*0.10;
else
if(sales > 12000)
comm = sales*0.07;
else
if(sales > 5000)
comm = sales*0.03;
else
comm = 0;
//display output
CommLabel.setText("The Commission is Rs. "+comm);
}
OUTPUT
8. Q3 Create Java application to calculate the result of student (Total and percentage) out of five subject.
SOLUTION: The GUI for Result Calculation is as follows:
CODING
int a,b,c,d,e,t,p;
a=Integer.parseInt(jTextField3.getText());
b=Integer.parseInt(jTextField4.getText());
c=Integer.parseInt(jTextField5.getText());
d=Integer.parseInt(jTextField6.getText());
e=Integer.parseInt(jTextField7.getText());
t=a+b+c+d+e;
p=t/5;
jTextField8.setText(""+t);
jTextField9.setText(""+p);
OUTPUT
9. Q 4Create a GUI application to compute and display payment amount and tax payable .
SOLUTION: The GUI for compute and display payment amount and tax payable is as follows:
CODING
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
int hours = Integer.parseInt(hwTextField.getText());
double prate = Double.parseDouble(prTextField.getText());
double trate = Double.parseDouble(trTextField.getText());
double payAmt = hours* prate ;
double taxAmt = payAmt*trate ;
payamentTF.setText(""+payAmt);
taxTF.setText(""+taxAmt) ;
OUTPUT
10. Q 5 Create a GUI application to calculate salary of employes.
SOLUTION:
CODING
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
Double BasicSalary = Double.parseDouble(BsalaryTF.getText()) ;
Double D =BasicSalary*0.15;
jTextField4.setText(""+ D);
Double H =BasicSalary*0.30;
jTextField5.setText(""+H);
Double P =BasicSalary*0.05;
jTextField6.setText(""+P);
Double NtSalary =((BasicSalary+D+H)-P);
NetSalary.setText(""+NtSalary);
OUTPUT
Bakshish
11. Q6 Create Java application to accept payment through three type of credit card. The discount is given according
to given criteria (Platinum card : 20% discount, Gold: 15%, Silver: 10% of amount)
SOLUTION: The GUI for discount calculation is as follows:
CODING
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
double TotalCost = Double.parseDouble(jTextField2.getText());
double offer = Double.parseDouble(jTextField3.getText());
double AdditionalOffer =Double.parseDouble(jTextField4.getText());
double netAmt = TotalCost-offer-AdditionalOffer;
jTextField5.setText(""+netAmt);
}
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
jTextField4.setText("0");
jTextField5.setText("0");
jTextField4.setEditable(false);
jTextField5.setEditable(false);
double dis = 0;
double amt= Double.parseDouble(jTextField2.getText());
if(platRB.isSelected())
dis=amt*0.20;
else if(silvRB.isSelected())
dis= amt*0.15;
else
13. Q 7Write a Java program to calculate the factorial of number by using method.
SOLUTION: The GUI for Factorial Calculation is as follows:
CODING
private void FactorialBtnActionPerformed(java.awt.event.ActionEvent evt)
int a,c;
a=Integer.parseInt(p.getText());
c=fact(a);
q.setText(" "+c);
}
/**
* @param args the command line arguments
*/
private int fact (int x) //Method
{int z=1;
for(int i=1;i<=x;i++)
z=z*i;
return z;
}
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new factorial().setVisible(true);
}
});
15. Q8 Create a Java application to find greater number out of two numbers by using method
SOLUTION: The GUI for Factorial Calculation is as follows:
CODING:
private void FindLargestBtnActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
double num1 = Double.parseDouble(num1TF.getText());
double num2 = Double.parseDouble(num2TF.getText());
largest (num1,num2);
}
private void largest (int x, int y) // METHOD
{if (x>y)
resultTF.setText(" First Number is Largest");
else
resultTF.setText(" Second Number is Largest");;
}
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new Largest().setVisible(true);
}
});
17. Q9 Design a GUI application using methods that obtains a number in the textfield, computes the sum of
digits and displays it in a label.
SOLUTION: The GUI for Sum Calculation is as follows:
CODING
private void SumBtnActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
int num = Integer.parseInt(numTF.getText());
int sum = addDigits(num);
OutLbl.setText(" Sum of its digits is : " +sum);
}
int addDigits (int n) {
int s = 0;
int dig;
while(n > 0) {
dig = n%10;
s = s+dig;
n = n/10;
}
return s;
}
19. Q10 create java application to check the eligibilty for voting by using method.
SOLUTION: The GUI to check the eligibilty for voting is as follows:
CODING
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
{
Integer a;
a =Integer.parseInt(jTextField1.getText());
age (a);
}
}
/**
* @param args the command line arguments
*/private void age (int a)
{
if ( a>=18)
jTextField2.setText("eligble for voting" );
else
jTextField2.setText ("not eligible");
}
21. Q11 Design a GUI application whether a string is palindrome or not.
SOLUTION: The GUI to check the string is palindrome or not.
CODING
private void SubmitButtonActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
String str = strTF.getText();
showPalindrome(str);
}
public void showPalindrome(String s) {
StringBuffer out = new StringBuffer(s);
if(isPalindrome(s))
s = s+": IS a palindrome!";
else
if(isPalindrome2(s))
s = s+": IS NOT a palindrome";
outLbl.setText(s);
}
public boolean isPalindrome(String s) {
StringBuffer reversed = (new StringBuffer(s)).reverse();
return s.equals(reversed.toString());
}
public boolean isPalindrome2(String s) {
StringBuffer reversed = (new StringBuffer(s)).reverse();
return s.equalsIgnoreCase(reversed.toString());
}
23. Q12 Create a program that displays the swapping of 2 numbers using:
Call By Value
Call By Reference
SOLUTION: The GUI for Factorial Calculation is as follows:
CODING:
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
n1 = Integer.parseInt(num1TF.getText());
n2 = Integer.parseInt(num2TF.getText());
SwapByVal(n1,n2);
Num1Lbl.setText(" " + n1);
Num2Lbl.setText(" " + n2);
MsgLbl.setText("Swapped By VALUE");
}
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
n1 = Integer.parseInt(num1TF.getText());
n2 = Integer.parseInt(num2TF.getText());
SwapByRef(this);
Num1Lbl.setText(" " + n1);
Num2Lbl.setText(" " + n2);
MsgLbl.setText("Swapped By REFERENCE");
}
24. void SwapByVal(int a, int b) {
int tmp ;
tmp = a;
a = b;
b = tmp;
}
void SwapByRef(CallMechanism obj) {
int tmp;
tmp = obj.n1;
obj.n1 = obj.n2;
}
OUTPUT
12
25. Q13: Create a GUI application that uses a class to implement the following for a rectangle class:
Calculate area of Rectangle
Calculate perimeter of Rectangle
SOLUTION: The GUI to Calculate area of Rectangle
And Calculate perimeter of Rectangle
CODING
User defined class in class Volume I
public class Rectangle {
int length;
int breadth;
/** Creates a new instance of Rectangle */
public Rectangle() {
length = 0;
breadth = 0;
}
int area(int L,int B) {
length = L;
breadth = B;
return(length*breadth);
}
int Perimeter(int L,int B) {
length = L;
breadth = B;
return(2*(length + breadth));
}
}
26. private CalcBtnActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
int L,B;
int result = 0;
L = Integer.parseInt(txtLength.getText());
B = Integer.parseInt(txtBreadth.getText());
// Create an object RecObj for Rectangle class
Rectangle RecObj = new Rectangle();
if(jRadioButton1.isSelected())
{
result = RecObj.area(L,B);
}
else
if(jRadioButton2.isSelected())
{
result = RecObj.Perimeter(L,B);
}
txtResult.setText(Integer.toString(result));
}
private void ExitBtnActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
System.exit(0); }
OUTPUT
27. Q14 Write a program that finds the area of circle and cylinder using java overriding method
SOLUTION: The GUI to calculate the area of circle and cylinder
CODING
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
double rad,len;
double AreaC,AreaCy;
rad = Double.parseDouble(txtR.getText());
len = Double.parseDouble(txtL.getText());
Circle cir = new Circle(rad);
Cylinder cyl = new Cylinder(rad,len);
AreaC = cir.getArea();
AreaCy = cyl.getArea();
txtCircle.setText(Double.toString(AreaC));
txtCylinder.setText(Double.toString(AreaCy));
28. }
class Circle {
protected double radius;
public Circle(double radius) {
this.radius = radius;
}
public double getArea() {
return Math.PI*radius*radius;
}
}
class Cylinder extends Circle {
protected double length;
public Cylinder(double radius,double length) {
super(radius);
this.length = length;
}
public double getArea() {
return 2*super.getArea() + 2*Math.PI*radius*length;
}
}
/**
* @param args the command line arguments
*/
29. public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new INHERITANCE().setVisible(true);
}
});
}
OUTPUT
30. Q15Design a GUI application to demonstrate the abstract class concept for the class declaration to print the
message.
SOLUTION: The GUI to demonstrate the abstract class concept for the class declaration to print the message.
//CODING:
private void ExitActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
System.exit(0);
}
private void PrintMessageActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
subClass sb = new subClass();
sb.print_String();
}
abstract class Message
{
abstract String printData();
public void print_String()
{
jTextField1.setText(printData());
}
}
class subClass extends Message
{
String printData()
{
return " Java Abstract Class Concepts "; } }
OUTPUT
31.
32. Q16 DesignGUI application using connectivity that canretrieve data from dept table
from My SQL database.
SOLUTION: The GUI that can retrieve data from dept table from My SQL database.
CODING
import java.sql.*;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;
public class DatabaseConnectivity extends javax.swing.JFrame {
/** Creates new form DatabaseConnectivity */
public DatabaseConnectivity() {
initComponents();
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
jScrollPane1 = new javax.swing.JScrollPane();
depTbl = new javax.swing.JTable();
rtrBtn = new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
36. Q17:Create a java GUI applicationthat obtains records from a table(sayempl) basedon
three different criteria.It then displays all retrieved records basedon all the criteria
togetherin one table.
SOLUTION: The GUI that that obtains records from a table(say empl) based on three different
criteria.It then displays all retrieved records based on all the criteria together in one table.
CODING
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/*
* Search_From_Database.java
*
*/
37. package jdbc_2_ques;
/**
*/
import java.sql.*;
import javax.swing.table.DefaultTableModel;
import javax.swing.JOptionPane;
public class Search_From_Database extends javax.swing.JFrame {
String msg = "";
/** Creates new form Search_From_Database */
public Search_From_Database() {
initComponents();
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
jLabel1 = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();
jLabel3 = new javax.swing.JLabel();
criteriaTF = new javax.swing.JTextField();
opCBX = new javax.swing.JComboBox();
srchFldCBX = new javax.swing.JComboBox();
jSeparator1 = new javax.swing.JSeparator();
searchBtn = new javax.swing.JButton();
jScrollPane1 = new javax.swing.JScrollPane();
emplTbl = new javax.swing.JTable();
exitBtn = new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jLabel1.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
jLabel1.setText("Specify search criteria below");
jLabel2.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
jLabel2.setText("Search Field");
43. Q19 Write JAVA application that input number & find
-number of days in that month
-Table of input number
-First ten evennumbers
CODING:
private voidjButton1ActionPerformed(java.awt.event.ActionEventevt) {
intn=Integer.parseInt(t1.getText());
for(inti=1;i<=10;i++)
ta.append(""+n+"*"+i+"="+n*i+"n");
:
}
private voidjButton2ActionPerformed(java.awt.event.ActionEventevt) {
intmno=Integer.parseInt(t1.getText());
switch(mno)
{
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:
JOptionPane.showMessageDialog(null,"31days");
break;
case 2:
JOptionPane.showMessageDialog(null,"28or29 days");
break;
case 4:
case 6:
case 9:
case 11:
JOptionPane.showMessageDialog(null,"30days");
default:
System.out.print("notmonthnumber");
}
}
private voidjButton3ActionPerformed(java.awt.event.ActionEventevt) {
45. Q20 Write JAVA application that input number and show the week day
private voidjButton1ActionPerformed(java.awt.event.ActionEventevt) {
intno=Integer.parseInt(t1.getText());
switch(no)
{
case 1:
l2.setText("sunday");
break;
case 2:
l2.setText("Monday");
break;
case 3:
l2.setText("Tuesday");
break;
case 4:
l2.setText("Wednesday");
break;
case 5:
l2.setText("Thursday");
break;
case 6:
l2.setText("Friday");
break;
case 7:
l2.setText("Friday");
break;
default:
l2.setText("invaliddayno");
}
OUTPUT
46.
47. MY-SQL STATEMENTS
Q1. Write MySQL query to create a database named “school”.
Solution: create database school;
Q2: Write MySQL Query to use the database named “school”.
Solution: use school;
Q3: Using SQL statements in mysql,create the tables identified below in the following order (underlined
columns depict primary keys).
(i) Campus(CampusID,CampusName,Street,City,State,Pin,Phone,CampusDiscout)
Solution:
create table Campus(CampusID varchar(20),CampusName varchar(50),Street varchar(50),City
varchar(20),State varchar(20),Pin varchar(10),Phone varchar(10),CampusDicount decimal(2,2);
(ii) Members(MemberID,LastName ,FirstName,CampusAddress ,CampusPhone ,CampusID
,PositionID,ContractDuration).
Solution: create table Members(MemberID varchar(10),LastName varchar(20),FirstName
varchar(20),CampusAddress varchar(50),CampusPhone varchar(20),CampusID
varchar(10),PositionID varchar(10),ContractDuration varchar(20));
(iii) Position(PositionID ,Position ,YearlyMembershipFee).
Solution: Position(PositionID varchar(10),Position varchar(20),YearlyMembershipFee varchar(20));
48. Q4: Write SQL Statements to show data of table named “Position1”.
Solution: select * from Position1;
Q5: Write a MySQL query to display current date and time.
Solution: select now();
Q6: Write SQL commands to show the output of 3.14*8.
Solution: select 3.14*8;
Q7: Write SQL command to show the output of round(235.327,2).
Solution: select round(235.327,2);
49. Q8: Write MySQL command to predict the output of mid(‘Banasthali’,4,5).
Solution: select MID(‘Banasthali’,4,5);
Q9: Write MySQL query to predict the output of MOD(16,3).
Solution: select MOD(16,3);
Q10: Tell the output of the MySQL query: select UPPER(‘Banasthali Public School’ AS “School Name”;
Solution: select UPPER (‘Banasthali Public School’ ) AS “School Name”;
Q11: Write a mysql query to predict the output of POWER(4,2).
Solution: select POWER(4,2);
50. Q12: Write SQL commands for creating a table “student” with the following details:
FIELD NAME DATA TYPE SIZE CONSTRAINT
StudentID integer 5 Unique
LastName Varchar 30
FirstName Varchar 30
Score integer 5
Solution: create table student(StudentID int(5) UNIQUE,LastName varchar(30),FirstName varchar(30),Score
int(5));
Q13: Write SQL command to create a table “customer” with following constraints [SID-Primary Key]
Customer SID(integer),LastName varchar(30),FirstName varchar(30).
Solution: create table customer(CustomerID int(5) PRIMARY KEY,LastName varchar(30),FirstName
varchar(30));
Q14: Write MySQL command to remove the tuples from employee table that have gross salary less than
2200.
Solution: DELETE from employee where GrossSalary<2200;
51. Q15: Write MySQL query to add a new column tel_number at type integer in table employee.
Solution:ALTER table employee ADD (tel_number int(10));
Q16: Write MySQL command that counts the number of rows of score column in Q12 in table student.
Solution:select COUNT(Score) from student;
Q17: Write SQL query to display the details of all the students whose Last_Name starts with the letter
“S”.
Solution:select * from student where LastName like’S%’;
Q18: Write a query to display name of all students that have distinct (Last_Name) from the table student.
Solution: select DISTINCT LastName from student;
52. Q19: Write MySQL query to show the structure of the table “student”.
Solution: desc student;
Q20: Write MySQl query to add foreign key through alter table command on the table “orders” which
has the following structure:
COLUMN
NAME
CHARACTERISTIC
SID Primary Key
Last_Name
First_Name
TABLE : orders TABLE : customer
COLUMN
NAME
CHARACTERISTIC
OrderID Primary Key
Amount
OrderDate
CustomerSID Foreign Key
Solution: ALTER table orders ADD FOREIGN KEY(Customer_SID) references customer(SID);