Question Bank - Java Programming
Question Bank - Java Programming
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.
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.
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.
**
***
****
*****
******
*******
********
*********
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) -
16. Define a class Bank to represent the bank account of a customer with the following specification
Private Members:
Public Members:
- 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
(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.
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:
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.
>=10000 50%
>=8000 50%
>=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:-
30. Observe the form given below and write a java code for the following:-
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.
Methods:-
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:-
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.
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
40. Name the method to perform the following operations in java Swing:-
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:-
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.
specifications :
Private Members:
SCODE(long),SNAME(String),Fees(int),
Duration(int)
Public members:
ii) Argument constructor to assign values to SCODE, SNAME and Duration through arguments
and assign the fees as per following conditions:
SNAME Fees
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.
(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.
>=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.
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).
Data members:-
price(double)
Methods:-
WAP to input drink details using class SoftDrink object and invoke all the methods of class &
interface.
62. Create a class "Employee" as follows:-
Methods:-
Create another class "Salary" that inherits from class "Employee" as follows:-
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:-
Less than 20 01
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
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.
Private Members:-
MetreNo(long),CName(string),Units(long),Charges(float)
Public Members:-
Units Charges
Below 100 Units Rs. 2.00 per Unit
Below 200 Units and > = 100 Units Rs. 3.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.
73. Design the following form and calculate Total charges according to the following criteria:-
Stall 20
Circle 35
Upper 50
Box 80
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
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 :
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 :
(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.