0% found this document useful (0 votes)
33 views46 pages

Astha Oopj

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

Astha Oopj

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

OOPJ(3153203) 211310132060

Name : Ashapurna
En. No.: 211310132060
Branch : ICT B-4

1
AIIE-ICTB4
OOPJ(3153203) 211310132060

INDEX

SNo Objective of Experiment Page Date Remark


No.
1. Write a program to convert rupees to dollar. 60
rupees dollar.
2. Write a program that calculate percentage marks
of the student ifmarks of 6 subjects are given.
3. Write a program to enter two numbers and
perform mathematical operations on them.
4. Write a program to ϐind length of string and
print second half of the string.

5. Write a program to accept a line and check how


many consonants and vowels are there in line.
6. Write a program to count the number of
words that start with capital letters.

7. Write a program to ϐind whether a given number


or string is palindrome.
8. Create a class which asks the user to enter a
sentence, and it should display t he count ofeach
vowel type in the sentence. The program should
continue till user enters the word “quit”. Display
9. Write an interactive program to print a string
entered
in a pyramid form. For instance, the string
“stream” has to be displayed as follows:
S

St

10. Write an interactive program to print a diamond


shape. For example, if user enters the number 3,
the diamond will be as follows:

* *
* **
OOPJ(3153203) 211310132060

DATE: / /

PRACTICAL:1
Aim: Write a program to convert rupees to dollar. 60 rupees dollar.
Code:

import java.util.Scanner;
public class p1 {
public static void
main(String[] args) {
Scanner s = new Scanner(System.in);
System.out.println("Enter value in
rupees (rs.): ");
float rupees = s.nextFloat();
float dollar = rupees/60;
System.out.println("Value in dollar : "+dollar+"$");
s.close();
}
}

3
AIIE-ICTB4
OOPJ(3153203) 211310132060

Output :

FIGURE 1.1: CONVERSION OF RUPEES TO DOLLARS IN JAVA

Signature:

Date: / /_ _
OOPJ(3153203) 211310132060

DATE: / /

PRACTICAL:2
Aim: Write a program that calculates the percentage marks of the
student if marks of 6 subjects are given.

Code:
import java. util.Scanner;
public class p2{
public String name;
static Scanner s = new Scanner(System.in);

public static void percentage(){


System.out.println("Enter student
name : ");
String name = s.nextLine();
System.out.println("Enter marks of maths: ");
float math = s.nextFloat();
System.out.println("Enter marks of sci: ");
float sci = s.nextFloat();
System.out.println("Enter marks of ss: ");
float ss = s.nextFloat();
System.out.println("Enter marks of java: ");
float java = s.nextFloat();
System.out.println("Enter marks of hindi: ");
float hindi = s.nextFloat();
System.out.println("Enter marks of python: ");
float python = s.nextFloat();
5
AIIE-ICTB4
OOPJ(3153203) 211310132060

float per = (hindi+ss+java+sci+python+math)/6;


System.out.println("The percentage of " +name+ " : "+per);
}
public static void main(String[] args) {
percentage() ;
}
}

OUTPUT :

FIG2.1: PERCENTAGE OF STUDENT IN JAVA

Signature:

Date: / /_
OOPJ(3153203) 211310132060

DATE: / /
PRACTICAL:3
Aim: Write a program to enter two numbers and perform mathematical operationson them.

Code:
import java.util.Scanner;
public class p3{
public static float a,b;

static String op;


static Scanner s = new Scanner(System.in);
public static void operation(float x,float y,String z)
{

if(op.equals("+"))

System.out.println("Sum of two

numbers:"+ (a+b)); else if(op.equals("-")

&& a>b) System.out.println("Subtraction

of two numbers:"+(a-b)); else

if(op.equals("/")&& b!=0)

System.out.println("Division of two

numbers:"+ (a/b)); else

if(op.equals("%")&& b!=0)

System.out.println("Modulous of two

7
AIIE-ICTB4
OOPJ(3153203) 211310132060

numbers:"+ (a%b)); else

if(op.equals("*"))

System.out.println("Multiplication of two numbers:"+ (a*b));

else

System.out.println("Wrong Input");

public static void main(String[]

args) {

System.out.print("Enter first

number : ");

a = s.nextFloat();
System.out.print("Enter second number : ");

b = s.nextFloat();
System.out.print("Enter operation : ");

op = s.next();
operation(a, b, op);

}
}

OUTPUT:
OOPJ(3153203) 211310132060

FIG:3.1 OPERATION IN TWO NO ON JAVA

Signature:

Date: / /_

9
AIIE-ICTB4
OOPJ(3153203) 211310132060

DATE: / /
PRACTICAL:4

Aim: Write a program to find the length of the string and print the second
half of the string.
Code:
Import.java.util.scanner;
public class p4
{
static String str;

static Scanner s = new Scanner(System.in);


public static void main(String[] args)
{
System.out.println("Enter a string :");
str = s.nextLine();
int le = str.length();
System.out.println("The length of string "+str+" is "+le);
System.out.println("Half of string is ");

System.out.print("-> ");

for(int i=le/2;i<le;i++)
{
System.out.print(str.charAt(i));
}
}
}
OOPJ(3153203) 211310132060

OUTPUT:

FIG:4.1 ACCEPTING STRING AND PRINTING THE SECOND HALF OF IT

Signature:

Date: / /_

11
AIIE-ICTB4
OOPJ(3153203) 211310132060

DATE: / /
PRACTICAL:5
Aim : Write a program to accept a line and check how many consonants
and vowels are there in line.
Code:
import java.util.Scanner;
public class p5{
static String str;
static Scanner s = new Scanner(System.in);
public static boolean Vowel (char c){
if(c=='a'||c=='e'||c=='i'||c=='o'||c=='u'||c=='A'||c=='E'||c=='I'||c=='O'||c
=='U')
{return true;}
return false;
}
public static void main(String[] args) { System.out.println("Enter a string :");

str = s.nextLine();

int count_v=0,count_c=0;

int le = str.length();
System.out.println("The length of string "+str+" is "+le);

for(int i=0;i<le;i++)

char c = str.charAt(i);
if(Character.isLetter(c))
OOPJ(3153203) 211310132060

{
if(Vowel(c))
count_v++;
else
count_c++;
}
}
System.out.println("There are "+count_v+"

vowels in the line"); System.out.println("There

are "+count_c+" consonants in the line");

}
}
OUTPUT:

FIG 5.1 ACCEPTING STRING AND NO OF VOWEKS AND CONSONANT

Signature:

Date: / /_

13
AIIE-ICTB4
OOPJ(3153203) 211310132060

DATE: / /
PRACTICAL:6
Aim : Write a program to count the number of words that start with capital letters.

Code :
import java.util.Scanner;
public class p6{
static String str;
static Scanner s = new Scanner(System.in);
public static boolean Capital (char c){
if(c>='A'&&c<='Z'){
return
true;
}
return false;
}
public static void main(String[] args)
{
System.out.print("Enter a string :
");
str =s.nextLine();
int le=str.length();
int cword=0;
for(int i=0;i<le;i++)
{
c
=str.charAt(
i);
if(Capital(c)
) cword++;
OOPJ(3153203) 211310132060
}
}
System.out.println("Total no. of letters starting with a capital letter "+cword);
}}

OUTPUT:

FIG: 6.1 CALCULATE NO OF WORDS STRING WITH A CAPITAL LATTER

Signature:

Date: / /_

15
AIIE-ICTB4
OOPJ(3153203) 211310132060

DATE: / /
PRACTICAL:7
Aim: Write a program to find that given number or string is palindrome or
not.
Code:
import java.util.Scanner;
public class p7{
static String str;
static Scanner s = new Scanner(System.in);
public static boolean palindrome(String c)
{
String r="";
for(int i=str.length()-1;i>=0;i--)
{
r = r + c.charAt(i);
}
System.out.println(r);
if(r.equals(c))
return true;
else
return false;
}
public static void main(String[] args)
{
System.out.print("Enter a string : ");
str = s.nextLine();
OOPJ(3153203) 211310132060

str=str.toLowerCase();
System.out.println(str);
if(palindrome(str))
else
System.out.println("String is not palindrome");
}
}

OUTPUT:

FIG:7.1 CHECKING ID STRINGS IS PALINDROM OR NOT

Signature:

Date: / /

17
AIIE-ICTB4
OOPJ(3153203) 211310132060

DATE: / /
PRACTICAL:8
Aim: Create a class which ask the user to enter a sentence, and it should
display count of each vowel type in the sentence. The program should
continue till user enters a word “quit”. Display the total count of each
vowel for all sentences.
Code:
import java.util.Scanner;
public class p8
{
public static void main(String[] args)
{
Scanner s=new Scanner(System.in);
int total A = 0, totalE = 0, totalI = 0, totalO

= 0, totalU = 0;

System.out.println("Enter sentences(type

'quit' to exit):");

while (true)

{
String input = s.nextLine();
if (input.equals("quit"))
{
break;
}
int countA = 0, countE = 0, countI = 0, countO = 0, countU = 0;
OOPJ(3153203) 211310132060

for (int j = 0; j < input.length(); j++)


{

char ch = input.charAt(j);

if (ch == 'a' || ch == 'A') {

countA++;

} else if (ch == 'e' || ch == 'E') {

countE++;

} else if (ch == 'i' || ch == 'I') {

countI++;
}
else
if (ch == 'o' || ch == 'O')
countO++;
} else if (ch == 'u' || ch == 'U') {
countU++;
}
}
totalA+=countA;

totalE +=countE;

19
AIIE-ICTB4
OOPJ(3153203) 211310132060

totalI += countI;

totalO +countO;

totalU += countU;
System.out.println("Counts for the current

sentence:");

System.out.print(" A: " + countA);

System.out.print(" E: " + countE);

System.out.print(" I: " + countI);

System.out.print(" O: " + countO);

System.out.print(" U: " + countU+"\n");

System.out.println("Total counts for all

sentences:"); System.out.println(" A : " +

totalA);

System.out.println(" E : " + totalE);

System.out.println(" I : " + totalI);

System.out.println(" O : " + totalO);

system.out.println(" U : " + totalU);


s.close();
}
OOPJ(3153203) 211310132060

OUTPUT:

FIG:8.1 ACCEPTING STRING ALL ”QUIT” IS ENTERD

Signature:

Date: / /

21
AIIE-ICTB4
OOPJ(3153203) 211310132060

DATE: / /
PRACTICAL:9
Aim : Write an interactive program to print a string entered in a pyramid
form. For instance, the string
“stream” has to be displayed as follows:

S
St
Str
S t re
Strea
Stream

Code :
import java.util.Scanner;
public class p9 {

public static void

main(String[] args) {

Scanner s = new

Scanner(System.in);

System.out.print("Enter a string:");
String input = s.nextLine(); s.close();

int length = input.length();


for (int i = 0; i < length; i++)
{
OOPJ(3153203) 211310132060

For (int j=0; j<length-i; j++)


{
System.out.print(" ");

}
for (int k=0; k<=i; k++) {
System.out.print(input.char
At(k) + " ");

}
System.out.println();}
}
OUTPUT:

FIG:9.1

Signature:

Date: / /_

23
AIIE-ICTB4
OOPJ(3153203) 211310132060

DATE: / /
PRACTICAL:10
Aim: Write a n intera ctive program to print a diamond shape. For
example, if user enters the number 3, the dia m ond will be as
follows:

*
**
***
**
*
Code:
import ja va .util.Scanner;
public class p10
{

public sta tic void ma

in(String[] args)

{ Sca nner s = new Sca

nner(System .in);

System .out.print("Enter a number : ");

int n = s.nextInt();

s.close();

for (int i = 0; i < n ; i++)


OOPJ(3153203) 211310132060

{
for (int j=0; j<n-i;
j++)
{
System .out.print(" ");

}
for (int k=0; k<i;
k++)
{ System
.out.print("*" + "");

}
System .out.println();

for(int i=n; I >=0; i--)

{
for (int j=0; j<n-i; j++)
{ System.out.print("");
}

for (int k=0; k<i; k++)


System .out.print("*" + " ");
System .out.println();
}

25
AIIE-ICTB4
OOPJ(3153203) 211310132060

}
}

OUTPUT:

Signature:
Date: / /_
OOPJ(3153203) 211310132060

DATE: / /

Practical :-11
Aim: Create a class called Student. Write a student manager program to manipulate the student
information from files by using FileInputStream and FileOutputStream.
Program:
→Student class
import java.util.*;
import java.io.*;
class Student implements Serializable {
String name;
int rollno;
double submarks;

Student(String n, int r, double m){


this.name=n;
this.rollno=r;
this.submarks=m;
}
}

→ Manager class
import java.io.*;
import java.util.*;
class StudentManager {
public static void main(String[] args){

List <Student> studList=new ArrayList<Student>();


String name;
int roll;

27
AIIE-ICTB4
OOPJ(3153203) 211310132060
double marks;
char ans='y';
try{
FileOutputStream fs = new FileOutputStream("object.txt");
ObjectOutputStream os = new ObjectOutputStream(fs);
Scanner sc = new Scanner(System.in);
do{
System.out.println("Enter Name of the Student: ");
name = sc.next();
System.out.println("Enter roll number of the Student: ");
roll = sc.nextInt();
System.out.println("Enter Marks of the Student: ");
marks = sc.nextDouble();

Student s1 = new Student(name,roll,marks);

os.writeObject(s1);
os.flush();

System.out.println("Do you want to continue?(y/n)");


ans = sc.next().charAt(0);
}while(ans=='y'||ans=='Y');
os.close();
}
catch(Exception e){ e.printStackTrace();}

try{
FileInputStream fis = new FileInputStream("object.txt");
ObjectInputStream ois = new ObjectInputStream(fis);
while(true){
Object obj = ois.readObject();
if(obj instanceof Student)

studList.add((Student)obj);
else
OOPJ(3153203) 211310132060

break;
}
ois.close();

}
catch (Exception e) { }
Iterator <Student> items = studList.iterator();
while(items.hasNext()){
Student sl = items.next();
System.out.print(sl.name +" ");
System.out.print(sl.rollno +" ");
System.out.print(sl.submarks +" ");
System.out.println();
}
}
}

Output:

29
AIIE-ICTB4
OOPJ(3153203) 211310132060

Signature:

Date: / /
OOPJ(3153203) 211310132060

DATE: / /
Practical:-12
Aim: Refine the student manager program to manipulate the student information from files by
using the BufferedReader and BufferedWriter.

Program:
import java.io.*;
import java.util.*;
class P12 {
public static void main(String[] args){
List <Student> studList = new ArrayList<Student>();
String name;
int roll;
double marks;
char ans = 'y';
try{
FileOutputStream fs = new FileOutputStream("object.txt");
BufferedOutputStream bs = new BufferedOutputStream(fs);
ObjectOutputStream os = new ObjectOutputStream(bs);
Scanner sc = new Scanner(System.in);
do{
System.out.println("Enter Name of the Student: ");
name = sc.next();
System.out.println("Enter roll number of the Student: ");
roll = sc.nextInt();
System.out.println("Enter Marks of Student: ");
marks = sc.nextDouble();

Student s1 = new Student(name,roll,marks);


os.writeObject(s1);
31
AIIE-ICTB4
OOPJ(3153203) 211310132060
os.flush();

System.out.println("Do you want to continue?(y/n)");


ans=sc.next().charAt(0);
}while(ans=='y'||ans=='Y');
os.close();
}
catch(Exception e) {e.printStackTrace();}
try{
FileInputStream fis = new FileInputStream("object.txt");
BufferedInputStream bis = new BufferedInputStream(fis);
ObjectInputStream ois = new ObjectInputStream(bis);
while(true){
Object obj = ois.readObject();
if(obj instanceof Student)

studList.add((Student)obj);
else
break;
}
ois.close();
}
catch (Exception e) { }
Iterator <Student> items = studList.iterator();
while(items.hasNext()){
Student sl = items.next();
System.out.print(sl.name +" ");
System.out.print(sl.rollno +" ");
System.out.print(sl.submarks +" ");
System.out.println();
}
}

}
OOPJ(3153203) 211310132060

Output:

Signature:

Date: / /

33
AIIE-ICTB4
OOPJ(3153203) 211310132060

DATE: / /
Practical:-13
Aim: Refine the student manager program to manipulate the student information from files by
using the DataInputStream and DataOutputStream. Assume suitable data.
Program:
import java.io.*;

public class M13 {


public static void main(String[] args) {
System.out.println("--------Writing Data to File --------- ");
try {
FileOutputStream fout = new FileOutputStream("stdinfo.txt");
DataOutputStream bw = new DataOutputStream(fout);
bw.writeDouble(12.5);
bw.writeDouble(14.5);
bw.close();
System.out.println("Successful write");
} catch (Exception e) {
System.out.println(e);
}
System.out.println("---Retrieve Data from File---");
try {
FileInputStream fin = new FileInputStream("stdinfo.txt");
DataInputStream br = new DataInputStream(fin);
while (true) {
try {
double i = br.readDouble();
System.out.print(i + " ");
}
catch (EOFException e) {
break; // Exit the loop when the end of the file is reached
}
}
fin.close();
OOPJ(3153203) 211310132060

br.close();
} catch (Exception e) {
System.out.println(e);
}
}
}

Output:

Signature:

Date: / /_

35
AIIE-ICTB4
OOPJ(3153203) 211310132060

DATE: / /
Practical:-14
Aim: Prepare a class diagram for given group of classes using multiplicity, generalization,
association concepts. And add atleast 5-7 attributes and 3-5 operations for particular class page,
shape, point, Line, Arc, Ellipse, Rectangle, Circle.
Solution:

Signature:

Date: / /_
OOPJ(3153203) 211310132060

DATE: / /
Practical:-15
Aim: Prepare a class diagram for a given group of classes using multiplicity, generalization, and
association concepts. And add at least 5-7 attributes and 3-5 operations for particular class City,
Airport, Airline, Pilot, Flight, Plane, Seat, Passenger.
Solution:

Signature:

Date: / /_

37
AIIE-ICTB4
OOPJ(3153203) 211310132060

DATE: / /
Practical :-16
Aim: Categorize the following relationships into generalization, aggregation or association.
[A] A country has a capital city

[B] A dining philosopher uses a fork

[C] A file is an ordinary file or a directory file

[D] Files contains records

[E] A polygon is composed of an ordered set of points

[F] A drawing object is text, a geometrical object, or a group


OOPJ(3153203) 211310132060

[G] A person uses a computer language on a object

[H] Modems and keyboards are input/output devices

[I] Classes may have several attributes

[J] A person plays for a team in a certain year

[K] A route connects two cities


39
AIIE-ICTB4
OOPJ(3153203) 211310132060

[L] A student takes a course from a professor

Signature:

Date: / /_
OOPJ(3153203) 211310132060

DATE: / /
Practical :-17
Aim: Prepare a state diagram for an interactive diagram editor for selecting and dragging objects.
Solution:

Signature:

Date: / /_

41
AIIE-ICTB4
OOPJ(3153203) 211310132060

DATE: / /

Practical:-18
Aim: Prepare a Use case diagram and sequence diagram for a computer Email System.
Solution:

Sequence diagram for Receive Email


OOPJ(3153203) 211310132060

Sequence diagram for Compose and Send Email

Signature:

Date: / /_
43
AIIE-ICTB4
OOPJ(3153203) 211310132060

DATE: / /
Practical:-19
Aim: Prepare an activity diagram for computing restaurant bills, there should be a charge for
each delivered item. The total amount should be subject to a tax and service charge of 18% for
groups of six or more. For smaller groups, there should be a blank entry. Any coupons or gift
certificates submitted by the customer should be subtracted.
Solution:

Signature:

Date: / /_
OOPJ(3153203) 211310132060

DATE: / /
Practical:20
Aim: Prepare a sequence diagram for issuing a book in the library management system.
Solution:

Signature:

Date: / /_
45
AIIE-ICTB4
OOPJ(3153203)
221313132004

You might also like