Astha Oopj
Astha Oopj
Name : Ashapurna
En. No.: 211310132060
Branch : ICT B-4
1
AIIE-ICTB4
OOPJ(3153203) 211310132060
INDEX
St
* *
* **
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 :
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);
OUTPUT :
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;
if(op.equals("+"))
System.out.println("Sum of two
if(op.equals("/")&& b!=0)
System.out.println("Division of two
if(op.equals("%")&& b!=0)
System.out.println("Modulous of two
7
AIIE-ICTB4
OOPJ(3153203) 211310132060
if(op.equals("*"))
else
System.out.println("Wrong Input");
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
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;
System.out.print("-> ");
for(int i=le/2;i<le;i++)
{
System.out.print(str.charAt(i));
}
}
}
OOPJ(3153203) 211310132060
OUTPUT:
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+"
}
}
OUTPUT:
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:
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:
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
char ch = input.charAt(j);
countA++;
countE++;
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:");
totalA);
OUTPUT:
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 {
main(String[] args) {
Scanner s = new
Scanner(System.in);
System.out.print("Enter a string:");
String input = s.nextLine(); s.close();
}
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
{
in(String[] args)
nner(System .in);
int n = s.nextInt();
s.close();
{
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 j=0; j<n-i; j++)
{ System.out.print("");
}
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;
→ Manager class
import java.io.*;
import java.util.*;
class StudentManager {
public static void main(String[] args){
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();
os.writeObject(s1);
os.flush();
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();
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.*;
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
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:
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