You are on page 1of 21

Q1.

Develop an application to perform mathematical operations on two numbers

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


int n1, n2, aoPlus, aoMult, aoRem, Diff;
float aoDiv;
n1 = Integer.parseInt(txtNum1.getText());
n2 = Integer.parseInt(txtNum2.getText());
aoPlus = n1 + n1; // integer addition
Diff = n1 - n2; // integer subtraction
aoMult = n1 * n2; // integer multiplication
aoDiv = n1 / n2; // integer division
aoRem = n1 % n2;
txtPlus.setText(“”+aoPlus );
txtMinus.setText(“”+ Diff);
txtMult.setText(“”+ aoMult);
txtDiv.setText(“”+aoDiv);
txtMod.setText(“”+aoRem);
}

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


System.exit(0);
}
Q2. Input the Principal, Rate and Time and calculate the Simple Interest and Amount

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


int prin = Integer.parseInt (t1.getText());
int rate = Integer.parseInt (t2.getText());
int time = Integer.parseInt (t3.getText());
double interest = ( prin * rate * time) / 100;
t4.setText ("" + interest);

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


int prin = Integer.parseInt (t1.getText());
int rate = Integer.parseInt (t2.getText());
int time = Integer.parseInt (t3.getText());
double interest = ( prin * rate * time) / 100;
double amount = prin + interest;
t5.setText ("" + amount);
}

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


System.exit(0);
// TODO add your handling code here:
}

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


t1.setText("");
t2.setText("");
t3.setText("");
t4.setText("");
t5.setText(""); }
Q3. Program to find the greater of three numbers

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


int N1, N2, N3; // Variables to hold three input values.
int max; // Variable to hold maximum value.
N1 = Integer.parseInt(txtN1.getText());
N2 = Integer.parseInt(txtN2.getText());
N3 = Integer.parseInt(txtN3.getText());
if ((N1 > =N2) && (N1 > N3))
max = N1;
else if ((N2 > =N1) && (N2 > N3))
max = N2;
else if ((N3 > N1) && (N3 > N2))
max = N3;
jLabel4.setText("The greater number is : " + max);

}
private void exButtonActionPerformed(java.awt.event.ActionEvent evt) {
System.exit(0);
}
Q4. Application to input a number and display its reverse (using do…while loop)

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


t1.setText ("");
t2.setText ("");// TODO add your handling code here:
}

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


System.exit(0);
// TODO add your handling code here:
}

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


int a = Integer.parseInt (t1.getText ());
int b = a; int d=0;
do {
int c = a%10;
d=d*10+c;
a = a/10;
}while(a!=0);
t2.setText ("Mirror Image Of " + b + " is " + d);
// TODO add your handling code here:
}
Q5. Enter the Sales and calculate the incentive of a salesman depending on the choice of any one
option of achievement : Maximum Sales – 10% of sales, Customer feedback – 8% of sales, Maximum
Customers- 5% of Sales. (Implementing Button Group)

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


// TODO add your handling code here:
System.exit(0);
}

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


// TODO add your handling code here:
// Declare & initialize variables for storing sales
int sales = 0;
sales = Integer.parseInt(t1.getText());
double incentive = 0.0;
if(c1.isSelected()){
incentive = 0.1; //10%
}
if(c2.isSelected()){
incentive = 0.08; //8%
}
if(c3.isSelected()){
incentive = 0.05; //5%
}
double t = (sales * incentive);

l1.setText("" + t);

}
Q6. ABN Shipment Corporation imposes charges to customers for different product. The shipment
company costs for an order in 2 forms : Wholesaler &Retailer. The cost is calculated as below :
No Units Price for wholesaler (per unit) Price for retailer (per unit)
1 – 15 Rs 50/- Rs 60
16 - 20 Rs 45/ Rs 55/
21 - 30 Rs 40/ Rs 50/
31 - 50 Rs 35/ Rs 45/
> 50 Rs 30/ Rs 40/

Special customers are further given a discount of Rs 10%

private void formWindowGainedFocus(java.awt.event.WindowEvent evt) {


txtTCost.enable(false);
optWhole.setSelected(true);
}
private void cmdExitActionPerformed(java.awt.event.ActionEvent evt) {
System.exit(0);
}
private void cmdCalcActionPerformed(java.awt.event.ActionEvent evt) {
int ordUnit; // Order unit
float TCost=0; // Total cost
float Discount = 0 ; // Discount price
ordUnit=Integer.parseInt(txtUnit.getText());
if (optWhole.isSelected())
{ if (ordUnit >= 1 && ordUnit <= 15)
TCost = ordUnit * 50;
else if (ordUnit >= 16 && ordUnit <= 20)
TCost = ordUnit * 45;
else if (ordUnit >= 21 && ordUnit <= 30)
TCost = ordUnit * 40;
else if (ordUnit >= 31 && ordUnit <= 50)
TCost = ordUnit * 35;
else if (ordUnit > 50)
TCost = ordUnit * 30;
}
else if (optRetail.isSelected())
{
if (ordUnit >= 1 && ordUnit <= 15)
TCost = ordUnit * 60;
else if (ordUnit >= 16 && ordUnit <= 20)
TCost = ordUnit * 55;
else if (ordUnit >= 21 && ordUnit <= 30)
TCost = ordUnit * 50;
else if (ordUnit >= 31 && ordUnit <= 50)
TCost = ordUnit * 45;
else if (ordUnit > 50)
TCost = ordUnit * 40;
}
if (chkSpecial.isSelected())
Discount = TCost * (float)0.1;
txtDisc.setText(Float.toString(Discount)); // (i) Displaying discount
TCost=TCost – Discount ;
txtTCost.setText(Float.toString(TCost)); // (ii) Displaying Total Cost
}
Q7. Program to input a number & find its factorial (while loop & input dialog box)

import javax.swing. JOptionPane;

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


int num, i = 1;
float fact = 1;
String str = JOptionPane.showInputDialog("Enter positive number to find factorial");
txtNum.setText(str);
num = Integer.parseInt(str);
if (num = = 1)
{
JOptionPane.showMessageDialog(this, "Factorial is 1");
}
while( i<=num)
{
fact = fact * num;
i = i + 1;
}
txtFact.setText(Float.toString(fact));
}
Q8. Using List Box control to show the list of states & display the Capital of the selected state.

private void l1ValueChanged(javax.swing.event.ListSelectionEvent evt) {


int i = l1.getSelectedIndex ();
String name = null;
switch (i)
{
case 0 : name = (" Hyderabad ");
break;
case 1 : name = (" Itanagar ");
break;
case 2 : name = ( " Dispur ");
break;
case 3 : name = ( " Patna ");
break;
case 4 : name = (" Raipur ");
break;
case 5 : name = (" Panaji");
break;
case 6 : name = (" Ahmedabad ");
break;
case 7 : name = (" Chandigarh ");
break;
case 8 : name = (" Shimla ");
break;
case 9 : name = (" Srinagar");
break;
case 10 : name = (" Ranchi");
break;
case 11 : name = (" Bangalore");
break;
case 12 : name = (" Thiruvananthapuram ");
break;
case 13 : name = (" Bhopal");
break;
case 14 : name = (" Mumbai");
break;
case 15 : name = (" Imphal");
break;
case 16 : name = (" Shillong");
break;
case 17 : name = (" Aizawl");
break;
case 18 : name = (" Kohima");
break;
case 19 : name = (" Bhubaneshwar");
break;
case 20 : name = (" Chandigarh");
break;
case 21 : name = (" Jaipur");
break;
case 22 : name = (" Gangtok");
break;
case 23 : name = (" Chennai");
break;
case 24 : name = (" Agartala");
break;
case 25 : name = (" Lucknow");
break;
case 26 : name = (" Dehradun");
break;
case 27 : name = (" Kolkata");
break;
default: name = null;
}
t1.setText(" " + name);
}
Q 9. Program to print different triangles

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


t1.setText ("");
t2.setText ("");
r1.setSelected(false);
r2.setSelected(false);

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


int a = Integer.parseInt (t1.getText());
for (int i = a; i>=1; i--)
{
t2.append("\n");
for (int j = 1; j <= i; j++)
t2.append (" * ");
}
}

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


int a = Integer.parseInt (t1.getText());
for (int i = 1; i <= a; i++)
{
t2.append("\n");
for (int j = 1; j <= i; j++)
t2.append (" * ");
} // TODO add your handling code here:
}
Q 10. Sagar electronics has the following products with their list price given. The store gives a 10%
discount on every product. However at the time of festival season, the store gives a further
discount of 7%. Note product name is stored in JListBox control.

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


float NetPrice;
NetPrice = Float.parseFloat(txtLPrice.getText()) - Float.parseFloat(txtDiscount.getText());
txtNPrice.setText(Float.toString(NetPrice));
}
private void cmdListActionPerformed(java.awt.event.ActionEvent evt) {
String Product = listProduct.getSelectedValue().toString();
if (Product.equals("Washing Machine")) {
txtLPrice.setText("12000");
} else if (Product.equals("Color Television")) {
txtLPrice.setText("17000");
} else if (Product.equals("Refrigerator")) {
txtLPrice.setText("18000");
} else if (Product.equals("OTG")) {
txtLPrice.setText("8000");
} else if (Product.equals("CD Player")) {
txtLPrice.setText("14500");
}
}
private void cmdDiscActionPerformed(java.awt.event.ActionEvent evt) {
float ProductPrice, Discount;
ProductPrice = Float.parseFloat(txtLPrice.getText());
// Calculating Discount Price
if (optFest.isSelected())
Discount = ProductPrice * 17 /100;
else
Discount = ProductPrice * 10 /100;
txtDiscount.setText(Float.toString(Discount));
}
private void cndExutActionPerformed(java.awt.event.ActionEvent evt) {
System.exit(0); }
Q 11. Displaying string functions

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


String Board = "CBSE";
String str = " Informatics Practices";
Board = Board.concat(str); // Concatenate str with Board
String str1 = "NetBeans IDE Programming";
int ln = str1.length();
String nStr = str1.substring(9); // Index starts from 9th position
String nStr1 = str1.substring(9, 13); // Index start from 9th position till 13th
String uCase = str1.toUpperCase(); // Converts into uppercase letters
String LCase = str1.toLowerCase(); // Converts into lowercase letters
String mess1 = " My Personal Bio-Data ";
String Year = "2009";
String nTrim = mess1.trim() + " " + Year;
txtStringArea.append("Concatenated string: " + Board + "\n");
txtStringArea.append("Length of '" + str1 + "' is: " + ln + "\n");
txtStringArea.append("str1.substring(9) is: " + nStr + "\n");
txtStringArea.append("str1.substring(9, 13) is: " + nStr1 + "\n");
txtStringArea.append("str1.toUpperCase() is: " + uCase + "\n");
txtStringArea.append("str1.toLowerCase() is: " + LCase + "\n");
txtStringArea.append("mess1 trim is: " + nTrim + "\n");
}
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
System.exit(0);
}
Q12 . Coding to concatenate two string along with the Input & Message Dialog Box.

import javax.swing. JOptionPane; // WRITTEN ON TOP

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


String str1 = JOptionPane.showInputDialog("Enter first string ");
String str2 = JOptionPane.showInputDialog("Enter second string ");
JOptionPane.showMessageDialog(this, str1 + " " + str2);
}
Q13. Develop an application using a table to input the data in a text box & add it in the table

Coding
import javax.swing.table.*;

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


String a = t1.getText();
String b = t2.getText();
String c = t3.getText();
Object[ ] ob = {a,b,c};
DefaultTableModel tm = (DefaultTableModel)table.getModel();
tm.addRow(ob);
}

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


t1.setText("");
t2.setText("");
t3.setText("");
}
Q14. Create a Java Desktop Application using class the implement the rectangle class & calculate
the area & perimeter of a rectangle.

@SuppressWarnings("unchecked")
//user defined class
public class Rectangle {
int length;
int breadth;
/** Constructor 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)); }
}
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
int result=0;
int L= Integer.parseInt(jTextField1.getText());
int B= Integer.parseInt(jTextField2.getText());
// creates 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);
jTextField3.setText(Integer.toString(result));
}

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


System.exit(0);
}
Q15. To create a simple GUI application that displays the records of a database table in a tabular format
(using jTable) on the GUI form.

Q16 . To create a simple GUI application that takes input and adds a record to the above created database

[ PROGRAMS GIVEN IN ASSIGNMENT -----EXECUTED IN LAB]


Table in HTML

<HTML>
<TABLE BORDER=2 CELLPADDING=4>
<TR> <TH COLSPAN=2 BGCOLOR="BLUE">Production</TH> </TR>
<TR> <TD>N. N. Reddy</TD> <TD>1493</TD> </TR>
<TR> <TD>S. M. Krishna</TD> <TD>3829</TD> </TR>
<TR> <TD>P. Chidamberam</TD> <TD>0283</TD> </TR>
<TR> <TH COLSPAN=2 BGCOLOR="Blue">Sales</TH> </TR>
<TR> <TD>Maria Philip</TD> <TD>4827</TD> </TR>
<TR> <TD>S. Gandhi</TD> <TD>7246</TD> </TR>
<TR> <TD>James Andrew</TD> <TD>5689</TD> </TR>
</TABLE>
<HTML>
Creating a website along with the unordered list, image & links.

<HTML>
<HEAD>
<TITLE>Wildlife</TITLE>
</HEAD>
<BODY vLink=red aLink=blue link=Maroon bgColor=SilVer>
<FONT FACE ="Times New Roman" SIZE=2 >
<H1 align=center>What is Social Networking ?</H1>
</FONT>
<FONT FACE ="Times New Roman" SIZE=4 >
<Img align="right" border = "1" width=160 height=140 src="Image1.JPG">
<P align="justify">
Social networking is the grouping of individual into specific groups,
like small rural communities or a neighbourhood subdivision, if you
will. Although social networking is possible in person, especially in
schools or in the workplace, it is most popular online.
</P>
<P align="justify">When it comes to online social networking, websites
are commonly used. These websites are known as social sites.
</P>

<TABLE cellPadding=2 width="70%" align=center border=2 color="BLUE">


<CAPTION color="blue"><B>List of major social networking websites
</B> </CAPTION>
<TBODY>
<TR>
<TH bgColor=cyan>Name</TH>
<TH bgColor=cyan>Description/Focus</TH>
</TR>
<TR>
<TD>Advogato</TD>
<TD>Free and Open source software developers</TD>
</TR>
<TR>
<TD>ANobii</TD>
<TD>Books</TD>
</TR>
<TR>
<TD>Avatars United</TD>
<TD>Online Games</TD>
</TR>
</TBODY>
</TABLE>
<U><B>MENU</B></U>
<UL>
<LI><A href="one.html">Social Networking and Websites
<LI><A href="two.html">Should You Join
<LI><A href="three.html">Starting Your own Network
<LI><A href="abc@xyz.com">Contact Us
</UL>
</BODY>
</HTML>

You might also like