STANDARD12 Practical Assignment
STANDARD12 Practical Assignment
1
Chapter 7 Java Basics Ãkúfhý : 7 òðkLke {q¤¼qík çkkçkíkku
PRACTICAL NO. 1 File Name - [Link]
# Create a java program that will compute the cost of phone call and
update balance.
• yuðe økýíkhe fhíkku òðk Ãkúkuøkúk{ çkLkkðku fu VkuLkfku÷Lkk ¾[oLke økýíkhe fhu yLku Ãknu÷ktÚke [qfðu÷e hf{ {kt
MkwÄkhku fhu.
public class CallCost
OUTPUT OF CODE LISTING
{
>javac [Link]“
public static void main(String[]args)
>Exit code: 0“
{
>java -cp . CallCost
double balance;
“Call Duration:
double rate;
37.0
double duration;
Seconds
double cost;
Balance:132.26Rupees
>Exit code: 0“
balance=170;
rate=1.02;
duration=37;
cost=duration*rate;
balance=balance-cost;
[Link]("Call Duration:");
[Link](duration);
[Link]("Seconds");
[Link]("Balance:" +balance+ "Rupees");
}
}
PRACTICAL NO. 2 File Name - [Link]
# Create a java program that will compute the cost of Simple Interest.
• MkkËk ÔÞksLke økýíkhe fhe ÔÞks{wÆ÷ økýíkhe fhe ykÃkíkku Mkh¤ òðk Ãkúkuøkúk{ íkiÞkh fhku.
public class Interest
{
OUTPUT OF CODE LISTING
public static void main(String[]args)
>javac [Link]“
{
>Exit code: 0“
double principal;
>java -cp . Interest
double rate;
“principal amount17000.0Repees
double duration;
Deposit for duration of3.0 years
double maturity;
interest Rate9.5%
double interest;
Maturity amount21845.0Repees
>Exit code: 0“
principal=17000;
rate=9.50;
duration=3;
PAGE NO. 2
interest=principal*duration*rate/100;
maturity=principal+interest;
[Link]("principal amount" +principal+ "Repees");
[Link]("Deposit for duration of" +duration+ "years");
[Link]("interest Rate" +rate+ "%");
[Link]("Maturity amount" +maturity+ "Repees");
}
}
PRACTICAL NO. 3 File Name - [Link]
# Using Arithmatic Operator create Java program.
• Arithmatic operator (ytføkrýíkeÞ Ãkúr¢Þf)Lkku WÃkÞkuøk Ëþkoðíkku òðk Ãkúkuøkúk{
public class ArithOpeators
OUTPUT OF CODE LISTING
{
>javac [Link]“
public static void main(String[]args)
>Exit code: 0“
{ >java -cp . ArithOpeators
short x=6; “x is6,y is3
int y=3; x+y=9
float a=12.5f; x-y=3
float b=7.2f; x/y=2
x%y=0
x%y=0
[Link]("x is" +x+",y is" +y);
x%y=-2
[Link]("x+y=" +(x+y)); x%y=2
[Link]("x-y=" +(x-y)); a is12.5,b is7.2
[Link]("x/y=" +(x/y)); a/b=1.7361112
[Link]("x%y=" +(x%y)); a/x=2.0833333
x=-6; a%x=0.5
[Link]("x%y=" +(x%y)); a%b=5.3
>Exit code: 0
y=-4;
[Link]("x%y=" +(x%y));
x=6; y=-4;
[Link]("x%y="+(x%y));
}
}
PAGE NO. 3
Chapter 8 Classes & Objects in Java
Ãkúfhý : 8 òðk{kt õ÷kMk yLku ykìçsuõx
PRACTICAL NO. 4 File [Link]
# To understand the concept of class and object in java program.
• MkkËk ÔÞksLke økýíkhe fhe ÔÞks{wÆ÷ økýíkhe fhe ykÃkíkku Mkh¤ òðk Ãkúkuøkúk{ íkiÞkh fhku.
class Room
{
float length,width,height; OUTPUT OF CODE LISTING
byte nWindows;
>javac [Link]“
void setAttr (float l, float w, float h, byte n) >Exit code: 0“
{ >java -cp . Interest
length=l; width=w; height=h; “principal amount17000.0Repees
nWindows=n; Deposit for duration of3.0 years
}
interest Rate9.5%
double area()
{ Maturity amount21845.0Repees
return (length * width); >Exit code: 0“
}
void display()
{
[Link]("\nLength:" +length);
[Link]("Width:" +width);
[Link]("height:" +height);
[Link]("Number of windows:" +nWindows);
}
}
class RoomDemo
{
public static void main(String[]args)
{
Room r1; r1=new Room();
Room r2;
r2 = new Room();
[Link]();
[Link]();
[Link]();
[Link]();
OUTPUT OF
class Prime CODE LISTING
{ >javac
static boolean isPrime(int n) [Link]“
{ >Exit code: 0“
int i,last; >java -cp .
primeClassMethod
if (n<=1)return false; “Prime numbers
if(n<4)return true; between 3 and 100:
3
last = (int)[Link](n); 5
i=3; 7
do 11
{ 13
if (n%i==0)return false; 17
i=i+2; 19
} 23
while (i<last); 25
29
return true; 31
} 35
37
} 41
43
class primeClassMethod 47
{ 49
public static void main(String[]s) 53
{ 59
int i, n; 61
67
[Link] ("Prime numbers between 3 and 100:"); 71
for (n=3; n<100; n=n+2) 73
{ 79
if ([Link](n))[Link](n); 83
} 89
} 97
}
>Exit code: 0“
PAGE NO. 5
PRACTICAL NO. 6 File [Link]
# Using user-defined no-argument constructor.
class Room
{ OUTPUT OF CODE LISTING
float length, width, height; >javac [Link]“
byte nWindows; >Exit code: 0“
static int totWindows; >java -cp . RoomConstructorDemoA
Length:16.0
Room (float l, float w, float h, byte n) Width:12.5
{ Height:10.0
length=l; width=w; height=h; Windows:1
nWindows=n; totWindows+=n;
}
Length:20.0
Room(float l, float w) Width:14.0
{ Height:12.0
length=l; width Windows:2
=w; height=10; “Total number of Windows :3
nWindows=1; totWindows++; >Exit code: 0“
}
double area()
{
return (length * width);
}
void display()
{
[Link]("\nLength:" +length+ "\nWidth:" +width);
[Link]("Height:" +height);
[Link]("Windows:" +nWindows);
}
}
class RoomConstructorDemoA
{
public static void main (String args[])
{
Room r1=new Room(16,12.5f);
Room r2=new Room(20,14,12,(byte)2);
[Link](); [Link]();
[Link] ("\nTotal number of Windows :" +[Link]);
}
}
PAGE NO. 6
PRACTICAL NO. 7 File Name - [Link]
# Default visibility modifier, available everywhere in a package.
class Rectangle
{
double length,width; OUTPUT OF CODE LISTING
>javac [Link]“
void setAttributes(double x, double y) >Exit code: 0“>java -cp . RectangleDemo
{
“Rectangle with length=10.5width=20.0
length=x; width=y;
Area of rectangle is=210.0
}
double area() Area of recangle with length=10.0
{ width=15.0is150.0
return length * width; >Exit code: 0“
}
void display()
{
[Link]("Rectangle with length=" +length+ "width=" +width);
}
}
class RectangleDemo
{
public static void main(String[]s)
{
Rectangle rect1;
rect1=new Rectangle();
Rectangle rect2=new Rectangle();
[Link](10.5,20);
[Link]();
[Link]("Area of rectangle is=" +[Link]());
[Link](10,15);
[Link]("Area of recangle with length="
+[Link]+"width="+[Link] + "is" +[Link]());
}
}
PAGE NO. 7
int marks[]; OUTPUT OF
marks=new int[7]; CODE LISTING
>javac [Link]“
>Exit code: 0“
for (int i=0; i<7; i++) >java -cp . Array1“marks[0]is0
marks[1]is0
{ marks[2]is0
[Link]("marks["+i+"]is" +marks[i]); marks[3]is0
} marks[4]is0
marks[5]is0
} marks[6]is0
} >Exit code: 0
PAGE NO. 8
PRACTICAL NO. 10 File Name - [Link]
# Java program to computer average of 10 numbers using 1-D array & loop.
• 10 yÃkqýkof MktÏÞkykuLke Mkhuhkþ ({æÞf) þkuÄðk {kxuLkku òðk Ãkúkuøkúk{
class ArrayAvg
{
public static void main(String[]s)
{
double numbers[]={10.5,20.6,30.8,15.5, 17.3,25.5,27.2,20,30,18.5};
byte ctr; OUTPUT OF CODE LISTING
double sum=0, avg; >javac [Link]“
>Exit code: 0“
>java -cp .
[Link]("list of numbers is"); ArrayAvg“list of numbers is
for (ctr=0; ctr<10; ctr++) 10.5
20.6
{ 30.8
[Link](numbers[ctr]); 15.5
17.3
sum=sum+numbers[ctr]; 25.5
} 27.2
avg=sum/10; 20.0
30.0
[Link]("\n Average of above number is" +avg); 18.5
} “ Average of above number is21.59
>Exit code: 0“
}
class Array2Dchar
{
public static void main(String [] s)
{
char names[][]= {
{'j','a','v','a'},
{'c'},
{'c','+','+'},
{'B','a','c','i','c'},
{'p','a','s','c','a','l'},
};
[Link]("Number of elements in 2D array :" +[Link] + "\n");
class finallydemo
{
public static void main(String args[])
{
String citylist[]={"ahmedabad","baroda","rajkot","surat"};
int numerator=15,denominator=0,answer;
[Link]("statement to be executed before try block");
try OUTPUT OF CODE LISTING
{ >javac [Link]“
[Link]("begining of try block....."); >Exit code: 0“
>java -cp . finallydemo
[Link](citylist[5]); “statement to be executed before try block
answer=numerator/denominator; begining of try block.....
this part of code will always get executed
[Link]("end of try block...."); Exception in thread "main"
} [Link] at
finally [Link]([Link])
>Exit code: 1“
{
[Link]("this part of code will always get executed");
}
[Link]("end of program...");
}
}
PAGE NO. 12
Chapter 11 File handling Ãkúfhý : 11 VkR÷ ÔÞðMÚkkÃkLk
PRACTICAL NO. 18 File Name - [Link]
# Program to list files in a given directory.
• ykÃku÷ rzhufxhe{kt WÃk÷çÄ VkE÷kuLke ÞkËe {u¤ððk {kxuLkku Ãkúkuøkúk{ ÷¾ku.
import [Link]; OUTPUT OF CODE LISTING
public class ListFiles >javac [Link]“
{ >Exit code: 0“
>java -cp . ListFiles
public static void main(String args[])
“List of files in
{ the Directory: C:\Windows
String path= "C:/Windows"; [Link]
String files; [Link]
[Link]
int countOfFiles; [Link]
try [Link]
{ [Link]
[Link]
File folder= new File(path); [Link]
File[] objects;
File[] listOfFiles=[Link]();
countOfFiles= [Link];
[Link]("List of files in the Directory:");
[Link]([Link]());
for(int i=0;i<countOfFiles;i++)
{
if(listOfFiles[i].isFile())
{
files=listOfFiles[i].getName();
[Link](files);
}
}
}
catch(Exception eobj)
{
[Link](eobj);
}
}
}
PAGE NO. 13
PRACTICAL NO. 19 File Name - [Link]
# Program to illustrate file writer operation.
• VkE÷{kt fuðe heíku ÷¾ðwt íkuLkwt ðýoLk fhíkku Ãkúkuøkúk{ ÷¾ku.
import [Link].*;
class FileWriterDemo
{
public static void main(String args[])
{
FileWriter fwobject= null;
try {
fwobject = new FileWriter("[Link]");
[Link]("File writing stats...");
for(int i=1; i< 11; i++)
[Link]("Line:" +i+ "\n");
[Link]("File writing ends...");
}
catch(Exception eobj)
{
[Link](eobj);
}
finally
{
try{
[Link]();
}
catch(Exception eobj)
{
[Link](eobj);
}
}
}
}
PAGE NO. 14
PRACTICAL NO. 20 File Name - [Link]
# Program to illustrate file read operation.
• VkE÷{ktÚke fuðe heíku ðkt[ðwt íkuLkwt ðýoLk fhíkku Ãkúkuøkúk{ ÷¾ku.
import [Link].*;
class FileReaderDemo
{
public static void main(String args[])
{
FileReader frobject = null;
try {
frobject = new FileReader("[Link]");
int i;
char ch;
while((i= [Link]())!= -1)
{
ch= (char) i;
[Link](ch);
} OUTPUT OF CODE LISTING
} >javac [Link]“
catch(Exception eobj) >Exit code: 0“>java -cp . FileReaderDemo
{ “File writing stats...Line:1
[Link](eobj); “Line:2
“Line:3
} “Line:4
finally “Line:5
{ “Line:6
try{ “Line:7
[Link](); “Line:8
} “Line:9
“Line:10
catch(Exception eobj)
“File writing ends...>Exit code: 0
{
[Link](eobj);
}
}
}
}
PAGE NO. 15
PRACTICAL NO. 21 File Name - [Link]
# Program to add two numbers.
• WÃkÞkuøkfíkko ÃkkMkuÚke ÃkhMÃkh MktðkË æðkhk çku MktÏÞk ðkt[u yLku íku çku MktÏÞkLkku Mkhðk¤ku Ëþkoðu íku {kxuLkku Ãkúkuøkúk{.
import [Link].*;
import [Link].*;
class ScannerInputDemo
{
public static void main(String args[])
{
Scanner kbInput=null;
int number1;
int number2;
int sum=0;
try
{
kbInput=new Scanner([Link]);
[Link]("Enter the first number:");
number1=[Link]();
[Link]("Enter the second number:");
number2=[Link]();
sum=number1+number2;
[Link]("Sum is : " +sum);
}
catch(Exception eobj)
{ OUTPUT OF CODE LISTING
[Link](eobj); >javac [Link]“
} >Exit code: 0“
finally >java -cp . ScannerInputDemo
{ “Enter the first number:20
try { Enter the second number:40
[Link](); Sum is : 60
>Exit code: 0
}
catch(Exception eobj)
{
[Link](eobj);
}
}
}
}
PAGE NO. 16
PRACTICAL NO. 22 File Name - [Link]
# Accepts input from a file “[Link]” and calculates the total marks of
each student.
• Ëhuf rðãkÚkeoLkku zuxk ðkt[e íkuLkk fw÷ økwýLke økýíkhe fhðk {kxuLkku Ãkúkuøkúk{ ÷¾ku.
import [Link].*;
import [Link].*; OUTPUT OF CODE LISTING
class ScannerFileDemo >javac [Link]“
{ >Exit code: 0“
public static void main(String args[]) >java -cp . ScannerFileDemo
{ “Defalut delimeter is:\p{javaWhitespace}+/n
Scanner fileinput=null; Total marks of Rollno1,Dhruvi are :294
int rollno, mark1, mark2, mark3, totalmarks; Total marks of Rollno2,Payal are :262
String name=null; Total marks of Rollno3,Vibhuti are :236
FileReader frobject = null; Total marks of Rollno4,Bhaveshri are :278
try Total marks of Rollno5,Shreeya are :266
{ >Exit code: 0
frobject = new FileReader("C:/school/[Link]");
fileinput=new Scanner(frobject);
[Link]("Defalut delimeter is : "+[Link]()+"/n");
while([Link]())
{
rollno=[Link]();
name=[Link]();
mark1=[Link]();
mark2=[Link]();
mark3=[Link]();
totalmarks=mark1+mark2+mark3;
[Link]("Total marks of Rollno" +rollno+","+name+" are :" +totalmarks);
}
[Link]();
}
catch(Exception eobj)
{
[Link](eobj);
}
}
}
Note :- Notepad [k÷w fhe Lke[uLke VkE÷ çkLkkðku. VkE÷Lku "C:/school/[Link]" Lkk Lkk{Úke Mkuð fhku.
1 Dhruvi 98 97 99
2 Payal 78 95 89
3 Vibhuti 95 57 84
4 Bhaveshri 95 85 98
5 Shreeya 95 84 87
PAGE NO. 17
Chapter 12 Publishing documents using LaTeX
Ãkúfhý : 12 ÷uxuõMkLke {ËËÚke ËMíkkðusLkwt «fkþLk
PRACTICAL NO. 23 File Name - [Link]
# Line handling example source file.
• ÷uxufMk{kt Mkíkík ÷¾ký yLku ÷¾ký{kt ÷kELkçkúuf Ëþkoðíkwt ÷¾ký Ëþkoðku.
Mkki ÃkúÚk{ start - All Programs - MikTex 2.9- TeXworks Open fhku.
Lke[u ykÃku÷ fkuz xkEÃk fhe [Link] Lkk{Úke Mkuð fhku.
\documentclass[12pt]{article}
\title{Line handling in \LaTex} OUTPUT OF CODE LISTING
\date{May 2013}
\begin{document}
\maketitle
\section{Continuous Text}\textsf
{
We have no wings, we cannot fly
But we have legs to sail and climb
By slow degrees and by and by
The cloudy summits of our time
}
\section{Text with Seperate Lines} \textsf
{
Heights by great men reached and kept \\
Where not attained by a sudden flight \\
But they, while their companions slept, \\
Were toiling upwards in the night
}
\end{document}
PRACTICAL NO. 24 File Name - [Link]
# Demonstration of the math environments.
• ÷uxufMk{kt ÷¾ký yLku økkrýríkf yuLðkÞLko{uLxLkwt ÃkúËþoLk fhíkku Ãkúkuøkúk{ ÷¾ku.
\documentclass[12pt] {article}
\usepackage{amsmath}
OUTPUT OF CODE LISTING
\title{Introduction to \LaTeX}
\date{May 2013}
\begin{document}
\section*{math environment}
The quadratic equation, in its general form, is
\begin{math}
ax^2 + bx + c = 0
\end{math}.
You learnt about them in class X.
PAGE NO. 18
The quadratic equation, in its general form, is
$ax^2 + bx + c = 0$. You learnt about them in
class X.
\section*{displaymath environment}
The quadratic equation, in its general form, is
\begin{displaymath}
ax^2 + bx + c = 0
\end {displaymath}. You learnt about them in class X
\end{document}
PRACTICAL NO. 25 File Name - [Link]
# A sample book in Latex.
• ÷uxufMk 5wMíkfLku fE heíku økkuXðu Au íku Ëþkoðíkku Ãkúkuøkúk{ ÷¾ku.
\documentclass[12pt]{book}
\usepackage{amsmath}
\title{\huge Mathematics \\ [3\baselineskip]
\Large Standard 12}
\author { Gujarat State Board of School Textbooks}
\date{2013}
\setcounter{secnumdepth}{2}
\setcounter{tocdepth}{1}
\begin{document}
\frontmatter
\maketitle
\chapter{\MakeUppercase{Fundamental Duties}}
\tableofcontents
\chapter{\MakeUppercase{About This Textbook....}}
\mainmatter Page -1
\part{Semester I}
\section{Introduction}
\section*{exercise 1.1}
\section{Properties of the Union Operation}
\subsection{Union is a Binary Operation}
\subsection{Properties of the Intersection Operation}
\subsection{Intersection is a Binary Operation}
\subsection{Associative Law}
\chapter{Number Systems}
\section{Introduction}
\section*{Exercise 2.1}
\section{Irrational Numbers}
Page -2
PAGE NO. 19
PAGE NO. 20