0% found this document useful (0 votes)
7 views

Comp Prject11

, kl
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)
7 views

Comp Prject11

, kl
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/ 26

11.

WAP to input a string and count the number of vowels present in the
string.
class vowels{
public static void main(String S){
S=S.trim();
int l=S.length();
S=S.toUpperCase();
int c=0;
for(int i=0; i<l; i++)
{
char ch=S.charAt(i);
if(ch=='A' || ch=='E' || ch=='O' || ch=='I' || ch=='U' )
{
c++;

}
}
System.out.println("Number of vowels =" + c);

}
}
OUTPUT

(String S= “classmate”)

VARIABLE DESCRIPTION TABLE

VARIABLE DATA TYPE PURPOSE


S String To store the string
L int to store the length of
the string
C int To store the number of
vowels present in the
string
Ch char To store each letter of
the string
I int Counter variable
12. WAP to input a string and count the number of words present in the
string.
class vowels{
public static void main(String S){
S=S.trim();
int l=S.length();

int c=0;
for(int i=0; i<l; i++)
{
char ch=S.charAt(i);
if(ch==' ' )
{
c++;

}
}
System.out.println("Number of words =" +( c+1));

}
}
OUTPUT

(String S= “She is a girl”)

VARIABLE DESCRIPTION TABLE


VARIABLE DATA TYPE PURPOSE
S String To store the string
L int to store the length of
the string
C int To store the number of
words present in the
string
Ch char To store the number of
spaces in the string
I int Counter variable
13. WAP to input a sentence. Print each word of the sentence along with its
length.

import java.util.Scanner;
class c{
public static void main(){
Scanner sc=new Scanner (System.in);
System.out.println("Enter a sentence");
String S=sc.nextLine();
S=S.trim();
S=S + " ";
int l=S.length();
String NS="";
for (int i=0; i<l ; i++)
{
char ch=S.charAt(i);
if (ch!=' ')
{
NS=NS+ch;
}
else
{
System.out.println(NS);
System.out.println( NS.length());
NS="";
}
}
}}

OUTPUT

VARIABLE DESCRIPTION TABLE


VARIABLE DATA TYPE PURPOSE
S String To store the string
l int to store the length of
the string
NS String To store an empty string
ch char To store each character
of the string
i int Counter variable
14. WAP to input your name and print it alphabetically

class vowels{
public static void main(String S){
S=S.trim();
S=S.toUpperCase();
int l=S.length();
String NS=" ";
for(char ch='A' ; ch<='Z'; ch++)
{
for(int i=0; i<l; i++)
{
if(S.charAt(i)==ch)

{
NS=NS+ ch;
}}}

System.out.println(NS);

}
}
OUTPUT

(String S=”Priya”)

VARIABLE DESCRIPTION TABLE


VARIABLE DATA TYPE PURPOSE
S String To store the string
L int to store the length of
the string
NS String To store an empty
string

Ch char Counter variable


I int Counter variable
15. WAP to input two strings and check whether they are an anagram or not .
Anagram strings are those which when alphabetically arranged are equal to
each other.
class anagram{
public String Arrange(String S){
S=S.trim();
S=S.toUpperCase();
int l=S.length();
String NS=" ";
for(char ch='A' ; ch<='Z'; ch++)
{
for(int i=0; i<l; i++)
{
if(S.charAt(i)==ch)

{
NS=NS+ ch;}}}
return NS;
}
public static void main(String S1, String S2){
anagram ob=new anagram();
String P=ob.Arrange(S1);
String Q=ob.Arrange(S2);
if(P.compareTo(Q)==0)
System.out.println(P+" " +Q +" "+ "are anagram strings");
else
System.out.println("NO");}}
OUTPUT

( the strings inputted are “dad and “dda”)

VARIABLE DESCRIPTION TABLE


VARIABLE DATA TYPE PURPOSE
S String To store the string
l int to store the length of
the string
NS String

ch char Counter variable


i int Counter variable
S1 String To store a string
S2 String To store a string
P String To store alphabetically
arranged form of String
S1
Q String To store alphabetically
arranged form of String
S2

16. WAP to create a class with the following specifications


1) class name employee
2) member variable
 eno(employee no.)
 ename(employee name)
 age(age of employee)
 basic(basic salary)
 net(to store the net salary )
3) member functions
 void accept ()
 void calculate()
net=basic +hra+da-pf
hra=18.5% of basic
da=17.45% of basic
pf= 8.10% of basic
Accept details using scanner class
If age> 50 , extra 5000/- in net salary.
void print()
void main()

import java.util.Scanner;
class employee
{
int eno,age;
String ename;
double basic,net;
void accept()
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter details");
eno=sc.nextInt();
age=sc.nextInt();
ename=sc.next();
basic=sc.nextDouble();
}
void calculate()
{
double hra=(18*basic)/100.0;
double da=(17.45*basic)/100.0;
double pf=(18.10*basic)/100.0;;
net=basic+hra+da-pf;
if(age>50)
{
net+=5000;

}
}
void print()
{
System.out.println("eno"+ eno +"\t ename"+ ename);
System.out.println("age="+age +"\t basic " +basic);
System.out.println("Net" + net);
}
public static void main()
{
employee ob= new employee();
ob.accept();
ob.calculate();
ob.print();
}
}
OUTPUT

VARIABLE DESCRIPTION TABLE


VARIABLE DATA TYPE PURPOSE
basic double To store basic salary
eno int to store employee
number
ename String To store employee
name

net double To store net salary


age int To store employee age
hra double To store 18.5 % of basic
salary
pf double To store 8. 10 % of basic
salary
da double To store 17.45 percent
of basic salary

17. WAP to create a class to overload a method pattern()


1. void pattern()
4321
321
21
1
2. void pattern (int r,int c)
12345
12345
12345
12345

class pp{
void pattern()
{
for(int i=4; i>=1; i--)
{
for(int j=i;j>=1; j--)
{
System.out.print(j + " ");
}
System.out.println();

}
}
void pattern(int r,int c)
{
for(int i=1; i<=r; i++)
{
for(int j=1; j<=c; j++){
System.out.print(j+ " ");}
System.out.println();

}
}

OUTPUT
VARIABLE DESCRIPTION TABLE
VARIABLE DATA TYPE PURPOSE
r int to store the number of
rows
j int Counter variable
i int Counter variable
c int To store the number of
columns

18. WAP to design a class to overload a function volume as follows


double volume (double R)
V =4/3 * 22/7*R^3
double volume(double H , double R)
V=22/7*R^2 *H
Double volume(double L, double B, double H)
V=L*B*H
class pp{
double volume(double R)
{double V=4/3 * 22/7 * R*R*R;
return V;
}
double volume(double R ,double H)
{double V=22/7.0 * R*R*H;
return V;
}
double volume(double L, double B, double H)
{double V=L*B*H;
return V;}

OUTPUT
VARIABLE DESCRIPTION TABLE
VARIABLE DATA TYPE PURPOSE
R double To store the radius
H double to store the height
L double To store the length
B double To store the breadth
V double To store the volume

19. A DTDC courier company chargesfor the courier based on the weight of
the parcel . Define a class with the following specifications
1)class name courier
2)member variable
 name
 weight
 address
 bill
Type ‘D’ for domestic and ‘I’ for international
3)member methods
 void accept ()
 void calculate()
WEIGHT PRICE /Kg
First 5 kg 800/-
Next 5 kg 700/-
Above 10kg 500/-

Additional 1500/- if the type is international


4)void print()
5)void main()

import java.util.Scanner;
class employee
{
int bill,weight;
String name,address;
char type ;
void accept()
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter details");
name=sc.next();
weight=sc.nextInt();
address=sc.next();
bill=sc.nextInt();

System.out.println("Enter \' D\' for domestic and \' I\' for international");
type=sc.next().charAt(0);
}
void calculate()
{

if(weight<=5)
{
bill=weight*800;

}else if(weight>5 && weight<=10)


{
bill=(5*800) + (weight-5)* 700;

}else
{
bill=(5*800)+ (5*700)+(weight -10) *500;

if (type== 'I')
{bill=bill+1500;
}
}
void print()
{
System.out.println("bill=" + bill);
System.out.println("name=" + name);
System.out.println("address=" + address);
System.out.println("type=" + type);
}
public static void main(){
employee ob=new employee();
ob.accept();
ob.calculate();
ob .print();
}
}

OUTPUT

VARIABLE DESCRIPTION TABLE


VARIABLE DATA TYPE PURPOSE
basic double To store basic salary
Bill int to store bill
name String To store name
address String To store the address
weight int To store the weight of
the parcel
type char To store the
type(international or
domestic)

20. WAP to create a method double S1(int ,int,int) . Invoke the above method
from the main function.

class pp{
double SI(int R, int T, int P)
{double s=(P*T*R) /100.0;
return s;
}
void main(int p, int r, int t)
{
pp ob=new pp();
double Q=ob.SI(p,t,r);
System.out.println(R);
}

OUTPUT
(p=500, r=5, t=5)

VARIABLE DESCRIPTION TABLE


VARIABLE DATA TYPE PURPOSE
S double To store the simple
interest
P int to store the principal
T int To store time

R int To store the rate of


interest
T int To store the time
P int To store the principal
r int To store the rate of
interest
Q double To create and store an
object of the class SI

PROJECT
NAME : Siddhima Goel

CLASS : X SECTION: F

SUBJECT: Computer

SUBJECT TEACHER: Mrs. Zehra Abbas

SCHOOL : City Montessori School

ROLL NUMBER: 45

internal examiner’s external examiner’s


sign sign

You might also like