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

Java Programs for ISC Class 12 Project

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

Java Programs for ISC Class 12 Project

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

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 [Link].*; //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];
[Link](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;
}
[Link](s);
}
public static void main(String[] args) {
Scanner scr=new Scanner([Link]);
[Link]("Enter the amount");
int n=[Link]();
program_01 ob=new program_01(n);
[Link]();
[Link]();
}
} //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 [Link].*; //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)
[Link]("Amt=Rs"+500);
if(n>100 && n<=200)
[Link]("Amt=Rs"+(500+(extra(n))));
if(n>200 && n<=300)
[Link]("Amt=Rs"+(600+(extra(n))));
else
[Link]("Amt=Rs"+(720+(extra(n))));
}
public static void main(String args[]){

Scanner scr=new Scanner([Link]);


[Link]("Enter the number of calls");
int call=[Link]();
program_02 ob=new program_02(call);

[Link]();
}
} //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 [Link].*; //importing package
public class program_03 { //declaring class
int h,m,s;
void input(){ //inputting the times
Scanner scr=new Scanner([Link]);
[Link]("Enter hours");
h=[Link]();
[Link]("Enter mins");
m=[Link]();
[Link]("Enter secs");
s=[Link]();
}
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;
[Link]("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();
[Link]();
[Link]();
program_03 ob3=new program_03();
[Link](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 [Link].*; //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([Link]);
[Link]("Enter "+n+" strings");
for(int i=0;i<n;i++)
a[i]=[Link]();
}
String reverse(String s){ //to reverse the string
String s1="";
for(int i=([Link]()-1);i>=0;i--){
char ch=[Link](i);
s1+=ch;
}
return s1;
}
String ahead(String s){//two characters ahead of the original
String s1="";
for(int i=0;i<[Link]();i++){
char ch=[Link](i);
if([Link](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++)
[Link](a[i]);
}
public static void main(String[] args) {
Scanner scr=new Scanner([Link]);
[Link]("Enter the value of n");
int size=[Link]();
if(size<1 || size>10){
[Link]("the value of n must be greater than 1 and less than 10");
[Link](0);
}
else{
program_04 ob=new program_04(size);
[Link]();
[Link]();
}
}
} //end of class

Output:

Common questions

Powered by AI

This approach disrupts natural sentence ordering and character placement, potentially enhancing security by obscuring original content. However, it significantly impairs readability as reversed or modified character sequences may become incomprehensible, which is not conducive to information retrieval or communication .

Potential issues include handling non-alphabetic characters when incrementing two characters ahead, which the program checks conditionally. Reversing strings doesn't thoroughly account for multi-byte characters or characters outside of the standard ASCII range, potentially causing unexpected behavior with certain inputs .

The program calculates total time by converting hours to seconds, minutes to seconds, and adding them with the seconds, resulting in a total second calculation. It handles overflow by using integer division and modulo operators to work back up to hours, minutes, and seconds, which is an effective method for modular arithmetic in time calculations .

User input validation is crucial as it prevents erroneous input, like entering a size for an array outside the specified range, which helps avoid errors and exceptions during runtime. It improves user experience by providing immediate feedback and ensuring the program operates within expected parameters .

The program determines the number of notes by dividing the amount by the highest available denomination and continues this process through the array of denominations in descending order. This approach is significant because it minimizes the number of notes needed, which is efficient for both storage and handling of money .

Improvements could include implementing input checks that confirm numerical inputs and error handling for non-integers or negative numbers. Extending functionality for international calls or varying rates based on additional criteria such as call duration could also enhance robustness and applicability of the program .

The time addition program uses modular arithmetic by breaking down time into seconds, then reconverting back to hours, minutes, and seconds using division and modulus operations. These principles can be applied in contexts like cyclic scheduling, encryption, and digital signal processing where periodic or cyclic behavior is involved .

Changing the character offset from two to three would further obscure the original content by shifting characters further from their original position, potentially increasing security. However, it also risks creating more character overflows beyond the alphabet and necessitates additional handling logic, altering the encoding dynamics substantially .

The program converts amounts into words by matching each digit to a corresponding word in a predefined array. Limitations might include not handling numbers beyond single digits effectively, and lacking punctuation or structure for compounded numbers like 'twenty-one' .

The program implements the tiered pricing structure by initially setting a base amount for up to 100 calls and then calculating additional charges based on call increments over key thresholds (100, 200, 300). Each range has a different pricing formula, ensuring users are billed appropriately for their level of usage .

You might also like