Question Bank - Java Programming

Download as pdf or txt
Download as pdf or txt
You are on page 1of 30

QUESTION BANK – JAVA PROGRAMMING

1) Write a java code to display the system date and the date before 763 days from system date
today‟s date.

2) Write a code in java which take 10 numbers store it in a combo box and display the greatest
one.
3) WAP to input any number „n‟ and print the product of all its digits.

For e.g. if n=235 then print 5*3*2=30

4) Write a code in java to generate single calculator using classes and accepting the two integers and
operator with all methods to input, display, add, subtract, product and division.

5) Write a java code to get the output as shown below if the user input the String „D‟.

A
B A
C B A
D C B A
6) Write a java code to find area of a rectangle and triangle by using class hierarchy.

7) Write a java method which take a float argument and return integer without using type casting and
round method.
8) Read the following case study and answer the questions that follow:

ABC Company has developed the following interface to enter and display data related
to Income Tax of employees.
(a) When Calculate button is clicked, Income Tax, Education Tax, Surcharge, and Total
Tax( Sum of Income Tax, Education Tax, Surcharge) is displayed in their respective text
boxes based on the following criterion

(b) When the user clicks the clear button all textboxes should be set to zero.

Taxable Income Income Tax Education Tax Surcharg


e

Upto 1,00,000 Nil Nil Nil

1,00,000 to 1,50,000 10 % of the amount 2% of Taxable Nil


exceeding 1,00,000 Income

1,50,000 to 2,50,000 5,000 + 20% of 2 % of Taxable Nil


Income
amount exceeding 1,
50,000

2,50,000 and above 25,000 + 30 % of the 2% of Taxable 1% of


amount exceeding Income taxable
Income
2,50,000

9) The given form Calculates the GCD (HCF) of two Number‟s Write code for the command
button (jbutton1) to print the GCD in the jTextField3.

10) Create an application that receive a number through a jTextField1 and Print the sum of the
individual digits when the submit button is pressed. (2)
11) Write a Program in Java to Calculate the Factorial of an Integer using a while loop. (2)

12) Write a Program in Java to display the following series upto 10 terms (2)
10 13.5 17 20.5 24.0…………

13) Write a Program in Java to print series squares of first 10 Natural numbers and their sum.

14) Using For…..Loop display the following pattern :

**

***

****

*****

******

*******

********

*********

15) Read the following case study and write a java code to answer the questions that following.
Manager of Bachat Bank has developed a java form for finding EMI to be paid by customers
against repayment of loan. Loan interest rates are(Yearly) -

Loan Type Interest Rate

Car Loan. 14.5 %

Personal Loan 13.25 %

Education Loan 11.75 %


a) Initially loan type should be set to Car Loan, jtxtRate should be disabled and jcmbYears should
have values 5,10,15, and 20.
b) If loan amount is less than or equal to 0. It should display an error message “Invalid Amount”
and cursor should point to jtxtLoanAmt.
c) When the user clicks the CmdCalcEMI button, the total payable EMI should be calculated and
displayed in the jtxtEMI text box. To calculate EMI, firstly calculate compound interest using
formula ci=p*(1+r/100)^t. Add compound interest to loan amount and divide by time (in
months).
d) Write the code for jCmdExit button to stop the application and jCmdClear command button to
clear all the text boxes, option buttons. Also cursor should point on jtxtLoanAmt test box.

16. Define a class Bank to represent the bank account of a customer with the following specification

Private Members:

- Name of type character array(string)

- Account_no of type long

- Type_of_account ( S for Saving Account, C for current Account) of type char

- Balance of type float

Public Members:

A constructor to initialize data members as follows

- Name NULL

- Account_no 100001

- Type_of_account „S‟

- Balance 1000

(i) A function NewAccount() to input the values of the data members Name, Account_no,
Type_of_account and Balance with following two conditions
 Minimum Balance for Current account is Rs.3000

 Minimum Balance for Saving account is Rs.1000

(ii) A function Deposit() to deposit money and update the Balance amount.

(iii) A function Withdrawal() to withdraw money. Money can be withdrawn if minimum balance is
as >=1000 for Saving account and >=3000 for Current account.

(iv) A function Display() which displays the contents of all the data members for a account.

17. Write a java method to fetch the data from the employee table and display it in jTable the method
already having Connection class object name con, Statement class Object name smt and ResultSet class
object rs with the following query SELECT EMPNO, ENAME, JOB, SAL FROM EMP‟ . 3

18. Write a java method to get the sum of the following series: 3

19. Write a Method in Java to take a number as argument and print the product of its digit, as if a
number entered is 234 then the program gives output as 24.

20. Read the following case study and answers the question that follows:

ABC Company has developed the following interface to enter and display data related to Income
Tax of employees.

Write the code to implement the following:


(a) When the Frame loads Text Fields for Income Tax, Education Tax, Surcharge and Total Tax
Amount should be disabled. They should also be enabled when Calculate command button is clicked.
(b) Taxable income entered should be numeric data only.
(c) When the user clicks the clear command button, the Text Fieldes EmpCode and EmpName should
be set to blank and other TextFields should be set to zero.
(d) When calculate command button is clicked, Income Tax, Education Tax, Surcharge and Total Tax
(sum of Income Tax, Education Tax and Surcharge) is displayed in their respective Text Fields
based on the following criterion:

Taxable Income Income Tax Education Tax Surcharge


Upto Rs. 1,00,000 Nil Nil Nil
Rs. 1,00,001 -Rs. 10% of the amount exceeding Rs. 2% of Taxable Nil
1,50,000 1,00,000 Income
Rs. 1,50,001 – Rs. 5000 + 20 % of the amount 2% of Taxable Nil
Rs.2,50,000 exceeding Rs. 150,000 Income
Rs. 2,50,001 and Rs. 2,50,000 + 30% of the amount 2% of Taxable 1% of the Taxable
above exceeding Rs. 2,50,000 Income Income

21. Write a method in Java that takes two integer arguments and returns power of it. Suppose x and y
passing as an argument then it returns x to power y after calculation.

22. Write a program to check given no is prime number or not. The number is prime if number is
divisible by 1 and itself.
23. Write a Method in Java to take a number as argument and print the product of its even digits, as if
a number entered is 234 then the program gives o/p as 2*4=8.
24. Write a java method that takes an integer N as input parameter and displays the sum of all the
digits in the number.

25. Design a class to represent a bank account. Include the following members:

Data Members:

 Name of the depositor


 Account number
 Type of account(Savings/Current)
 Balance amount in the account(Minimum balance is Rs.500.00)
Methods:


To read account number, Depositor name, Type of account

To deposit an amount ( Deposited amount should de added with it)

To withdraw an amount after checking balance(Minimum balance must be
Rs.500.00)
 To display the balance
( Assume necessary interface (with NetBeans IDE) for above program)

26. Read the following case study and answer the questions that follow:

Mr.Basu of MEGA MALL decided to computerize the billing department. The accounts
manager at MEGA MALL is creating the billing software to generate the bill during the sale
period. A new bill is generated for each item sold. The discount is given based on the item category.
An additional discount of 5% is given to the MEGA MALL card holders. The following is data entry
screen used at the MEGA MALL:

(a) Write the code for the Clear Button to clear all the JTextFields.

(b) Write the code for the TestJB button to ensure that the user does not enter a negative or a zero
value in txtItem JTextField.If a negative or a zero value is entered that txtItem should be made
blank and a warning message should be displayed through a JOptionPalne.

(c) Write the code for the Calculate button to display the discount and final price in the txtDiscount
and txtFP JTextFields respectively. Note that final price is calculated as (price – discount) and the
discount is calculated based on the category and price according to the following table. Also
remember to given an additional 5% discount for membership card holders i.e. if the CHCheck
JCheckBox is checked.

Category Price Discount

Men‟s <10000 30%

>=10000 50%

Women‟s <8000 40%

>=8000 50%

Kid‟s <5000 20%

>=5000 30%
(d) Write the code for ExitJB button to exit from the application.

27. WAP to input Basic salary of a person and calculate Net salary in Rs. after increasing his
salary as per the following criteria and Display the Net Salary.

Basic(Rs.) %increase
< 3000 2
>=3000<5000 5
>=5000<10000 10
Above 10000 20
28. Write a java code to input height(in inches) in a text field and convert it into feet and inches.
Display the final result in feet and inches. . For e.g. if height is 77 inches then after conversion it
will be 6 feet 5 inches. [ 1 feet=12 inches]
29. Consider the form given above and write code for the following:-

i) When „compute discount‟ button is clicked, the discount


should be calculated as per the following criteria:-
COST(Rs.) DISCOUNT(%)
<1000 5
>=1000 10
NOTE:- The extra discount of 3%, 2% and 1% should be given
for electrical appliances, electrical gadget and stationery
respectively.
ii)On clicking „Compute Net Amount‟ , the net amount must be
calculated and displayed in textbox 3 after giving desired
discount.

30. Observe the form given below and write a java code for the following:-

i) The list box should be populated with following 4


accessories when the form is opened.
ii) The text fields 1 & 3 must be set to non-editable.
iii) The default choice should be set to List Item1.
iv) Upon clicking the button, the price of selected
accessory should be displayed in TextField 1 and total
cost should be displayed in TextField3, on the basis
of given criteria:-
Accessory Price(Rs./Item)
Charger 45
EarPhone 100
Battery 250
Card 225
31. Write code for the following:-

i) The „cost‟ text field should contain only non-negative value.


ii) The jComboBox1 must contain Economic, Business and Luxury when the form window is
opened.

iii) The „material quality‟ should be set as „Luxury‟ by default.

iv) When „calculate‟ button is clicked, the cost should be calculated & displayed as per the following
criteria and message should be displayed on jLabel4 as given on the form:-

Material COST(Rs./sqm)
Economic 50
Business 80
Luxury 120
v) The „cost‟ text field could not be edited.

32. Create a class player as follows:-

Data members:- pname(String),innings(int),runs(int),notouts(int)

Methods:-

i) void showdata() – to display the details of player.


ii) Void calcAvg() – to calculate batting average of player as follows:-
Bat. Avg= runs/(innings-notouts);

WAP to create an object of class Player to input player details and invoke all its methods.

33. Give the name of the methods required to perform the following tasks in Java:-

i) To check the equality of two strings.


ii) To extract a set of characters from a given string.
iii) To get the character present at specified index.
iv) To find the index of the last occurrence of the specified character.

34. WAP to input any string and count total no. of uppercase and lowercase letters separately.

35. Write a method that takes a number as argument and check whether it is perfect or not.

36. Write a method that takes a fractional number as argument and print only its integer part.
37. Write a method that takes distance in inches as argument and convert it into feet and inches.For
example- if distance is 15 inches then result will be 1 feet 3 inches.
38. The shop-n-save store has developed the following data entry screen for its operations. The store
offers 3 different types of membership discount schemes for its regular customers. Platinum
members get a discount of 10% on all their purchases, Gold members get 5% and Silver members
get 3% discount.

Write a java code to add the following functionalities:-

a) to disable the text fields AMOUNT, DISCOUNT AND NET.

b) To remove the decimal part from the text field NET so that the net amount contains only the
integer portion in rupees.

c) The GOLD radio button should be selected by default when the form is opened. Also write the
appropriate event.

d) To calculate amount, discount and net amount as per the descriptions and conditions. The
formulas are as follows:- Amount = quantity * rate and Net Amount = Amount - Discount

e) WAP to input any number and print its first 10 multiples.


39. Observe the form given below and write a java code on the click of button to calculate the cost of
food items selected by the customer.

40. Name the method to perform the following operations in java Swing:-

i) to get the name of selected item from list box.


ii) To check whether the check box is selected or not.
iii) To enable/disable the text field.

41. Community Works Department has proposed the following layout to obtain the details of volunteers
for a community work project running in your school. The user types his/her roll number and
selects his/her stream and section from the jList provided. Upon clicking the „submit‟ button, the
selected contents of two lists and rollno are merged in the order <stream><section><Rollno> and
added to the combo box. Write a java code to implement the above metioned functionality.

42. The shop-n-save store has developed the following data entry screen for its operations. The store
offers 3 different types of membership discount schemes for its regular customers. Platinum
members get a discount of 10% on all their purchases, Gold members get 5% and Silver members
get 3% discount. The Regular customer gets an additional discount of 2% more.
43. Write the java code to add the following functionalities:-
i) to disable the text fields DISCOUNT AND NET.
ii) To remove the decimal part from the text field NET AMOUNT so that the net amount contains
only the integer portion in rupees.
iii) The GOLD radio button should be selected by default when the form is opened. Also write the
appropriate event.
iv) To calculate amount, discount and net amount as per the descriptions and conditions. The
formulas are as follows:-
Amount = quantity * rate
Net Amount = Amount – Discount
v) Write the code for cmdExit to close the application, but before the application is closed it should
check the net amount and if the net amount > 10,000 the membership of the customer should be
upgraded to the next higher level and a message box informing the customer should be
displayed. For example if the customer already has Silver membership it should be upgraded to
Gold and he should be informed of the same using a message box.
44. The YOUWE Event Managing Company is organizing a shopping festival in the Shopping Mall. The
company gives a discount on the total amount spend (in all the shops) in the mall. The discount is
given based on the credit card used. The following is the layout of the form:-
Write the Java code for the following:-

i) To display the message “Thank You for shopping” and to close the application when EXIT
button is clicked.
ii) To clear all the text fields when “clearALL” button is clicked and set the default choice to VISA.
iii) To apply a check so that user could not enter negative or zero value in „Shopping Amount‟ text
field. If user does so, the text field should be made blank and a warning message should be
displayed.
iv) Calculate and display discount and net price in appropriate text fields.
Net Price= Shopping Amount – Discount
The discount is calculated based on credit card and total shopping amount as follows:
Credit Card Type Shopping Amount(Rs.) Discount(%)
VISA <5000 10
>=5000 20
XYZ <10000 15
>=10000 25
ABC <8000 12
>=8000 15

45. Create a class Height to store height in feets and inches. WAP to input height in inches in a text box
and store it in an object and then convert it into feet and inches. Display the result in respective text
boxes.
46. Sumeet electronics has the following products with their list prices given .Create a class SHOP to
store product name & price of product. Write following class methods:-

i) void getinfo() – to input details of product through arguments.

ii)void showinfo() – to show details of product.

47. The store gives a 10% discount on every product. However at the time of festive seasons, the
store gives a further 7% festival discount in addition to 10%. Write a Java program to create an
object of class SHOP and take input of product name only. Calculate the List Price & Net price
for a product after giving discount after selecting either festival or non-festival radio buttons.

Product List price(Rs.)


Washing machine 12000
Colour TV 17000
Refrigerator 18000
OTG 8000
CD Player 4500

48. Define a class SPORTS with the following

specifications :

Private Members:

SCODE(long),SNAME(String),Fees(int),
Duration(int)
Public members:

i) Default constructor to assign initial values of


S_CODE as 1001, S_NAME as “CRICKET”, Fees as 500 and Duration as 70.

ii) Argument constructor to assign values to SCODE, SNAME and Duration through arguments
and assign the fees as per following conditions:
SNAME Fees

TABLE TENNIS 2000

SWIMMING 4000

FOOTBALL 3000

iii) void showsport ( ) to display the contents of all data members on screen.
WAP to create an object of this class & take input using text boxes and invoke argument constructor.
49. Pizza cafe software has provided the following Pizza order form for the customer.
The rate of Regular Pizza is Rs. 60 and of Pan Pizza Rs. 80.

(i) Write the code to clear all the check boxes.

(ii) Write the code to find the cost of toppings(Rs.10 each) selected by customer and then to
calculate the amount as follows:-
Amount=(Rate + cost of toppings)*quantity

50. A programmer is required to develop a student record. The school offers two different streams,
medical and non-medical, with different grading criteria.
The following is the data entry screen used to calculate percentage and grade.

(i) Write code to prevent the user from entering negative value in „Percentage‟ text field.

(ii) Write the code for the „Clear‟ button to set the default choice to “Medical”.

(iii)Write the code to close the form when „Exit‟ button is clicked.

(iv) Write the code for the „Calculate Percentage‟ button to calculate the percentage and
display in text field „Percentage‟, after finding the total marks of first term and
second term (assuming that both marks are out of 100).
51. Write a java program to print the following triangular pattern:-

**

***

* * **

*****

52. Write a java program to input two numbers x and y and count total number of prime
numbers
between x and y. For example if x=1 and y=10 then o/p is 4.

53.
54.
Glamour Garments has developed a GUI application for their company as shown below

The company accepts payments in 3 modes- cheque , cash and credit cards. The discount given as per
mode of payment is as follows.

If the Bill Amount is more than 15000 then the customer gets an additional discount of 10% on Bill
Amount.
(i) Write the code to make the textfields for Discount (named txtDisc) and Net Amount
(named txtNetAmt) uneditable.
(ii) Write code to do the following:
(a) Write a method that takes “Bill Amount” as argument and calculates discount when "Calculate
Discount" button is clicked and it should be displayed in the discount textfield. "Calculate Net
Amount" button (named btnCalcNetAmt) should also be enabled.
(b) Write a method to calculate Net Amount when"Calculate Net Amount" button is clicked and it
should be displayed in the net amount textfield.

55. Define a class Electbill that contains consumer details as follows:-


Data members/Instance variable :
cno (long) //consumer number
cname (String) // consumer name
cadd (String) // consumer address
NOU(long) // to store number of units consumed
Member functions / Methods :
(i) Electbill(....) : Parameterised constructor to assign values to consumer
number, consumer name and address
(ii) void display() : Display consumers details
(iii) void calculate() :Calculate the monthly bill of consumer according to following
slabs and it should also display the total amount to be paid .
Number of units consumed Rate
1 – 100 Rs 500/-rental charges only
101 - 200 Rs 1.00 per call + rental charges of Rs. 500
201 - 300 Rs 1.20 per call + rental charges of Rs. 500
Above 300 Rs 1.50 per call + rental charges of Rs. 500
56. WAP to create an object of class Electbill and invoke all its methods.

For the following GUI application. The percentage


marks are to be entered in the TextField and upon
clicking the Button, corresponding grade (as per
following rules ) should
Marks Grade
be displayed in the
Percentage
Label.
> =60 A++

>=45<60 B

>=33<45 C

<33 F

57. The Manager of Bachat Bank has developed a java form for finding EMI to be paid
by customers against repayment of loan.
Loan interest rates are(Yearly) -
Loan Type Interest Rate
Car Loan 14.5 %
Personal Loan 3.25 %
Education Loan 11.75 %

(i) Initially loan type should be set to Car Loan & InterestRate box should
be disabled.
(ii) If loan amount is less than or equal to 0. It should display an error
message “Invalid Amount”
(iii) When the user clicks the Calculate EMI button, the total payable EMI
should be calculated and displayed in the EMI text box. To calculate
EMI, firstly calculate compound interest using formula
ci=p*(1+r/100)^t. Add compound interest to loan amount and divide by
time by time(in years) * 12.
(iv) Write the code for Exit button to stop the application and Clear button
to clear all the text boxes & option buttons.
58. Write a java code to input time (in minutes) in a text box and convert it
into hours and minutes. Display the result in respective text boxes.

59. Write a java program to input any number in a text box and print the sum of its odd factors only.
Example:-
If number is 36 then its factors are 1,2,3,4,6,9,12,18 and sum of its odd factors is 1+3+9=13.
60. “Electro Bazaar” offers 5% discount to all the customers. However, if customer type is “regular”
then additional discount of 10% is given to that customer.

Create a class “BILL” as follows:-


Data members/Instance Variables:-
Amount - double type
Cust_type - String (can either be „regular‟ or „occasional‟)
Methods:-
i) Argument Constructor – to assign values to data members through arguments.
ii) void compute() – to calculate and display the discount(in Rs.) and Net Amount(in Rs.) in the
following format. Net Amount is calculated as Amount – Discount.
Bill Amount Discount(Rs.) NetAmount(Rs. )

Xxxxxxxxxx xxxxxxxxxxx xxxxxxxxxxxxxx

Write a Java program to create an object of class BILL and invoke constructor and compute().
61. Create an interface COST as follows:-
Method:-
public void calcPrice(int qty) - that takes 'qty' as argument and calculate total cost(price*qty).

Also Create a class SoftDrink as follows:-

Data members:-

dcode (long) // drink code

dname(String) // drink name

price(double)

Methods:-

i) showdetails() - to display details of drink

The class SoftDrink must also implement an interface COST.

WAP to input drink details using class SoftDrink object and invoke all the methods of class &
interface.
62. Create a class "Employee" as follows:-

Instance variables:- empno(long), empname(String), job(String);

Methods:-

i) void showinfo() - to display details of employee.

Create another class "Salary" that inherits from class "Employee" as follows:-

Instance variables:- basic(double), newsal(double)


Methods:-

i) void calculate(double perc) – that takes percentage amount “perc” as argument and
calculates newsalary by incrementing the basic salary by that percentage amount.
ii) void dispdata() – to display basic salary.
Write a Java program to create an object of class Salary to input details of employee and also
invoke showinfo(), calculate() and dispdata() methods.

63. The FOR U SHOP has computerized its billing. A new bill is generated for each
customer. The shop allows three different payment modes. The discount is given based
on the payment mode. The following is the data entry screen used at to generate the bill.

(i) Write the code for the CmdClear Button to clear all the Text Fields and default Payment
Mode must be „Cash‟ by default.

(ii) Write the code for the Calculate Button to display the Discount Amount and Net Price in
the Discount and the NetPrice Text Fields respectively. Note that Net Price is calculated
as Shopping Amount – Discount Amount and the discount is calculated based on the
credit card and the total shopping amount according to the following table:-

Credit Card Shopping Discount


Type Amount
< 10000 20 %
Cash
>= 10000 25 %
< 15000 10 %
Cheque
>= 15000 15 %
< 10000 10 %
Credit Card
>= 10000 12 %
(iii) Write the code for Exit button to display a message “Thank You “and exit out of the
application.

64. Define a class Travel with the following descriptions :


Data members/Instance variable :
TravelCode(long),Place(string),No_of_travellers(int),No_of_buses(integer)
Member functions / Methods :
i) A constructor to assign initial values of TravelCode as 201, Place as “Nainital”,
No_of_travellers as 10, No_of_buses as 1
ii)A method NewTravel() which allows user to enter TravelCode, Place and No_of_travellers
through arguments. Also, assign the value of No_of_buses as per the following conditions :
NoofTravellers Noofbuses

Less than 20 01

Equal to or More than 20 and less than 40 02

Equal to 40 or more than 40 03

iii)A method ShowTravel( ) to display the content of all the data members on screen.
WAP to create an object of class Travel and invoke all its methods.

65. Design the following form and calculate DA,HRA,Gross Sal, Annual Sal & TotalTax as given:-

66. WAP to input any digit number and print the sum of only its even digits. Example: 2354=2+4=6.

67. WAP to input two numbers and check whether it they are special Prime or not.
Example:- A special prime is a prime number that differs from another prime number
by six such as (7,13),(11,17), etc.
68. Design the given form and calculate the total cost & discount(only if customer is Special) as given
on the form. A special additional discount of 10% is given to special customers.
69. Define a class TOUR as follows:-

Private Members:-
Tcode(string),Noofadults(int),Noofkids(int),kilometres(int),totFare(float)
Public:
i) A constructor to assign initial values as follows:-
Tcode with the word “NULL”, Nofadults,Noofkids,kilometres & totfare with zero.
ii) A function AssignFare() which calculates and assigns the value of data members TotFare as
follows:-
For Each Adult
Fare(Rs.) For Kilometres

500 >=1000

300 <1000 & >=500

200 <500

For each kid the above fare will be 50% of the Fare mentioned above.

Example if distance is 850 km and Noofadults are 2,Noofkids are 3 then TotFare=1050Rs.

iii) EnterTour() to input values for Tcode, Nofoadults,Noofkids and kilometres through
arguments.

iv) ShowTour() to display the details of all the data members along with total fare.

70. WAP to input a string and count only those words that starts with uppercase vowel.

Example:- if string is “Carry An Umbrella” then o/p is:- 2

71. Define a class POWER in C++ with following description:

Private Members:-

MetreNo(long),CName(string),Units(long),Charges(float)
Public Members:-

i) A function CALCCHARGE( ) to calculate Charges according to the following conditions:

Units Charges
Below 100 Units Rs. 2.00 per Unit

Below 200 Units and > = 100 Units Rs. 3.00 per Unit

> = 200 Units Rs. 5.00 per Unit

For Example: If the Units are 392, Charges will be Rs. 1463/-

ii) A Function Enterdata( ) to allow user to enter values for MetreNo, CName, Units &

through arguments.

iii) A Function ShowBillI( ) to view the contents of all the data members.

72. WAP to input your full name and print its initials.

Example:- if name is “Amit Kumar Singh” then print A.K.S

73. Design the following form and calculate Total charges according to the following criteria:-

Seat Type Charges(Rs.)

Stall 20

Circle 35

Upper 50

Box 80

Display price per seat and payment mode on respective Labels.

74. Observe the form given below and write a java code on the click of button to calculate the total
cost of food items selected by the customer.
75. WAP to input Basic salary and calculate TA,DA,HRA & Net salary in Rs. and display them IN
respective text boxes as per the following criteria:-
Basic(Rs.) TA(%) DA(%) HRA(Rs.)
below 3000 NIL NIL NIL
3000 to 5000 5 10 500
5000 to 10000 10 20 1000
Above 10000 20 30 2000

Formula is :- Net Sal=Basic+TA+DA+HRA

76. Mr. Das is working as a Chief Information Officer in AMD Constructions Company. In this
month of January he received a letter form the management to store all his employee
information in electronic form. He decided to develop a small software application to store
employee‟s personal data. He instructed one of his juniors to make a form in VB to enter employee
information. The junior presented the following form to Mr. Das :

The form details are given in the following table :


(i) Write a Code snippet on click event of „ClearForm‟ command button to clear text boxes
ii) Write code to set default choice as option button1.
iii) Write code to clear all check boxes controls.
iv) Write code to close the form and display the gender selected.
v) Write a method procConvertCase to convert all the employee details in textbox1, 2 & 3 to
Upper Case character and display separately.
v) Write a method that takes your name as argument and print its length & reverse.
77. An electric shop has announced the following seasonal discounts on the purchase of certain
items:
Purchase Amount(Rs.) Discount on Laptop(%) Discount on Desktop PC(%)
0 to 25,000 0.0 5.0
25001 to 57000 5.0 7.5
57001 to 1,00,000 7.5 10.0
More than 1,00,000 10.0 15.0
Write the code to read compute Discount(Rs.) and Net Amount(Rs.) based on purchase amount
and type of purchase.
Discount=(Discount Rate/100) * Amount of purchase
Net Amount=Amount of purchase – discount

Home Decor Furnishing is a company that manufactures and sells various furnishing items in three qualities (Economy,
Business and Elite) and three sizes (Kids, Adults and Giants). The cost of each furnishing item is calculated on basis of a
Base Cost, which is the cost of the item in Business quality and Adults size. The cost is changed by – 10% and +20% in
case of Economy and Elite quality respectively. Similarly the cost is changed by –5% and +15% in case of Kids and
Giants sizes respectively. The interface for gathering users choice is as given below :

Add the following functionality to the interface:

(a) The combo box cmbquality must contain economic, Business and Luxury when the form loads in the memory.
2
(b) The combo boxes cmbquality and cmbsize should respectively be set to default values of Economy and Adults
initially. 1
(c) PRINT the caption of cmdcalculate button and lblsize. 1
(d) When a user chooses a choice other than the default choices, the labels lblchangeforquality and
lblchangeforsize should display the message. 3
‘Percent Increase / Decreases in cost ....% according to the logic explained above.

(e) When user clicks the Calculate button the final message should be displayed in the label as indicated in the
form image.
Q.5.

a) Write the commands to disable the text box and to set the Total Cost Command Button as default
command button. (1)
b) Write the code for cmdClear Command Button to clear all the checkboxes and TextBox. (1)
c) Write the code for cmdTotCost to calculate the Total Cost for the selected dishes. (3)

Q.6. An institute offers two courses MBA and MCA of duration 2 years and 3 years respectively . The
interface given to capture the marks secured by student in the semester exam.

a) if user select MBA then textboxes for YEAR1 and YEAR2 should be disabled.

a) When the user clicks GPA button ,the total marks and the average marks secured by the student should be
displayed in text boxes txttotal , txtavg respectively depending upon the option MCA or MBA . An overall
GPA in the range 0-10 should be displayed in the message box when the user click it .GPA = Average /10. (
Assume that the marks in each semester are out 600) 4
b) When the user clicks REPORT button , the final report should be displayed in the label lblreport.
30

Q.7. Mr. Vijay has designed a VB form to gather the data regarding the ranks and prize
amounts won by different teams in am annual sports meet. He has used different controls for
storing the sports name, rank and the prize amount respectively. Now he wishes to make the
following changes to the application he designed.

(a) The team Name should be displayed in upper case and the text box for rank should be enabled only
if the corresponding check box is checked. [3]
(b) The text box for prize amount should be enabled only if the corresponding check box is checked
[2]
(c) The contents of the text box prize amount should be a non-negative number. [2]
(d) When the user clicks the command button Calculate Prize Amount, the total prize amount should
be displayed in a message box. [2]
(e) When the user clicks the clear button, the form should be restored to the default state.

MOHIT TANDON www.mscclucknow.com 9839013528, 9838453834

You might also like