Computer Project Isc Class 11 1st Term
Computer Project Isc Class 11 1st Term
CONTENTS
2|Page
INTRODUCTION
Key Features:
- Object-Oriented - Security.
- Exception Handling - Platform Independence
- Rich Standard Library - Memory Management.
BlueJ Software:
BlueJ is an integrated development environment (IDE) specifically designed for teaching and
learning Java programming. It was developed at the University of Kent and Deakin
University to provide a user-friendly environment for beginners to grasp the concepts of
object-oriented programming.
Key Features:
- Simplicity - Object Inspection
- Visual Representation - Integrated Editor
- Interactive Debugger - Educational Focus
3|Page
PROGRAM 1
Question:
Design a class named “ElectricityBill” having the following data members and member
functions:
Data Members:
int units : stores the number of units consumed in a month
billAmt : stores the bill amount payable
Member Functions:
void accept( ) : accepts the number of units consumed in a month
float calcBill( ) : returns the net bill amount to be paid as per the criteria given below:
Units Consumed Rate / unit (in Rs.)
<=50 2.25
<=150 and >50 3.75
<=300 and >150 5.25
<=550 and >300 7.75
>550 9.50
void display( ) : displays the net bill amount
Define a main( ) to invoke the functions of the above class using an object of the above class.
Algorithm:
1. Start of algorithm
4. Declare private instance variables `units` (int) and `billAmt` (float) within the class.
4|Page
6. Create a parameterized constructor `ElectricityBill(int units, float billAmt)`:
- Set the `units` and `billAmt` variables using the values passed as arguments.
5|Page
Source Code:
6|Page
billAmt=(units-50)*3.75f+50*2.25f;
}
else if(units<=300){
billAmt=(units-150)*5.25f+50*2.25f+150*3.75f;
}
else if(units<=550){
billAmt=(units-300)*7.75f+50*2.25f+150*3.75f+150*3.75f;
}
else{
billAmt=(units-550)*9.50f+50*2.25f+150*3.75f+150*3.75f+250*7.75f;
}
return billAmt; // returning the bill amount as per the criteria
} // end of clacBill member function
void display()
{ // start of dislay member function
System.out.println("The Final Bill Amount Of The Customer: "+calcBill());// displaying
the final bill amount
} // end of dislay member function
public static void main(String args[])
{ // start of main method
ElectricityBill ob=new ElectricityBill();
ob.accept();
ob.display();
} // end of main method
} // end of class
7|Page
PROGRAM 2
Question:
Design a class named “Parking” having the following data members and member functions:
Data Members:
String vehNo : stores the vehicle number
int hrs : stores the number of hours parked
Member Functions:
void accept( ) : accepts the details of the vehicle from the user
int getCharges( ) : returns the total parking charges as per the criteria given below:
Parking Hours Rate / hour (in Rs.)
First 3 hours 35
Next 3 hours 30
Next 4 hours 28
Next 5 hours 25
Above 15 hours 22
void display( ) : displays the details of the vehicle and parking charges payable.
Define a main( ) to invoke the functions of the above class using an object of the above class
Algorithm:
1. Start of algorithm.
- Declare private instance variables: `vehNo` of type `String` and `hrs` of type `int`.
8|Page
- Define a parametrized constructor:
- Accept parameters `vehNo` and `hrs`.
- Set `this.vehNo` to `vehNo`.
- Set `this.hrs` to `hrs`.
9|Page
- Create an instance of the `Parking` class named `ob`.
- Call the `accept()` method on `ob` to input vehicle details.
- Call the `display()` method on `ob` to display the vehicle details and parking charges.
4. In the `main` method, create an object of the `Parking` class named `ob`.
5. Call the `accept()` method on the `ob` object to input vehicle details.
6. Call the `display()` method on the `ob` object to display the vehicle details and calculated
parking charges.
Source Code:
10 | P a g e
vehNo=sc.nextLine();// stores the vehicle number
System.out.println("Enter the number of Hours the vehicle is parked");
hrs=sc.nextInt();// stores the number of hours for which the car is parked
}// end of accept member function
int getCharges(){ // start of getCharges member function
int ch=0; // stores the amount charged according to the criteria
if(hrs<=3){
ch=hrs*35;
}
else if(hrs<=6){
ch=(3*35)+((hrs-3)*30);
}
else if(hrs<=10){
ch=(3*35)+(3*30)+((hrs-4)*28);
}
else if(hrs<=15){
ch=(3*35)+(3*30)+(28*4)+((hrs-5)*25);
}
else{
ch=(3*35)+(3*30)+(28*4)+(25*5)+(hrs*22);
}
return ch; // returning the parking charges as per the criteria
} // end of getCharges member function
void display(){// start of dislay member function
System.out.println("Vehicle Number "+vehNo);
System.out.println("The number of Hours the vehicle is parked "+hrs);
System.out.println("The Parking Charge "+getCharges());
} // end of dislay member function
public static void main(String args[]){ // start of main method
Parking ob=new Parking();
11 | P a g e
ob.accept();
ob.display();
} // end of main method
} // end of class
12 | P a g e
PROGRAM 3
Question:
Design a class named “PrimeNumbers” having the following data members and member
functions:
Data Members:
int x, y : stores the lower and upper limit of the range of numbers.
Member Functions:
void accept( ) : accepts the lower and upper limits from the user.
boolean isPrime(int num) : returns true if the number ‘num’ is prime otherwise it returns
false.
void display( ) : displays the prime numbers between the range x and y.
Define a main( ) to invoke the functions of the above class using an object of the above class.
Algorithm:
1. Start of algorithm.
13 | P a g e
- Define a method `isPrime(int num)` that takes an integer `num` as input and returns a
boolean:
- Declare an integer `i` and initialize it to 1.
- Declare an integer `f` and initialize it to 0 (to count factors).
- Use a loop that iterates from `1` to `num` (inclusive):
- Check if `num` is divisible by `i` (num % i == 0).
- If true, increment `f`.
- Return `f` is equal to `2`. (A prime number has exactly two factors: 1 and itself.)
- Call the `accept()` method on the `ob` object to input lower and upper limits.
- Call the `display()` method on the `ob` object to display prime numbers within the
specified range.
14 | P a g e
Source Code:
import java.util.*;
class PrimeNumbers
{
int x,y;
void accept()
{
Scanner sc= new Scanner(System.in);
System.out.println(" Enter lower and upper limit ");
x=sc.nextInt();
y=sc.nextInt();
}
void display()
{
for(int i=x;i<=y;i++)
{
if(isPrime(i))
System.out.println(i);
15 | P a g e
}
}
16 | P a g e
PROGRAM 4
Question:
Design a class named “KrishnaMurthyNums” having the following data members and
member functions:
Data Members:
int n : stores a positive number accepted from the user
Member Functions:
void takeNum( ) : accepts the number from the user
Define a main( ) to invoke the functions of the above class using an object of
the above class.
Algorithm:
1. Start of algorithm.
- Define a method `isKrishna(int num)` that takes an integer `num` as input and returns a
boolean:
- Set `n` to the value of `num`.
- Compare the result of `getSum()` with `n`.
- If they are equal, return `true`, else return `false`.
18 | P a g e
- Call the `takeNum()` method on `ob` to input a number.
- Call the `display()` method on `ob` to determine and display if the number is
Krishnamurthy.
- Call the `display()` method on the `ob` object to determine and display whether the
number is Krishnamurthy.
Source Code:
import java.util.*;
class KrishnaMurthyNums
{
int n;
void takeNum()
{
Scanner sc= new Scanner(System.in);
System.out.println(" Enter a number ");
n=sc.nextInt();
}
19 | P a g e
for(i=1;i<=num;i++)
f*=i;
return f;
}
int getSum()
{
int d,s=0,m=n;
while(m!=0)
{
d=m%10;
s=s+factorial(d);
m=m/10;
}
return s;
}
void display()
{
if(isKrishna(n))
System.out.println(" Krishnamurthy number ");
20 | P a g e
else
System.out.println(" Not Krishnamurthy number ");
21 | P a g e
PROGRAM 5
Question:
Design a class named “Pattern” having the following data members and member functions:
Data Members:
int rows : stores the number of rows of the pattern
Member Functions:
void getRows( ) : accepts the number of rows from the user
void display( ) : displays the pattern as shown below:
The Patterns shown below is for input rows=5
&
& @ &
& @ @ @ &
& @ @ @ @ @ &
& & & & & & & & &
Define a main( ) to invoke the functions of the above class using an object of the above
class.
Algorithm:
1. Start of algorithm
22 | P a g e
- Create a `Scanner` object.
- Print a message to prompt the user to input the number of rows.
- Read and store the input number in `rows`.
- Call the `getRows()` method on the `ob` object to input the number of rows.
- Call the `display()` method on the `ob` object to display the pattern.
23 | P a g e
Source Code:
import java.util.*;
class Pattern
{
int rows;
void getRows()
{
Scanner sc= new Scanner(System.in);
System.out.println(" Enter no rows "); rows=sc.nextInt();
}
void display()
{
int i,j,k;
for(i=1;i<=rows;i++)
{
for(k=1;k<=(rows-i);k++)
{
System.out.print(" ");
}
for(j=1;j<i*2;j++)
{
if( j==1 || j==(i*2-1) || i==rows)
System.out.print("&");
else
System.out.print("@");
}
System.out.println();
}
24 | P a g e
}
25 | P a g e
PROGRAM 6
Question:
Design a class named “SmithNum” having the following data members and member
functions:
Data Members:
int num : stores the number to be checked.
Member Functions:
void getNum( ) : accepts the number from the user
Define a main( ) to invoke the functions of the above class using an object of the above
class.
Algorithm:
1. Start of algorithm
26 | P a g e
- Declare an instance variable `num` of type `int`.
- Define a method `sumDigits(int n)` that takes an integer `n` as input and returns an
integer:
- Declare an integer `d` and initialize it to 0.
- Declare an integer `s` and initialize it to 0.
- Use a loop to extract digits from `n`:
- Calculate `d` as `n % 10`.
- Add `d` to `s`.
- Update `n` by dividing it by 10.
- Return the value of `s`.
- Define a method `getSumofPF(int n)` that takes an integer `n` as input and returns an
integer:
- Declare an integer `i` and initialize it to 2.
- Declare an integer `s` and initialize it to 0.
- Use a loop while `i` is less than or equal to `n`:
- Check if `n` is divisible by `i` (n % i == 0).
- If true, add the sum of digits of `i` to `s` using the `sumDigits()` method.
- Update `n` by dividing it by `i`.
- If not divisible, increment `i`.
- Return the value of `s`.
27 | P a g e
- Define a method `display()`:
- Check if the input number `num` is a Smith number using the `isSmith()` method.
- Print "Smith number" if true, otherwise print "Not Smith number".
- Call the `display()` method on the `ob` object to determine and display whether the
number is a Smith number.
The provided Java program checks if a given number is a Smith number, where the sum of
the digits of the number is equal to the sum of the digits of its prime factorization. The
algorithm breaks down the code's functionality into steps to provide a clear understanding of
its structure and logic.
Source Code:
import java.util.*;
class SmithNum
{
int num;
28 | P a g e
void getNum()
{
Scanner sc= new Scanner(System.in);
System.out.println(" Enter a number ");
num=sc.nextInt();
}
int getSumofPF(int n)
{
int i=2,s1=0 ;
while(i<=n)
{
if(n%i==0)
{
s1=s1+sumDigits(i);
n=n/i;
}
else
29 | P a g e
{
i++;
}
}
return s1;
}
boolean isSmith()
{
if(sumDigits(num) == getSumofPF(num))
return true;
else
return false;
}
void display()
{
if(isSmith())
System.out.println(" Smith number ");
else
System.out.println(" Not Smith number ");
}
30 | P a g e
Variable Description Table:
31 | P a g e
PROGRAM 7
Question:
Design a class named “Words” having the following data members and member functions:
Data Members:
String w : stores a word accepted from the user
int n : stores the number of words to be accepted from the user
Member Functions:
int readWords( ) : accepts the words from the user and returns a count of
the number of words which ends and starts with a vowel.
boolean checkVowel(String s) : returns true if the word stored in ‘s’ starts and
ends with a vowel, otherwise returns false
void display( ) : displays the number of words which
starts and ends with a vowel.
Algorithm:
1. Start of algorithm.
- Declare instance variables `w` of type `String` and `n` of type `int`.
32 | P a g e
- Prompt the user to input the number of words.
- Read and store the input number in `n`.
- Initialize an integer `t` to 0 (to count words that start and end with vowels).
- Use a loop to input `n` words:
- Prompt the user to input a word.
- Read and store the word in `w`.
- Check if the word starts and ends with vowels using the `checkVowel()` method:
- If true, increment `t`.
- Return the value of `t`.
- Define a method `checkVowel(String s)` that takes a string `s` as input and returns a
boolean:
- Get the length of string `s` and store it in `l`.
- Create a string `v` containing all the vowel characters in upper and lower case:
`"AEIOUaeiou"`.
- Get the first character `c` of string `s`.
- Get the last character `d` of string `s`.
- Check if both `c` and `d` are present in the `v` string using the `indexOf()` method:
- If true, return `true` (word starts and ends with a vowel).
- If not, return `false`.
33 | P a g e
- Create an object of the `Words` class named `ob`.
- Call the `display()` method on the `ob` object to perform the word processing and display
the count.
Source Code:
import java.util.*;
class Words {
String w;
int n;
int readWords() {
Scanner sc = new Scanner(System.in);
System.out.println("Enter the number of words");
n = sc.nextInt();
int t = 0;
for (int i = 1; i <= n; i++) {
System.out.println("Enter a word");
w = sc.next();
if (checkVowel(w))
t = t + 1;
}
return t;
}
boolean checkVowel(String s) {
34 | P a g e
int l = s.length();
String v = "AEIOUaeiou";
char c = s.charAt(0);
char d = s.charAt(l - 1);
if (v.indexOf(c) >= 0 && v.indexOf(d) >= 0)
return true;
else
return false;
}
void display() {
int count = readWords();
System.out.println("Number of words starting and ending with a vowel: " + count);
}
35 | P a g e
PROGRAM 8
Question:
Design a class named “PrimeWords” having the following data members and member
functions:
Data Members:
String sent : stores the sentence to be operated upon
String fstr : stores a list of words whose sum of the ASCII value of the letters is
a prime number.
Member Functions:
void accept( ) : accepts a sentence from the user
int getSum(String w) : returns the sum of the ASCII value of the letters of the word ‘w’.
void findWords( ) : stores all the words from the sentence ‘s’ whose
sum of the ASCII value of the letters is a prime number into the String
object ‘fstr’.
void show( ) : displays the original sentence and the list of words
whose sum of the ASCII value of the letters is a prime number.
Define a main( ) to invoke the functions of the above class using an object of the above
class.
Algorithm:
1. Start of Algorithm
2. Class PrimeWords
- Declare instance variables `sent` (String) and `fstr` (String).
Method: accept()
- Display "Enter a sentence:"
- Create a `Scanner` object `sc`.
- Read a line of text from user input using `sc`.
36 | P a g e
- Store the input text in `sent`.
Method: getSum(String w)
- Initialize an integer variable `sum` to 0.
- For each character `c` in string `w`:
- Add the ASCII value of `c` to `sum`.
- Return `sum`.
Method: findWords()
- Initialize an empty string array `words`.
- Split the `sent` into words using space as a delimiter and store in `words`.
- For each word `word` in `words`:
- Calculate the sum of ASCII values of characters in `word` using `getSum()`.
- If the sum is prime (using `isPrime()`):
- Append `word` to `fstr`.
Method: show()
- Print "Original Sentence: " followed by `sent`.
- Print "Words with Prime ASCII Sum: " followed by `fstr`.
37 | P a g e
- Call the `show()` method on `ob` to display the results.
5. End of Algorithm
Source Code:
import java.util.*;
class PrimeWords {
String sent;
String fstr;
void accept() {
System.out.println("Enter a sentence:");
Scanner sc = new Scanner(System.in);
sent = sc.nextLine();
}
int getSum(String w) {
38 | P a g e
int sum = 0;
for (int i = 0; i < w.length(); i++) {
sum += (int) w.charAt(i);
}
return sum;
}
void findWords() {
fstr = "";
String[] words = sent.split(" ");
for (String word : words) {
int sum = getSum(word);
if (isPrime(sum)) {
fstr += word + " ";
}
}
}
39 | P a g e
void show() {
System.out.println("Original Sentence: " + sent);
System.out.println("Words with Prime ASCII Sum: " + fstr);
}
40 | P a g e
Variable Description Table:
41 | P a g e
PROGRAM 9
Question:
Design a class named “ChangeVowels” having the following data members and member
functions:
Data Members:
String w : stores a word to be operated upon
String nw : stores the changed word
Member Functions:
void readWord( ) : accepts a word from the user.
String change( ) : returns a word with all the vowels changed to
uppercase and consonants changed into lowercase.
void display( ) : displays the original word and the new word.
Define a main( ) to invoke the functions of the above class using an object of the above
class.
Algorithm:
Certainly, here's the algorithm for the provided Java program:
1. Start of Algorithm.
2. Class ChangeVowels
- Declare instance variables `w` (String) to store the input word and `nw` (String) to store
the changed word.
Method: readWord()
- Display "Enter a word:"
- Create a `Scanner` object `sc`.
- Read a word from user input using `sc` and store it in `w`.
42 | P a g e
Method: change()
- Initialize an empty string `nw`.
- For each character `c` in the string `w`:
- If `c` is a vowel (using `isVowel()`):
- Convert `c` to uppercase and append it to `nw`.
- Else:
- Convert `c` to lowercase and append it to `nw`.
- Return `nw`.
Method: isVowel(char c)
- Convert `c` to lowercase.
- If `c` is 'a', 'e', 'i', 'o', or 'u', return `true`; otherwise, return `false`.
Method: display()
- Print "Original Word: " followed by the value of `w`.
- Print "Changed Word: " followed by the result of the `change()` method.
3. Create an object:
- Create an object of the `ChangeVowels` class named `ob`.
43 | P a g e
5. End of Algorithm.
Source Code:
import java.util.Scanner;
class ChangeVowels {
// Data Members
String w; // stores a word to be operated upon
String nw; // stores the changed word
44 | P a g e
return nw;
}
// Helper Function: isVowel(char c)
// Checks if the given character is a vowel.
boolean isVowel(char c) {
c = Character.toLowerCase(c);
return c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u';
}
// Member Function: display()
// Displays the original word and the new word.
void display() {
System.out.println("Original Word: " + w);
System.out.println("Changed Word: " + change());
}
// Main Method
public static void main(String args[]) {
ChangeVowels ob = new ChangeVowels();
ob.readWord();
ob.display();
}
}
Variable Description Table:
45 | P a g e
PROGRAM 10
Question:
Design a class named “LetterFreq” having the following data members and member functions:
Data Members:
String sent : stores the sentence to be operated upon.
Member Functions:
void readSentence( ) : reads a sentence from the user.
Algorithm:
1. Start of algorithm
46 | P a g e
- Initialize an integer variable `t` to count the frequency of the current letter.
- Iterate over each character `c` in the string `s`:
- Compare the current character `c` with the current letter `i`:
- If they are equal, increment the count `t`.
- Check if `t` is greater than `0` (the letter appears in the string):
- If true, print the current letter `i` and its frequency `t`.
- Call the `display()` method on the `ob` object to display the frequency of each letter.
Source Code:
import java.util.*;
class LetterFreq
{
String sent;
void readWord( )
{
47 | P a g e
Scanner sc= new Scanner (System.in); System.out.println(" Enter a string ");
sent=sc.nextLine();
}
void display( )
{
int i,l=sent.length(),j;
String s=sent.toUpperCase();
for(i='A';i<='Z';i++)
{
int t=0;
for( j=0;j<l;j++)
{
char c=s.charAt(j);
if(c==i)
t++;
}
if(t>0)
System.out.println((char)i+" is " + t+" times");
}
}
}
}
48 | P a g e
Variable Description Table:
49 | P a g e