Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (1 vote)
391 views

Pcas6 - Java Programming: Practical Records

1. The document is the practical records of a student named Nadar Laxmi Rajgopal for the course Java Programming (PCAS6) at the University of Madras Institute of Distance Education. 2. It contains 13 programs written by the student on various Java concepts like classes, inheritance, arrays, methods etc. along with the program details, date, and signature. 3. The programs cover concepts like mathematical operations using classes and inheritance, calculating digit sum, designing a bank account class, area calculation of shapes using inheritance, star pattern printing, and more.

Uploaded by

best xerox
Copyright
© © All Rights Reserved
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (1 vote)
391 views

Pcas6 - Java Programming: Practical Records

1. The document is the practical records of a student named Nadar Laxmi Rajgopal for the course Java Programming (PCAS6) at the University of Madras Institute of Distance Education. 2. It contains 13 programs written by the student on various Java concepts like classes, inheritance, arrays, methods etc. along with the program details, date, and signature. 3. The programs cover concepts like mathematical operations using classes and inheritance, calculating digit sum, designing a bank account class, area calculation of shapes using inheritance, star pattern printing, and more.

Uploaded by

best xerox
Copyright
© © All Rights Reserved
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 26

PCAS6 – JAVA PROGRAMMING

PRACTICAL RECORDS

UNIVERSITY OF MADRAS

INSTITUTE OF DISTANCE EDUCATION

UNIVERSITY OF MADRAS

INSTITUTE OF DISTANCE EDUCATION

NAME: NADAR LAXMI RAJGOPAL COURSE: MCA


REG.NO : A12321PCA6003 SEMESTER: 3

This is certified to be the bonafide record of work done by the


student in the JAVA PROGRAMMING (PCAS6) OF UNIVERSITY OF
MADRAS [IDE] in the department of information technology during
the year. JUNE – 2019.

Head of the Department Staff-In-Charge


Submitted for the practical examination held on

Examiner
INDEX

EX.NO DATE PROGRAM SIGNATURE

1 6.5.19 WAP to print sample program

WRITE A PROGRAM TO PERFORM


2 20.5.19
MATHEMATICAL OPERATIONS.

3 3.5.19 WRITE SIMPLE PROGRAM TO CALCULATE


THE SUM OF DIGITS OF ANY NUMBER.

DESIGN A CLASS TO REPRESENT A BANK


4 10.5.19
ACCOUNT. INCLUDE THE FOLLOWING
MEMBERS:

5 17.5.19 WAP TO DISPLAY AREA OF RECTANGLE


AND TRIANGLE USING INHERITANCE
WRITE A SIMPLE PROGRAM TO DISPLAY A
6 24.5.19 “*” I TRIANGLE SHAPE.
OUTPUT WILL BE LIKE THIS

CREATE A CLASS WITH A DEFAULT


7 31.5.19 CONSTRUCTOR (ONE THAT TAKES NO
ARGUMENTS) THAT PRINTS A MESSAGE.

8 7.6.19 WAP TO STORE NUMBERS IN ARRAY AND


STRING IN ARRAY

WAP TO PRINT AREA OF RECTANGLE


9 14.6.19
USING FUNCTION

WRITE A JAVA PROGRAM TO FIND THE


10 14.6.19
VOLUME OF A SPHERE AND A CONE.

WRITE A JAVA PROGRAM THAT TAKES A


11 14.6.19
STRING AND CONVERTS IT INTO
UPPERCASE AND LOWERCASE LETTERS
WRITE A JAVA PROGRAM TO CONVERT
12 14.6.19
RUPEES TO DOLLARS.
WRITE APPLETS TO DRAW THE
FOLLOWING SHAPES:
(I) CONE

(II) CYLINDER

13 14.6.19 (III) CUBE

(IV) SQUARE INSIDE A CIRCLE

(V) CIRCLE INSIDE A SQUARE

14 14.6.19 WRITE AN APPLET TO DISPLAY A FACE.

PROGRAM 1

AIM: WAP to print sample program


coding

public class helo

public static void main(String args[])

System.out.println("Hello This my first java program");

}
WRITE A PROGRAM TO PERFORM MATHEMATICAL OPERATIONS. CREATE A CLASS CALLED
ADDSUB WITH METHODS TO ADD AND SUBTRACT. CREATE ANOTHER CLASS CALLED
MULTDIV THAT EXTENDS FROM ADDSUB CLASS TO USE THE MEMBER DATA OF THE
SUPERCLASS. MULTDIV SHOULD HAVE METHODS TO MULTIPLY AND DIVIDE. A MAIN
METHOD SHOULD ACCESS THE METHOD AND PERFORM THE MATHEMATICAL
OPERATIONS.

CODING
class addsub
{ int num1;
int num2;
addsub(int n1, int n2)
{
num1 = n1;
num2 = n2;
} int add()
{ return num1+num2;
} int sub()
{ return num1-num2;
}
}
class multdiv extends addsub
{ public multdiv(int n1, int n2)
{
super(n1, n2);
}
int mul()
{return num1*num2;}
float div()
{return num2/num1;}
public void display()
{
System.out.println("Number 1 :" + num1);
System.out.println("Number 2 :" + num2);
}
}

public class adsb


{ public static void main(String arg[])
{
addsub r1=new addsub(50,20);
int ad = r1.add();
int sb = r1.sub();
System.out.println("Addition =" +ad);
System.out.println("Subtraction =" +sb);
multdiv r2 =new multdiv(4,20);
int ml = r2.mul();
float dv =r2.div();
System.out.println("Multiply =" +ml);
System.out.println("Division =" +dv);}}
PROGRAM 2
AIM: WRITE SIMPLE PROGRAM TO CALCULATE THE SUM OF DIGITS OF ANY NUMBER.

Coding
class digit
{
public static void main(String args[])
{
int sum;
int num1 = 10;
int num2 = 23;
{
System.out.println("first number= " +num1);
System.out.println("second number= " +num2);
sum=num1+num2;
System.out.println("Sum of Digits = " +sum);
}
}
}
PROGRAM 3

AIM: DESIGN A CLASS TO REPRESENT A BANK ACCOUNT. INCLUDE THE FOLLOWING


MEMBERS:

DATA MEMBERS:
NAME OF THE DEPOSITOR
ACCOUNT NUMBER
TYPE OF ACCOUNT
BALANCE AMOUNT IN THE ACCOUNT
METHODS:

TO ASSIGN INITIAL VALUES


TO DEPOSIT AN AMOUNT
TO WITHDRAW AN AMOUNT AFTER CHECKING BALANCE
TO DISPLAY THE NAME AND BALANCE

Coding

class account
{ String name;
int acc_no;
String type;
int bal;
int amount;

account()
{ name="karandeep";
acc_no=2905;
type="savings";
bal=6000;
}
int withdraw()
{ amount=1000;
bal-=amount;
return bal;
}
int deposit()
{ amount=500;
bal+=amount;
return bal;
}

void display()
{ System.out.println(name + " Your A/c no :" +acc_no + " Your A/c type :"
+type);

System.out.print("Your Balance is Rs." + bal);

withdraw();

System.out.print("\nYour Balance after withdrawl is Rs" + bal);

deposit();

System.out.print("\nYour Balance after deposit is Rs." + bal);

} }

public class karan

{ public static void main(String args[])

{ account b1=new account();

b1.display();

}
PROGRAM 4

AIM: WAP TO DISPLAY AREA OF RECTANGLE AND TRIANGLE USING INHERITANCE

Coding
class Shape
{ int dim1;
int dim2;
Shape(int x , int y)
{
dim1=x;
dim2=y;
}

void display()
{
System.out.println(dim1);
System.out.println(dim2);
}
}
class rectangle extends Shape
{ rectangle(int x, int y)
{
super(x, y);
}
int area()
{
return dim1*dim2;
}

void display()
{ System.out.println("In rectangle class");
super.display();
}
}
class triangle extends Shape
{ triangle(int x, int y)
{
super(x, y);
}
float area()
{
return (0.5f)*dim1*dim2;
}
}
class sh
{ public static void main(String arg[])
{ rectangle r1=new rectangle(20,20);
int ar=r1.area();
System.out.println("Area of Rectangle " +ar);
r1.display();
triangle t1=new triangle(20,25);
float ar1=t1.area();
System.out.println("Area of Triangle " +ar1);
}
}
PROGRAM 5

AIM: WRITE A SIMPLE PROGRAM TO DISPLAY A “*” I TRIANGLE SHAPE.


OUTPUT WILL BE LIKE THIS

* * *

* * * * *

coding

class star
{
public static void main (String args[])
{
int i;
int j;

for ( i=1; i<=5; i++)


{
for (j=1; j<=i; j++)
{
System.out.print("*");
}
System.out.println();
}
}
}
CREATE A CLASS WITH A DEFAULT CONSTRUCTOR (ONE THAT TAKES NO ARGUMENTS)
THAT PRINTS A MESSAGE. CREATE AN OBJECT OF THIS CLASS.

Coding
class rec
{
int a;
int b;

rec ( )
{
a=5;
b=10;
}

int area()
{
return a*b;
}
}

class test
{
public static void main (String args[ ])
{
System.out.println("Create an Object of this Class");
}
}
PROGRAM 6

AIM: WAP TO STORE NUMBERS IN ARRAY

Coding

class testarra
{
public static void main(String args[])
{
int anarray[];
anarray = new int[10];
anarray[1] = 90;
anarray[2] = 80;
anarray[3] = 70;
anarray[4] = 50;
anarray[5] = 60;

System.out.println(anarray[1]);
System.out.println(anarray[4]);
System.out.println(anarray[2]);
}
}
PROGRAM 6 b

AIM: WAP TO STORE STRING IN ARRAY

Coding
Class testarraystr
{
public static void main(String args[])
{
String anarray[];
anarray = new String[10];
anarray[1] = "Karandeep";
anarray[2] = "kandy";
anarray[3] = "Mandy";
anarray[4] = "Sahil";
anarray[5] = "Dinesh";

System.out.println(anarray[1]);
System.out.println(anarray[4]);
System.out.println(anarray[2]);
}
}
PROGRAM 7

AIM: WAP TO PRINT AREA OF RECTANGLE USING FUNCTION

Coding
class rectangle
{
int length;
int width;

int area()
{
return length*width;
}
}

public class testrec


{
public static void main(String args[])
{
rectangle r1 = new rectangle();
r1.length=20;
r1.width=40;
int r1area = r1.area();
System.out.println("Area of Rectangle is: " + r1area);
}
}
PROGRAM 8

AIM: WRITE A JAVA PROGRAM TO FIND THE VOLUME OF A SPHERE AND A CONE.

Coding

class Shape
{ int radius;
int height;
Shape(int x , int y)
{
radius=x;
height=y;
}

void display()
{
System.out.println(radius);
System.out.println(height);
}
}
class sphere extends Shape
{ sphere(int x, int y)
{
super(x, y);
}
float volume()
{
return (4/3f)*(3.14f)*radius*radius*height;
}

void display()
{ System.out.println("Radius & Height in Volume");
super.display();
}
}
class cone extends Shape
{ cone(int x, int y)
{
super(x, y);
}
float volume()
{
return (1/3f)*(3.14f)*radius*radius*radius;
}
}
class vol
{ public static void main(String arg[])
{ sphere r1=new sphere(18,20);
float ar=r1.volume();
r1.display();
System.out.println("Volume of Sphere is " +ar);
cone t1=new cone(15,15);
float ar1=t1.volume();
System.out.println("Volume of Cone is " +ar1);
}
}
PROGRAM 9

AIM: WRITE A JAVA PROGRAM THAT TAKES A STRING AND CONVERTS IT INTO UPPERCASE
AND LOWERCASE LETTERS

Coding
public class prog
{
public static void main(String args[])
{
String s = "KaRaN, SaGGu!";

String supper = s.toUpperCase();


String slower = s.toLowerCase();

System.out.println("The Upper case is"+supper);


System.out.println("The Lower case is"+slower);

}
}

WRITE A JAVA PROGRAM TO CONVERT RUPEES TO DOLLARS.

Coding
class display
{
public static void main(String args[])
{
currency ob= new currency();
double money=ob.convert(25.0);
System.out.println("The converted money in dollar is = "+money);
}
}
class currency
{
double convert(double rupee)
{
double doll=45*rupee;
return doll;
}
}

class pwr

{double r;

double change(int x, int y)

{r = Math.pow(x,y);

return r;

}
double change(int x, float y)

{r = Math.pow(x,y);

return r;

}
double change(float x, float y)

{r = Math.pow(x,y);

return r;

}
public class pw

{public static void main(String args[])

{pwr p = new pwr();

double a = p.change(2,2);

double b = p.change(2,3.2F);

double c = p.change(4.3F,3.6F);

System.out.println("Integer combination: "+a);

System.out.println("Integer - float combination: "+b);

System.out.println("Float combination: "+c);

abstract class shape

{ int dim1;
int dim2;

shape(int x, int y)

{ dim1 = x;

dim2 = y;

abstract double area();

class rectangle extends shape

{ rectangle(int x, int y)

{ super(x,y);

double area()

{ return dim1*dim2;

class triangle extends shape

{ triangle(int x, int y)

{ super(x,y);

}
double area()

{ return (0.5F)*dim1*dim2;

public class abshape

{ public static void main(String args[])

{ rectangle r1 = new rectangle(10,20);


triangle t1 = new triangle(20,15);

double r = r1.area();

double t = t1.area();

System.out.println("Area of rectangle: " +r);

System.out.println("Area of triangle: " +t);

PROGRAM 10

AIM: WRITE APPLETS TO DRAW THE FOLLOWING SHAPES:


(I) CONE

(II) CYLINDER

(III) CUBE

(IV) SQUARE INSIDE A CIRCLE

(V) CIRCLE INSIDE A SQUARE

CODING

import java.applet.*;

import java.awt.*;
import java.awt.event.*;

public class Shapes extends Applet

public void paint(Graphics g)

/*Cylinder*/

g.drawString("(a).Cylinder",10,110);

g.drawOval(10,10,50,10);

g.drawOval(10,80,50,10);

g.drawLine(10,15,10,85);

g.drawLine(60,15,60,85);

/*Cube*/

g.drawString("(b).Cube",95,110);

g.drawRect(80,10,50,50);

g.drawRect(95,25,50,50);

g.drawLine(80,10,95,25);

g.drawLine(130,10,145,25);

g.drawLine(80,60,95,75);

g.drawLine(130,60,145,75);

/*Squar Inside A Circle*/

g.drawString("(c).Squar Inside A Circle",150,110);

g.drawOval(180,10,80,80);

g.drawRect(192,22,55,55);

/*Circle Inside a Squar*/

g.drawString("(d).Circle Inside a Squar",290,110);

g.drawRect(290,10,80,80);
g.drawOval(290,10,80,80);

PROGRAM 11

AIM: WRITE AN APPLET TO DISPLAY A FACE.


CODING
import java.awt.*;
import java.applet.*;

public class face extends Applet


{
public void paint (Graphics g)
{
g.drawOval (83, 10, 40, 30) ;
g.drawOval (40, 40, 120, 150) ;
g.drawOval (57, 75, 30, 20) ;
g.drawOval (110, 75, 30, 20) ;
g.fillOval (68, 81, 10, 10) ;
g.fillOval (121, 81, 10, 10) ;
g.drawOval (85, 100, 30, 30) ;
g.fillArc (60, 125, 80, 40, 180, 180) ;
g.drawOval (25, 92, 15, 30) ;
g.drawOval (160, 92, 15, 30) ;
}
}

You might also like