0% found this document useful (0 votes)
1 views8 pages

Class 12 ISC Java Programs

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)
1 views8 pages

Class 12 ISC Java Programs

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/ 8

QUESTION 01: Program to accept the amount from the user and display the break-up in descending

Order of denominations. (i.e. preference should be given to the highest denomination available)
along with the total number of notes. The available denomination in the Bank are of rupees 1000,
500, 100, 50,20,10,5,2 and 1. Also print the amount in words according to the digits.

Algorithm:

1. Start.
2. [initialize the variables]
Money[]={1000,500,50,20,10,5,2,1}
Words[]={“one”,”two”,.......”nine”)
3. Print “Enter the amount”.
4. Store the value in amt.
5. [breaking the money]
Repeat i for 0,1,2....9
P=amt/Money[i]
If (P>0)
amt=amt % Money[i]
print P
end if
end loop i
6. [getting the amount digits in words]
[count the number of digits and store in L]
while 'amt' is greater than 0:
Increment 'L' by 1
Update 'amt' by dividing it by 10
end while loop
Repeat i for 0,1,2....L
T=amt % 10
S=Word[i]+ “ ”+S
amt=amt/10
end for i
7. Print S
8. Stop

Code:
import java.util.*; //declaring package
public class program_01 { //declaring class name
int amt,l,m[]={1000,500,100,50,20,10,5,2,1};
String s, w[]={"Zero","One","Two","Three","Four","Five","Six","Seven","Eight","Nine"};
program_01(int n){
amt=n;
s="";
l=0;
}

1
void Break(){ //breaks the amount in descending
int a=amt;
for(int i=0;i<9;i++) {
int p=a/m[i];
if(p>0){
a=a%m[i];
System.out.println(m[i]+" * "+p+" = "+(p*m[i]));
}
}
}
void word(){ //gets the amount in words
for(int i=amt;i>0;i=i/10)
l++;
for(int i=0;i<l;i++){
int t=amt%10;
s=w[t]+" "+s;
amt=amt/10;
}
System.out.println(s);
}
public static void main(String[] args) {
Scanner scr=new Scanner(System.in);
System.out.println("Enter the amount");
int n=scr.nextInt();
program_01 ob=new program_01(n);
ob.Break();
ob.word();
}
} //end of class

Output:

2
QUESTION 02:Program to accept number of telephone calls made and other details and calculates
total amount and prints all relevant details. Amount calculation is as per the following table:

Number of calls Cost


< 100 Rs. 500
101-200 Rs. 500 + Rs. 1 per extra calls over 100
201-300 Rs. 600 + Rs. 1.2 per extra calls over 200
> 300 Rs. 720 + Rs. 1.5 per extra calls over 200
Algorithm:

1. Start.
2. Input and store the number of calls in N.
3. [calculating extra amounts]
y=N
if((y/100)=1)
c=(y % 100)+c
if((y/100)=2)
c=(y % 100)*1.2+c
if((y/100)=3)
c=(y % 100)*1.5+c
if((y/100)>3)
c=(y-300)+(y % 100)*1.5+c
4. [calculating total amount]
if(N<=100)
total=500
if(n>100 and n<=200)
total= (500 +c)
if(n>200 and n<=300)
total=(600+c)
else
total=(720+c)
5. Display (total).
6. Stop.

Code:
import java.util.*; //importing package
class program_02{ //declaring class name
int n;
program_02(int x){
n=x;
}
double extra(int y){ //to calculate extra amounts
double c=0;
if((y/100)==1)
c+=(y%100);

3
if((y/100)==2)
c+=(y%100)*1.2;
if((y/100)==3)
c+=(y%100)*1.5;
if((y/100)>3)
c+=(y-300)+(y%100)*1.5;
return c;
}
void display(){ //calculating and displaying total cost
if(n<=100)
System.out.println("Amt=Rs"+500);
if(n>100 && n<=200)
System.out.println("Amt=Rs"+(500+(extra(n))));
if(n>200 && n<=300)
System.out.println("Amt=Rs"+(600+(extra(n))));
else
System.out.println("Amt=Rs"+(720+(extra(n))));
}
public static void main(String args[]){

Scanner scr=new Scanner(System.in);


System.out.println("Enter the number of calls");
int call=scr.nextInt();
program_02 ob=new program_02(call);

ob.display();
}
} //end of class
Output:

4
QUESTION 03: Program to add two given times and display it in the hour:minute:second format.
Algorithm:

1. Start.
2. Accept and store the hours in h1 and h2
3. Accept and store the minutes in m1 and m2
4. Accept and store the seconds in s1 and s2
5. Hours=(h1+h2)*3600
6. Mins=(m1+m2)*60
7. Secs=(s1+s2).
8. total=Hours+Mins+Secs
9. Display (total/3600)hrs ((total%3600)/60)mins ((total%3600)%60)secs
10. Stop.

Code:
import java.util.*; //importing package
public class program_03 { //declaring class
int h,m,s;
void input(){ //inputting the times
Scanner scr=new Scanner(System.in);
System.out.println("Enter hours");
h=scr.nextInt();
System.out.println("Enter mins");
m=scr.nextInt();
System.out.println("Enter secs");
s=scr.nextInt();
}
void add(program_03 x, program_03 y){ //adding the two times
int Ts=x.s+y.s;
int Tm=(x.m+y.m)*60;
int Th=(x.h+y.h)*3600;
int T=Ts+Tm+Th;
System.out.println("Total time: "+(T/3600)+"hr "+((T%3600)/60)+"min "+((T%3600)%60)+"sec");
}
public static void main(String args[]) {
program_03 ob1=new program_03();
program_03 ob2=new program_03();
ob1.input();
ob2.input();
program_03 ob3=new program_03();
ob3.add(ob1,ob2);
}
} //end of class

5
Output:

QUESTION 04 : A String array of size ‘n’ where ‘n’ is greater than 1 and less than 10, stores single
sentences (each sentence ends with a full stop) in each row of the array. Write a program to accept
the size of the array. Display an appropriate message if the size is not satisfying the given condition.
Define a string array of the inputted size and fill it with sentences row-wise. Change the sentence of
the odd rows with an encryption of two characters ahead of the original character. Also change the
sentence of the even rows by storing the sentence in reverse order. Display the encrypted
sentences.
Algorithm:

1. Start.
2. Accept and store size in N for the string array (str[])
3. If N <1 or N>10
Terminate the program with proper message.
4. [input the strings]
For i from 0 to (N-1)
Accept and store strings in str[i].
5. [ function reverse(s) to reverse the word]
STR=null
For i from (N-1) to 0
Ch=character of the string s of index i
STR=STR+Ch
End for i.
Display (STR).
6. [function ahead(S )for getting two characters ahead of original character]
STR=null
For i from 0 to (N-1)
Ch=character of the string S at index i
If(Ch is a letter)
If((convert to integer)(ch+3)>122)
STR =STR + ((ch+3)-26)
Else

6
String=String+(convert to character)(ch+3)
End If
Else
String=String+ch
End for i
Display (STR).
7. [displaying the new strings]
For i from 0 to (N-1)
If(i % 2=0)
reverse( str[i])
Else
ahead( str[i])
8. Stop.

Code:
import java.util.*; //importing package
public class program_04 { //declaring class
int n;String a[];
program_04(int x){
n=x;
a=new String[n];
}
void input(){ //taking input
Scanner scr=new Scanner(System.in);
System.out.println("Enter "+n+" strings");
for(int i=0;i<n;i++)
a[i]=scr.nextLine();
}
String reverse(String s){ //to reverse the string
String s1="";
for(int i=(s.length()-1);i>=0;i--){
char ch=s.charAt(i);
s1+=ch;
}
return s1;
}
String ahead(String s){//two characters ahead of the original
String s1="";
for(int i=0;i<s.length();i++){
char ch=s.charAt(i);
if(Character.isLetter(ch)){
if((int)(ch+3)>122)
s1+=(char)((((int)ch+3)-26));
else

7
s1+=(char)(ch+3);
}
else
s1=s1+ch;
}
return s1;
}
void display(){ //displaying the new strings
for(int i=0;i<n;i++){
if(i%2==0)
a[i]=reverse(a[i]);
else
a[i]=ahead(a[i]);
}
for(int i=0;i<n;i++)
System.out.println(a[i]);
}
public static void main(String[] args) {
Scanner scr=new Scanner(System.in);
System.out.println("Enter the value of n");
int size=scr.nextInt();
if(size<1 || size>10){
System.out.println("the value of n must be greater than 1 and less than 10");
System.exit(0);
}
else{
program_04 ob=new program_04(size);
ob.input();
ob.display();
}
}
} //end of class

Output:

You might also like