Sie sind auf Seite 1von 10

Q1.

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(""); }
Q2. 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);
}
Q3. 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:
}
Q4. 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);

}
Q5. 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
}
Q6. 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));
}
Q 7. 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));
}
Q8 . 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);
}
Q9. 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("");
}

Das könnte Ihnen auch gefallen