Sie sind auf Seite 1von 26

INDEX

S.no. TASK PAGE


NO.
1. Develop a simple calculator app as per the
screenshot, to implement +,-, x, / operations. The text
boxes get cleared when c button is clicked.
2. Develop a Compound Interest calculator app as per
given screenshot, to calculate total amount for the
given amount, Rate of interest and time using
(A=P(1+R/100)r) and Interest (I=A-P)
3. A Quick Fox Transport Company wants to develop
an application for calculating amount based on
distance and weight of goods.
4. Develop a JAVA application to print a pattern for
given character and steps as per given screenshot.
5. Develop an application to compute sum of digits of a
given number.
6. Develop a prime number generator application which
generator prime number for a given range. Prime
numbers are those numbers which are divisible by
one and itself only.
7. Develop a temperature converter application which
converts selected Celsius temperature on a scale and
displays it’s equivalent Fahrenheit temperature.
8. Develop an e-learning application with image and
text information as per the given screenshot.
9. Develop an application as per the given screenshot to
add, remove the given members of the list and
display selected item in a text field using List/Combo
Box control.
10. Develop a billing application for Happy Shoppers &
Retail chain involved in sales of readymade
garments. The Happy Shopping offers discount to its
members holding platinum, gold and silver cards.
The 10% discount is given to platinum card, 8% to
gold card and 5% to silver card holders on sales
amount.

1
2
EXPERIMENT – 1
Objective: Understanding and use of variables of float and other datatypes.

Task: Develop a simple calculator app as per the screenshot, to implement +,-,
x, / operations. The text boxes get cleared when c button is clicked.

Design View: -

Code for ‘+’ button:


int a,b,c;

a = Integer.parseInt(jTextField1.getText());

b = Integer.parseInt(jTextField2.getText());
c = a+b;

jTextField3.setText(c+"");

Code for ‘–‘ button:


int a,b,c;

3
a = Integer.parseInt(jTextField1.getText());

b = Integer.parseInt(jTextField2.getText());
c = a-b;

jTextField3.setText(c+"");

Code for ‘x’ button:

int a,b,c;

a = Integer.parseInt(jTextField1.getText());

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

c = a*b;
jTextField3.setText(c+"");

Code for ‘/’ button:

int a,b, c;
a = Integer.parseInt(jTextField1.getText());

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

c = a/b;
jTextField3.setText(c+"");
Code for ‘C’ button:

jTextField1.setText("");

jTextField2.setText("");

jTextField3.setText("");

Code for ‘OFF’ button:


System.exit(0);

4
Output Window :

5
Experiment – 2
Objective: Understanding the real-life application requirement and
developing a solution.

Task: Develop a Compound Interest calculator app as per given screenshot, to


calculate total amount for the given amount, Rate of interest and time
using (A=P(1+R/100)r) and Interest (I=A-P)
Design View:

Code for ‘CALCULATE’ button:

double principle, amount, interest, rate, time, a = 1, i = 1;

principle = Double.parseDouble(jTextField1.getText());

rate = Double.parseDouble(jTextField2.getText());
time = Double.parseDouble(jTextField3.getText());

while(i<=time)

{
a = a*(1+rate/100);

6
i++;

}
amount = principle*a;

jTextField4.setText(amount+"");

interest = amount-principle;

jTextField5.setText(interest+"");

Code for ‘CLEAR’ button:

jTextField1.setText("");

jTextField2.setText("");
jTextField3.setText("");

jTextField4.setText("");

jTextField5.setText("");
Code for ‘CLOSE’ button:

System.exit(0);

Output window:

7
Experiment – 3
Objective: Understanding and use of nested conditions in real-life
applications.

Task: A Quick Fox Transport Company wants to develop an application for


calculating amount based on distance and weight of goods.
Design view:

Code for ‘CALCULATE’ button:

int distance,weight, charge = 0, amount = 0;

distance = Integer.parseInt(jTextField4.getText());

weight = Integer.parseInt(jTextField3.getText());

if(distance<500)
{

if(weight<100)

8
charge = 5;

else
charge = 8;

else

if(weight<10)

charge = 7;

else if(weight<100&&weight>10)
charge = 6;

else

charge = 5;
}

amount = charge*distance;

jTextField5.setText(amount+"");
Code for ‘EXIT’ button:
System.exit(0);

9
Output Window:

10
Experiment – 4
Objective: Understanding and use of nested loops and use of Text Area
control.

Task: Develop a JAVA application to print a pattern for given character and
steps as per given screenshot.
Design View:

Code for ‘CREATE’ button:


int x = Integer.parseInt(jTextField2.getText());

String a = jTextField1.getText();
for(int i = 1; i<=x; i++)

for(int j = 1; j<=i; j++)


jTextArea1.append(a);

11
jTextArea1.append("\n");

}
Code for ‘EXIT’ button:

System.exit(0);

Output Window :

12
Experiment – 5
Objective: Understanding the use of loops and mathematical operation.

Task: Develop an application to compute sum of digits of a given number.

Design View :

Code for ‘FIND DIGIT SUM’ button:


int x, a, i;
x = Integer.parseInt(jTextField1.getText());

for(i= 10, a=0; x>0; x = x/i)

a+=(x%i);

}
jTextField2.setText(a+"");

Code for “EXIT’ button:

System.exit(0);

13
Output Window :

14
Experiment – 6
Objective: Understanding and developing a logic to solve a problem. Use of
nested loops and breaking it pre-maturely.

Task: Develop a prime number generator application which generator prime


number for a given range. Prime numbers are those numbers which are
divisible by one and itself only.
Design View :

Code for ‘GENERATE’ button:

int num i = Integer.parseInt(jTextField1.getText()), flag=1, y;

num = Integer.parseInt(jTextField2.getText());
for(; i<=num; i++)

for(y = 2; y<=(i/2); y++)


{

15
if(i%y==0)

{
flag = 0;

break;

else

flag = 1;

if(flag==1)
jTextArea1.append(i+", ");

Code for ‘EXIT’ button:


System.exit(0);

Output Window :

16
Experiment – 7
Objective: Use of slider or scroll bar control to get user input and using it for
some calculation.

Task: Develop a temperature converter application which converts selected


Celsius temperature on a scale and displays it’s equivalent Fahrenheit
temperature.
Design View :

Code for Slider:

private void jSlider1StateChanged(javax.swing.event.ChangeEventevt) {


int i;

double temp;

i = jSlider1.getValue();
temp = (i*1.8)+32;

jTextField1.setText(temp+"");

}
Output Window :

17
18
Experiment – 8
Objective: Displaying images on a Label and Text Area control.

Task: Develop an e-learning application with image and text information as per
the given screenshot.

Design View :

Code for ‘KEYBOARD’ button:

jTextArea1.setText("A computer keyboard is one of the primary input.


The keyboard is used as a text entry interface for typing text and numbers
into a word processor, text editor or any other program. In a modern
computer, the interpretation of key presses is generally left to the
software.");
jLabel3.setIcon(new ImageIcon("D:\\Documents\\ IP PROJECT\\
keyboard.jpg"));

19
Code for ‘MOUSE’ button:

jTextArea1.setText("A computer mouse, often simply referred to as


amouse, is a hand-held pointing device that translates the motion of hand
into the motion of a pointer on a display, which allows a smooth control
of the graphical user interface.");

jLabel3.setIcon(new ImageIcon("D:\\Documents\\ IP
PROJECT\\mouse.jpg"));
Code for ‘MONITOR’ button:
jTextArea1.setText("A computer monitor is an output device that
displays information in pictorial form. The display device in modern
monitors is typically a thin film transistor liquid crystal display (TFT-
LCD) with LED backlighting having replaced cold-cathode fluorescent
lamp (CCFL) backlighting.");

jLabel3.setIcon(new ImageIcon("D:\\Documents\\IP PROJECT\\


monitor.jpg"));

Code for ‘CPU’ button:


jTextArea1.setText("A central processing unit (CPU), also called a
central processor or main processor, is the electronic circuitry within a
computer that carries out the instructions of a computer program by
performing the basic arithmetic, logic, controlling, and input/output (I/O)
operations specified by the instructions.");
jLabel3.setIcon(new ImageIcon("D:\\Documents\\IP PROJECT\\
cpu.jpg"));

Code for ‘CLOSE’ button:


System.exit(0);

20
Output Window :

21
Experiment – 9
Objective: Demonstration of use of List/Combo box dynamically through
code.

Task: Develop an application as per the given screenshot to add, remove the
given members of the list and display selected item in a text field using
List/Combo Box control.

Design View :

22
Code for ‘ADD’ button:

String item = jTextField2.getText();


DefaultListModel dl = (DefaultListModel) jList1.getModel();

dl.addElement(item);

jTextField1.setText("");

Code for ‘REMOVE’ button:

String remove = jTextField3.getText();

DefaultListModel dl = (DefaultListModel) jList2.getModel();

dl.removeElement(remove);
jTextField3.setText("");

Code for ‘CLEAR LIST’ button:

DefaultListModel dl = (DefaultListModel) jList2.getModel();


dl.removeAllElements();

Code for ‘CLOSE’ button:

System.exit(0);

23
Output window:

24
Experiment – 10
Objective: Understanding and using the radio button in real life application.

Task: Develop a billing application for Happy Shoppers & Retail chain
involved in sales of readymade garments. The Happy Shopping offers
discount to its members holding platinum, gold and silver cards. The
10% discount is given to platinum card, 8% to gold card and 5% to silver
card holders on sales amount.
Design View :

Code for ‘CALCULATE’ button:

double disc;

if(jRadioButton1.isSelected())

disc = 0.1;

else if(jRadioButton2.isSelected())

disc = 0.08;
else
disc = 0.05;

25
int price, qty;
price = Integer.parseInt(jTextField2.getText());

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

double totalamount, netamount, discount;

totalamount = price*qty;

discount = disc*totalamount;

netamount = totalamount-discount;

jTextField4.setText(totalamount+"");
jTextField5.setText(discount+"");

jTextField6.setText(netamount+"");

Code for ‘CLOSE’ button:


System.exit(0);

Output Window :

26

Das könnte Ihnen auch gefallen