0% found this document useful (0 votes)
4 views10 pages

Practical Exam

The document contains practical exam answer sheets for a student named Ruchita Choudhary, detailing multiple Java programs including handling rational numbers, printing current date and time, demonstrating inheritance, creating a calculator, and implementing a Lisp-like list. Each program includes an aim, procedure steps, and code snippets, showcasing various Java programming concepts. The output for each program is also provided, indicating successful execution.

Uploaded by

ruchitakataria17
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views10 pages

Practical Exam

The document contains practical exam answer sheets for a student named Ruchita Choudhary, detailing multiple Java programs including handling rational numbers, printing current date and time, demonstrating inheritance, creating a calculator, and implementing a Lisp-like list. Each program includes an aim, procedure steps, and code snippets, showcasing various Java programming concepts. The output for each program is also provided, indicating successful execution.

Uploaded by

ruchitakataria17
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 10

PRACTICAL EXAM-ANSWER SHEET

Enrollment Number : EC2432251010239 Name of student : Ruchita


Choudhary
Date : 04-07 -2024 Subject Code :
V20PCA101
Name of Subject: Programming Using Java

Title 1:To handle rational number


Aim:
Write a program to handel rational number.

Procedure Steps/Algorithm:
1. Start the program.
2. Read the values for variables n by default passing 5.
3. Find the rational of numbers 5.
4. Using while loop calculate the of function cal
5. Print the rational value.
6. Stop the program.
Program

Import java.util.arraylist;
Import java utils.list;

Class static int cal(int num1, int num2)


{
Int n1= num1;
Int n2 = num2;
While (n1!=n2)
{
If (n1>n2)
N1-=n2;
Else
N2-=n1;
}
Return n1;
}

Class pr
{
Private static class prn
{
Private int numerator;
Private int denominator;
}
@Override
Public String tostring()
{
If (denominator==1)
{
Integer.tostring(numerator);
}
Else
{
Return Integer.tostring(numerator)
+Integer.toString(denominator);
}
}

Private static list<prn>gen(int n )


{
List<prn>= new arraylist<>();
If (n>1)
{
Prn r1= new prn(1,1);
List.add(r1);
}

For (int i=1; i<=n; i++)


{
Int jump=1;
If (I % 2==0)

Jump=2;
Else
Jump=1;
For (int r=1; r<=i-1; r+=jump)
{
If cal (r,i)==1
{
Prn r1= new prn(r,i);
List.add(r1);

}
}

For int(c=i-1; c>=1; c-=jump)


{
If (cal(c,i)==1)
{
Prn r1= new prn(l,c);
List.add(r1);

}
}
}
Return list;
}

Public static void main (String [] args)


{
List<prn>r1=gen(5); -- passing value
System.out.println(r1.stream().Map(prn::tostring).reduce((x,y)>x
+y).get());

Result /Output

INPUT
5
OUTPUT

Result:
Thus the program to perform rational number of 5;

2 Title :Current_Data_time Program

Aim:
Write a program to print date and time

Procedure Steps/Algorithm:

1Start the program.


2 Read the current date and time of system
3 Print the date and time.
4 Stop the program.

Program:-

Import java.text.* ;
Import java.utils.* ;

Public class date_time


{
Public static void main (string args[])
{
SimpleDateformat fd = new Simpledateformat("dd/mm/yyyy HH:mm:ss");

Date date = new date();

Fd.settimezone(timezone.gettimezone("IST"))

System.out.println(fd.format(date));

}
}

Result:
Thus the program to perform current date and time;

3 Title :Program for Inheritance concept

Aim:
Write a program to demonstrate inheritance

Procedure Steps/Algorithm:

1 Start the program.


2 Create class parent and child for the inheritance concept
3 Stop the program.

Program:-

Public abstract class testexe


{
Public static void executeaction();

}
Public class test1 extends testexe
{
@Override
Public void executeaction()
{
--Print any message to check
System.out.println(‘check test 1’);

}
}

Public class test2 extends testexe


{
@Override
Public void executeaction()
{
--Print any message to check
System.out.println(‘check test 2’);

}
}

Public class test


{
Public static void main (String args[])
{
Testexe t1 =new t1();
Testexe t2 = new t2();
T1. executeaction();
t2.executeaction();
}
}

Result:- Program will execute with the concept of inheritance.

4 Title :Program for Calculator

Aim: Write a program for calculator


Procedure Steps/Algorithm:

3 Start the program.


4 Create the concept of all calculator like sum multiple etc
3 Stop the program.

Program:-

Import java.awt.event.*;
Import java swing.*;
Import java awt.*;

Class calculator extends jframe implemented Actionlistener


{
Static jframe f;
Static jtextfield 1;
String s0,s1,s2;

Calculator()
{
S0= s1=s2= "";
}
}

Public static void main (String args[])


{
F= new jframe("Calculator");

Try
{

UIManager.setlookandfeel(UIManger.getSystemLookandFeel
ClassName());
}
Catch(Exception e)
{
System.err.println(e.getmessage());
}

Calculator c new calculator();


L= new JTextField(16);
l.sseteditable(false);
Jbutton
b0,b1,b2,b3,b4,b5,b6,b7,b8,b9,ba,bs,bd,bm,be,beq,beq1;

B0= new JBUTTON("0");


B1= new JBUTTON("1");
B2= new JBUTTON("2");
B3= new JBUTTON("3");
B4= new JBUTTON("4");
B5= new JBUTTON("5");
B6= new JBUTTON("6");
B7= new JBUTTON("7");
B8= new JBUTTON("8");
B9= new JBUTTON("9");

Beq1= new JBUTTON("=");

Ba= new JBUTTON("+");


Bs= new JBUTTON("-");
Bd= new JBUTTON("/");
Bm= new JBUTTON("*");

Beq= new JBUTTON("C");


Be= new JBUTTON(".");

Jpanel p= new Jpancel();

Bm.addactionlistener(c);
Bd.addactionlistener(c);
Bs.addactionlistener(c);
Ba.addactionlistener(c);
B9.addactionlistener(c);
B8.addactionlistener(c);
B7.addactionlistener(c);
B6.addactionlistener(c);
B5.addactionlistener(c);
B4.addactionlistener(c);
B3.addactionlistener(c);
B2.addactionlistener(c);
B1.addactionlistener(c);
B0.addactionlistener(c);
Be.addactionlistener(c);
Beq.addactionlistener(c);
Beq1.addactionlistener(c);
p.add(1);
p.add(ba);
p.add(b1);
p.add(b2);
p.add(b3);
p.add(b4);
p.add(b5);
p.add(b6);
p.add(b7);
p.add(b8);
p.add(b9);
p.add(b0);
p.add(bm);
p.add(bs);
p.add(bd);
p.add(be);
p.add(beq);
p.add(beq1);

f.add(p);
f.show();

Public void actionperformed(Actionevent e)


{
String s = e.getActionCommand();
IF (S.CHARAT(0)>= ‘0’ && S.CHARAT(0)<=9)
{
if !s1.equals("")
s2=s2+s;
else
s0=s0+s;

}
Else if (S.CHARAT(0)>= ‘C’)
{
S0=s1-s2="";
}
Else if (S.CHARAT(0)== ‘=’)
{
If (!s1.equals("+"))
Te=(Double.parseDouble(s0)+
Double.parseDouble(s2));
elseif (!s1.equals("-"))
Te=(Double.parseDouble(s0)-
Double.parseDouble(s2));
Elseif (!s1.equals("/"))
Te=(Double.parseDouble(s0)/
Double.parseDouble(s2));
else (!s1.equals("*"))
Te=(Double.parseDouble(s0)*
Double.parseDouble(s2));

S0=double.toString(te);
S1=s;
S2="";

l.Settext(s0+s1+s2);

}
}

Result:= Calculator created with all functionality.

5 Title :Program Lisp likelist

Aim: Write a program in Java lisp like list

Procedure Steps/Algorithm:

1. To implement the necessary package needed


2. To implement the lisp_like list in Java to perform functions like car(), cdr();
3. Car function ()
This function car of list return first element of the list.(3,0,2,5)
4. Cdr function () this function – return reset list by removing first element
5. Stop the program.

PROGRAM :-

Public class lisp


{
Public int car(list l)
{
Object obj = get(0);
String str = l.toString();
System.out,println(“using car function”);
Return integer.parseint(str);
}
Public list cdr(list l)
{
Object ob =remove(0);
Object obj=l.toarray();
System.out,println(“using cdr function”);

Return list;

}
Public static void main(String args[])
{
List<integer>l= new arraylist<integer>();
l.add(3);
l.add(0);
l.add(2);
l.add(5);

lisp l=new lisp();


list val=l.car()
list list=l.cdr(i);

}
}

Output:= using a.lcar function


3
Using l.cdr function
(0,2,5)

You might also like