Vous êtes sur la page 1sur 31

1. Design an application for Movie Booking system and answer the following questions?

a) When the user select different seat type, then its price should be displayed in the Label.

b) If the user enters an invalid no of seats i.e. less than 1, then an error message should be
displayed in the dialog box.

c) When the user click at the Book Seats button, then total amount (calculated as no. of
seats * price per seat) should be displayed along with payment method, next to the
push button.

Price per seat depend upon the seat type: Stall 625/- Circle 750/- Upper Circle 850/- Box
1000/-

source code:
(a) if (jRadioButton1.isSelected())
jLabel2.setText(“625”);
if (jRadioButton2.isSelected()) jLabel2.setText(“750”);
if (jRadioButton3.isSelected()) jLabel2.setText(“850”);
if (jRadioButton4.isSelected()) jLabel2.setText(“1000”);
(b)
int s = Integer.parseInt(jTextField1.getText());
if (s < 1) JOptionPane.showMessageDialog(null, ”Error! Enter at least one
seat.”);

(c)
int s = Integer.parseInt(jTextField1.getText());
int p = Integer.parseInt(jLabel2.getText());
int tp = s * p;
if (jRadioButton5.isSelected())
jLabel5.setText(“Cash Payment of “ + tp);
if (jRadioButton6.isSelected())
jLabel5.setText(“Visa Payment of “ + tp);
if (jRadioButton7.isSelected())
jLabel5.setText(“American Exress Payment of “ + tp);
if (jRadioButton8.isSelected())
jLabel5.setText(“Master Card Payment of “ + tp);

Result:
Thus the program is executed successfully.
2. Design the following application and answer the questions that follow :

(a) Write the code for the Clear button to clear all the text fields and check box.
Set the default choice in the radio button as Fixed Deposit.

(b) Write the code for the calculate button to calculate compound interest and
amount and display the values in the txtInterest and txtAmount depending on
principal, rate and time.

Rate is calculated based on the time according to the following table:

Account Time Rate


Fixed Deposit <=2 8%
>2 and <=5 9%
>5 10%
Recurring Deposit <=2 9%
>2 and <=7 10%
>7 12%
An additional rate of 2% is given to the senior citizens i.e. if the
Senior citizen (chkSR checkbox) is checked.
source code:
(a)
jTextField1.setText(“”);
jTextField2.setText(“”);
jTextField3.setText(“”);
jRadioButton1.setSelected(true);
jCheckBox1.setSelected(false);

(b) int p = Integer.parseInt(jTextField1.getText());


int t = Integer.parseInt(jTextField2.getText());
int r = 0;
if (jRadioButton1.isSelected())
{ if (t <= 2) r = 8;
else if( t > 2 && t <= 5) r = 9;
else r = 10; }
else { if (t <= 2) r = 9;
else if (t > 2 && t <= 7) r = 10;
else r = 12; }
if (jCheckBox1.isSelected()) r = r + 2;
float amt = p*Math.pow((1+(r/100)),t);
float ci = amt - p;
txtInterest.setText(“” + ci);
txtAmount.setText(“” + amt);

Result:
Thus the program is executed successfully.
3. Alpha Chemicals PVT ltd has asked his programmer to develop the following GUI
application in Netbeans:

Service Charges Rates are as follows:


Class of City Rate of Service Charges
I 5% of sales price
II 10% of sales price
III 15% of sales price
Write java code for the following:
a. To calculate service charges depending on the selection of radio button.
This code will execute after
click on the calculate service charges?
b. To calculate net price when Calculate Net price button will be clicked.
c. When exit button will be clicked application should be automatically
closed.
source code:

float q = Float.parseFloat(jTextField2.getText());
float p = Float.parseFloat(jTextField3.getText());
float sp = q * p;
jLabelsp.setText(“” + sp);
float sc;
if (jRadioButton1.isSelected())
sc = (5 * sp) / 100;
else if (jRadioButton2.isSelected())
sc = (10 * sp) / 100;
else
sc = (15 * sp) / 100;
jLabelsc.setText(“” + sc);

(b) float sp = Float.parseFloat(jLabelsp.getText());


float sc = Float.parseFloat(jLabelsc.getText());
float np = sp + sc;
jLabelnp.setText(“”+np);

(c) System.exit(0);

Result:
Thus the program is executed successfully.
4. Ms. Priya works as a programmer in “Avon Education” where she has
designed a software to compute fee charges to be paid by the students. A
screenshot of the same is shown below:

Name of the student is entered by the user.


Any one Course out of Pharmacy, Architecture and Arts & Design is chosen
by the user.
If the student is eligible for Concession, the required checkbox is selected
by the user.
Based on the course selected, Fee
Per
Quarter is displayed in the
appropriate textfield according to
the following criterion :

Course Fee Per Quarter


Pharmacy 2000.00
Architecture 2500.00
Arts & Design 2300.00
 If the student is eligible for Concession, a concession of 7% of Fee per
quarter is calculated as the concession amount, otherwise concession
amount is 0.

 Fee to be paid is the Fee per quarter with the concession amount (if
any) deducted from it.

Help Ms. Priya in writing the code to do the following :

(i) When ‘Calculate Charges’ button is clicked, ‘Fee per quarter’, ‘Concession
Amount’, ‘Fee to be Paid’ should be calculated and displayed in the
respective text fields.

(ii) When ‘CLEAR’ button is clicked, all the textfields, radiobuttons and
checkbox should be cleared.

(iii) When ‘Exit’ button is clicked, the application should close.

source code:
// Calculation of Amount

double feeperqtr = 0.0,concess = 0.0,feetopay=0.0;


if (jRadioButton1.isSelected())
feeperqtr=2000;
else if (jRadioButton2.isSelected())
feeperqtr=2500;
else if (jRadioButton3.isSelected())
feeperqtr=2300;
if (jCheckBox1.isSelected())
concess= (0.07*feeperqtr);
feetopay=feeperqtr-concess;
jTextField2.setText("" + feeperqtr);
jTextField3.setText("" + concess);
jTextField4.setText("" + feetopay);

(ii) jTextField1.setText("");
jTextField2.setText("");
jTextField3.setText("");
jTextField4.setText("");
jRadioButton1.setSelected(false);
jRadioButton2.setSelected(false);
jRadioButton3.setSelected(false);
jCheckBox1.setSelected(false);

(iii)System.exit(0);

Result:
Thus the program is executed successfully.
5. Well Tech Institute offers two post graduate courses, one in computers and
one in management. The students can avail certain optional facilities. The basic
interface for accepting the details of facilities availed by a student is as follows

Write the code and the event procedures for incorporating the following functionality:

(a) The library facility should be selected by default. And the default course
choice should be computers course.

(b) When user clicks clear button all the text fields should be cleared.

(c) Whenever user selects the HOSTEL facility , the MESS facility should get
selected automatically , which the user can deselect later if desired.

(d) Given that the charges for library , mess and hostel are RS 500, RS 1500 and
Rs 2000 respectively per month , write a method calculate() that calculates and
displays the charges per semester, for the facilities . This method should be called when
user clicks Calculate button .
source code:
a) public NewJFrame() {

initComponents();

jCheckBox1.setSelected(true);

jRadioButton2.setSelected(true);

b) jTextField1.setText("");

jTextField2.setText("");

jTextField3.setText("");

jTextField4.setText("");

jTextField5.setText("");

jRadioButton1.setSelected(false);

jRadioButton2.setSelected(true);

jCheckBox1.setSelected(true);

jCheckBox2.setSelected(false);

jCheckBox3.setSelected(false);

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

// TODO add your handling code here:


int lib, mess, hostel ,tot=0,ch1=0,ch2=0,ch3=0,amt;

if(jRadioButton1.isSelected())
{
if(jCheckBox1.isSelected())
{
ch1=500;
jTextField2.setText(""+ch1);
}

if(jCheckBox2.isSelected())
{
ch2=1500;
jTextField3.setText(""+ch2);
}

if(jCheckBox3.isSelected())
{
jCheckBox2.setSelected(true);
ch2=1500;
ch3=2000;
jTextField3.setText(""+ch2);
jTextField4.setText(""+ch3);
}
}
else
if(jRadioButton2.isSelected())
{
if(jCheckBox1.isSelected())
{
ch1=500;
jTextField2.setText(""+ch1);
}

if(jCheckBox2.isSelected())
{
ch2=1500;
jTextField3.setText(""+ch2);
}

if(jCheckBox3.isSelected())
{
jCheckBox2.setSelected(true);
ch2=1500;
ch3=2000;
jTextField3.setText(""+ch2);
jTextField4.setText(""+ch3);
}
}
amt=ch1+ch2+ch3;
jTextField5.setText(""+(amt*6));
}

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

// TODO add your handling code here:

System.exit(0);

Result:
Thus the program is executed successfully.
6. ) Mr. Suman, a programmer in New Era Programming World has designed a registration 6 page
for a hobby club as shown below:

Fee for different hobbies are as follows:

Hobby Fee
Dancing 1000
Drawing 1500
Music 2000
Singing 2500

Help him in writing the code to do the following:


i. As per the hobby chosen in the hobby combo box, fee should be displayed in
the respective text field named t1 as per the criteria given above after clicking
on
“Check Fee” button.
ii. If a candidate belongs to “Jr. Category” then a discount of 10% should be given
in displayed in the text field.

iii. After clicking on the “Net Fee” button, Net Fee should be calculated and
displayed in the respective text field as per the given formula:
Net Fee = Fee – Discount
iv. Write suitable java code to close the application.

v. Write java statement to add a new hobby “Reading” in the combo box at run
time.

source code:
(i). int x=c1.getSelectedIndex();
int fee=0;
if(x==0)
fee=1000;
else if(x==1)
fee=1500;
else if(x==2)
fee=2000;
else if(x==3)
fee=2500;
t2.setText(""+fee);
(ii).
double disc=0;
int fee=Integer.parseInt(t2.getText());

if(r2.isSelected())
disc=fee*10/100;
t3.setText(""+disc);
(iii).
double disc=Double.parseDouble(t3.getText());
int fee=Integer.parseInt(t2.getText());
double net=fee-disc;
t4.setText(""+net);
(iv).
System.exit(0);
(v).
c1.addItem("Reading");

txtNetFee.setEditable(false);

Result:
Thus the program is executed successfully.
7. The following GUI form is created in Netbeans for a Shop where customers can purchase following
items Computer Mobile Laptop.

(i) Write the coding to display the Price in jTextField1 when user select any item from
the jComboBox1 based on the following table :

Item Price

Computer 30000

Laptop 20000

Mobile 10000

(ii) Write the coding to calculate and display the amount(Price *Quantity) , discount
amount and net amount when user click on the purchase command button by using
following table :

Amount Discount Rate %

<=50000 0

50001 to 200000 10

>200000 20

(iii) Write the coding for exit button to close the application.
Source code:
(i) private void jComboBox1ActionPerformed(java.awt.event.ActionEvent evt) {

if(jComboBox1.getSelectedItem().toString()=="Computer")

jTextField1.setText("50000");

else if(jComboBox1.getSelectedItem().toString()=="Laptop")

jTextField1.setText("30000");

else if(jComboBox1.getSelectedItem().toString()=="Mobile")

jTextField1.setText("10000");

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

float price,amt,dis=0.0F,netamt; int qty;

price = Float.parseFloat(jTextField1.getText());

qty = Integer.parseInt(jTextField2.getText());

amt = price * qty;

if((amt>50000)&&(amt<=200000))

dis = amt * 10/100;


}

else if(amt > 200000)

dis = amt * 20/100;

netamt = amt - dis;

jTextField3.setText(" "+amt);

jTextField4.setText(" "+dis);

jTextField5.setText(" "+netamt);

(iii)

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

System.exit(0); }

Result:

Thus the program is executed successfully.


8. Ms. Sharma works as a programmer in “ABC Car Rental Company” where she has
designed a software to compute charges to be paid by the client. A screenshot of the same is
shown below :

A client can take any car out of Deluxe/SemiDeluxe/Ordinary for rent.

A client can also opt for services of a guide. Charges vary depending on the
type of car opted.

Charges of services of Guide are extra.

Help Ms. Sharma in writing the code to do the following :

(i) After selecting appropriate Radio Button and checkbox(if required),


when ‘CALCULATE’ button is clicked, Amount, Guide Charges and
Total Amount should be calculated and displayed in the respective
text fields.
Category of Car Amount (in C)

Deluxe Car 1000 per day


Semi Deluxe Car 800 per day
Ordinary Car 700 per day

Amount is obtained by multiplying per day charges of Car with number of


days for which the car is taken.

If ‘Guide Required’ checkbox is selected, Guide charges per day are 500.00.

Guide Charges is calculated as : Car required for No. of days * 500; Total Amount
=Amount+Guide Charges

(ii) When ‘CLEAR’ button is clicked, all text fields and checkbox should
be cleared.

(iii) When ‘CLOSE’ button is clicked,the application should close

Source code:
(i) int nod;
double amt=0,gc=0,totamt;
nod=Integer.parseInt(jTextField3.getText());
if(jRadioButton1.isSelected())
{
amt=nod*1000;
if(jCheckBox1.isSelected())
{

gc=nod*500;
jTextField5.setText(""+gc);
}
}
else if(jRadioButton2.isSelected())
{
amt=nod*800;

if(jCheckBox1.isSelected())
{
gc=nod*500;
jTextField5.setText(""+gc);
}

}
else if(jRadioButton3.isSelected())
{
amt=nod*700;
if(jCheckBox1.isSelected())
{

gc=nod*500;
jTextField5.setText(""+gc);
}
}

totamt=amt+gc;
jTextField4.setText(""+amt);

jTextField6.setText(""+totamt);

(ii) jTextField1.setText("");
jTextField2.setText("");
jTextField3.setText("");
jTextField4.setText("");
jRadioButton1.setSelected(false);
jRadioButton2.setSelected(false);
jRadioButton3.setSelected(false);
jCheckBox1.setSelected(false);

(iii) System.exit(0);

Result:

Thus the program is executed successfully


9. XYZ Co.has computerized its salary generation.The following is the data entry form
in java used by them.

(a) On clicking set initial button the textfields for DA,HRA,PF,IT,Gross salary and
netSalary editable property should be set to false.

(b) on clicking the calculate salary button the salary should be displayed as per the
criteria as follows.
DA:60% of Basic
HRA:30% of Basic
PF:10% of Basic(will be deducted)
IT :5% of gross
There are two job types
 permanent
 ADhoc
For permanent employee calculate gross salary as :
Gross =sum+hra+da
netsal=gross-pf-it

For asdhoc employee calculate gross salary as :


Gross =sum+hra+da
netsal=gross-pf

(c)When ‘CLEAR’ button is clicked, all text fields and checkbox should be cleared.

(d)When ‘CLOSE’ button is clicked,the application should close.


Source code:
(a) jTextField5.setEditable(false);

jTextField4.setEditable(false);

jTextField6.setEditable(false);

jTextField7.setEditable(false);

jTextField8.setEditable(false);

jTextField9.setEditable(false);

jRadioButton1.setSelected(true);

jRadioButton2.setSelected(true);

(b) double da, hra, pf,it=0,gross,netsal=0;

double basic=Double. parseDouble(jTextField3.getText());

da=basic*0.60;

hra=basic*0.30;

pf=basic *0.10;

gross=basic+hra+da -pf;

if(JRadioButton2.isSelected())

netsal=gross-pf;

else if(jRadioButton1.isSelected())

it=basic *0.05;

netsal=gross-it;

jTextField5.setText(""+hra);

jTextField4.setText(""+da);

jTextField6.setText(""+pf);

jTextField7.setText(""+it);
jTextField8.setText(""+gross);

jTextField9.setText(""+netsal);

(c)

jTextField1.setText(" ");

jTextField2.setText(" ");

jTextField3.setText(" ");

jTextField4.setText(" ");

jTextField5.setText(" ");

jTextField6.setText( " ");

jTextField7.setText(" ");

jTextField8.setText(" ");

jTextField9.setText( " ");

(d) System.exit(0);

Result:

Thus the program is executed successfully.


10. Ms. Fauzia works as a programmer in ‘‘TelTel Mobile Company’’ where she
has designed a software to compute charges to be paid by the mobile phone user. A
screenshot of the same is shown below :

Each Call is charged at < 1·00.


Each SMS is charged at < 0·50.
Users can also opt for Mobile Data Plan. Charges for Mobile Data Plan are
flat < 50·00.

Help Ms. Fauzia in writing the code to do the following :


(i) When the Calculate Charges button is clicked, Calls and SMS
Charges, Mobile Data Plan Charge’ and ‘Amount to Pay’
should be calculated and displayed in the respective text
fields.
‘Amount to Pay’ is calculated as :
Calls and SMS Charges + Mobile Data Plan Charges (if any)
(ii) When the Clear button is clicked, all the textfields and
checkbox should be cleared.
(iii) When the Exit button is clicked, the application should close.
Source code:
(a) int Calls, Sms;
double Total,dataAmt = 0, grandTot, callsChg ,smsChg;
Calls = Integer.parseInt(jTextField3.getText());
Sms = Integer.parseInt(jTextField4.getText());
callsChg = Calls * 1.00 ;
smsChg = Sms * 0.5 ;
Total = callsChg + smsChg;//Total=(Calls*1.00)+(Sms*0.5);
if (jCheckBox1.isSelected())
dataAmt = 50.00;
grandTot = Total + dataAmt;
jTextField5.setText(“”+ Total);
jTextField6.setText(“”+dataAmt);
jTextField7.setText(“”+grandTot);
(b)
jTextField1.setText(“”);
jTextField2.setText(“”);
jTextField3.setText(“”);
jTextField4.setText(“”);
jTextField5.setText(“”);
jTextField6.setText(“”);
jTextField7.setText(“”);
jCheckBox1.setSelected(false);
(c) System.exit(0);

Result:

Thus the program is executed successfully.


11. Hotel Hill Top Inn in Ooty plan to go for computerization in order to meet the workload during
tourist session. There are three types of rooms available in Hill Top.

(a)Write the code to disable the text boxes txtRate,txtAmount.txtFacility when the form activated.
(b)Write the code for cmdClear command button to clear all the textboxes.

(c)Write the code for cmdRate to calculate rate of the room per day and display it in txtRAte
depending on the type of room selected by the customer. Rate is calculated according to the following
table:

Room Type Rate per day


Single 1500
Double 2800
Delux 5000

(d)Write the code for cmdAmount to calculate the total amount and display it in txtAmount.The total
amount is
calculated by first finding the cost of facilities selected by the customer. Cost of facilities is calculated
according to the following table:

Facility Cost
Tour Package 7000
Gym 2000
Laundry 1000
Source code:
public class NewJFrame15 extends javax.swing.JFrame {
public NewJFrame15() { initComponents();
jTextField4.setEnabled(false);
jTextField5.setEnabled(false);
jTextField3.setEnabled(false);
}
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
jTextField3.setEnabled(true);
if(jRadioButton1.isSelected())
r=1500;
else if(jRadioButton2.isSelected())
r=2800;
else if(jRadioButton3.isSelected())
r=5000;
jTextField3.setText(""+r);
}
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
jTextField4.setEnabled(true);
jTextField5.setEnabled(true);
int n;
double r,c=0,amt;
n=Integer.parseInt(jTextField2.getText());
r=Double.parseDouble(jTextField3.getText());
if(jCheckBox1.isSelected())
c=c+7000;
if(jCheckBox2.isSelected())
c=c+2000;
if(jCheckBox3.isSelected())
c=c+1000;
amt=r*n+c;
jTextField4.setText(""+c);
jTextField5.setText(""+amt); }
private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {
jTextField1.setText("");
jTextField2.setText("");
jTextField3.setText("");
jTextField4.setText("");
jTextField5.setText(""); }
private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {
System.exit(0);
}
Result:

Thus the program is executed successfully.


12.ABC super store has decided to computerize its billing department.

a)The price textField should not have a negative or zero value. if a negative or zero
value is entered then the textfield should be made blank and a warning message in the
window should be displayed. The final price and the discount is based on the following
table. Give an additional discount of 5% if member checkbox is checked.
Category Discount
Footwear 30%
Apparels 20%
(b) write the code for clear button to clear all the textfields
(c) write the code for exit to close the application.

Source code:
(a) double disc=0,mdisc=0,discamt,famt;
double price=Double.parseDouble(jTextField3.getText());
if(price<=0)
{
JOptinPane.showMessageDialog(null,"wrong input");
jTextField3.setText("");
}
if(jRadioBuuton1.isSelected())
disc=0.30;
if(jRadioButton2.isSelected())
disc=0.20;
if(jcheckBox1.isSelected())
mdisc=0.05;
discamt=(price*disc)+(price*mdisc);
famt=price-discamt;
jTextField4.setText(""+discamt);
jTextField5.setText(""+famt);

(b)
jTextField1.setText("");
jTextField2.setText("");
jTextField3.setText("");
jTextField4.setText("");
jTextField5.setText(""); }

(c)System.exit(0);

Result:

Thus the program is executed successfully.


13.Design a GUI application for the code to count number of vowels in a given string.

Character

check

Source code:
String S= jTextField1.getText();

int x=S.lenghth();

int vowel=0;

for(int i=0;i<x;i++)

String a=S.subString(i,i+1);

a=a.toLowerCase();

if(a.equals("a")||a.equals("e")||a.equals("i")||a.equals("o")||a.equals("u"))

vowel++;

jLabel1.setText("Number of vowels are:"+vowel);

Result:

Thus the program is executed successfully.

Vous aimerez peut-être aussi