Computer Project by Devasya Bansal

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 35

COMPUTER PROJECT

By
Devasya Bansal
Class : 10
Section : C
Roll No. : 16
Session : 2023 – 2024
Acknowledgement
I would like to thank my Computer teacher Mr. M. Alsam for
his valuable guidance and help. He clarified all my queries
about the project without which I would have not been able to
complete the project. I would also like to thank my family for
providing all necessary materials and my friends for helping me
with this project.
Assignment programs :
Program 1 Write a program using Java language to calculate total number of
vowels and consonants present in the given string.

import java.util.*;

public class Read_string

public static void main (String args[])

Scanner sc = new Scanner(System.in);

System.out.println("Please enter a Word");

String word = sc.nextLine(); //to take input from user

int v = 0;

int c = 0;

int i = 0;

int l = word.length();

for(i=0; i<l; i++)

char ch = word.charAt(i);

switch(ch)

case 'a':

case 'e':

case 'i':

case 'o':

case 'u':

v++; //will add 1 to variable ‘v’ if the letter is a vowel


break;

default : c++; //will add 1 to variable ‘c’ if the letter is a consonant

System.out.println("There are " +v +" vowels and " +c +" consonants in " +word);

The Variable Description Table for Program 1


Sr. No. Variable Name Variable Type Purpose
1 word String To store the word given
2 v Integer To store the number of vowels
3 c Integer To store the number of consonants
4 i Integer To iterate the loop
5 l Integer To get the length of the word
To test each letter of the word
6 ch character
separately
Program 2 Write a program using Java language to display the given string
in the vertical manner.

import java.util.Scanner;
public class Vertical
{
public static void main(String args[])
{
Scanner sc = new Scanner(System.in);
System.out.println("Enter the word ");
String word = sc.nextLine(); //to input the word given by the user
int i; //to iterate the for loop
int l= word.length(); //to indicate the no. of letters in the word
word = word.toUpperCase(); //to change the letters to Uppercase
for(i=0; i<l; i++)
{
System.out.println("\t"+word.charAt(i)); //to print each letter of the word
}
}
}

The Variable Description Table for Program 2


Sr. No. Variable Name Variable Type Purpose
1 i Integer To iterate the loop
2 word String To get input from the user
3 l Integer To get the number of letters in the word
Program 3 Write a program using Java language to input the marks in Computer
Applications of a student out of 100 and then generate a suitable grade
obtained by him as per the given criteria:
Note: Use switch…case statement.
Percentage of Marks Obtained Grade
75 to 100 A
60 to 74 B
40 to 59 C
Less than 40 D

import java.util.Scanner;
public class Grade
{
public static void main(String args[])
{
Scanner sc = new Scanner(System.in);
System.out.println("Enter the marks obtained in Computer Applications (out of 100): ");
int marks = sc.nextInt();
int percentage = marks; //since they are out of 100
char grade;
switch (percentage / 5) //switch expression
{
//case statements
case 20:
case 19:
case 18:
case 17:
case 16:
case 15:
grade = 'A';
break;
case 14:
case 13 :
case 12:
grade = 'B';
break;
case 11:
case 10:
case 9 :
case 8 :
grade = 'C';
break;
default: grade = 'D'; //will print D grade if marks are less than 40
break;
}
System.out.println("Grade obtained: " + grade);
}
}

The Variable Description Table for Program 3


Sr. No. Variable Name Variable Type Purpose

1 marks Integer To read and store the marks obtained

2 percentage Integer To store the percentage of the marks

3 grade Character To store the Grade obtained


Program 4 Write a program using Java language to generate a menu driven
program to calculate the sum, product and average of three random
numbers according to the choice entered by the user of this program.

import java.util.Scanner;
public class Calculator
{
public static void main(String args[])
{
Scanner sc = new Scanner(System.in);
int num1 = sc.nextInt(); // First random number
int num2 = sc.nextInt(): // Second random number
int num3 = sc.nextInt(); // Third random number
int choice;
do
{
System.out.println("Menu:"); // Display the menu
System.out.println("1. Calculate Sum");
System.out.println("2. Calculate Product");
System.out.println("3. Calculate Average");
System.out.println("4. Exit");
System.out.print("Enter your choice: ");
choice = scanner.nextInt();
switch (choice)
{
case 1: int sum = num1 + num2 + num3; //to calculate the sum
System.out.println("Sum: " + sum);
break;
case 2: int product = num1 * num2 * num3; //to calculate the product
System.out.println("Product: " + product);
break;
case 3: double average = (num1 + num2 + num3) / 3.0;
//to calculate the average
System.out.println("Average: " + average);
break;
case 4: System.out.println("Exiting the program.");
break;
default : System.out.println("Invalid choice. Please enter a valid option.");
break;
}
}
while (choice != 4);
}
}

The Variable Description Table for Program 4


Sr. No. Variable Name Variable Type Purpose
1 num1 Integer To get 1st random number.

2 num2 Integer To get 2nd random number.

3 num3 Integer To get 3rd random number.

4 choice Integer To get input from user

5 sum Integer To get the sum of the numbers

6 product Integer To get the product of the numbers

7 average Double To get the average of the numbers


Program 5 Write a program using Java language to verify whether the entered
number is divisible by 8 or not. Display an appropriate message. The
program must stop when the number 0 is entered from the keyboard.
import java.util.Scanner;
public class Divisibility
{
public static void main(String args[])
{
Scanner sc = new Scanner(System.in);
System.out.println("Enter a number (0 to exit): ");
int num = sc.nextInt();
if (num == 0)
{
System.out.println("Exiting the program");
System.exit(0);
}
else if (num % 8 == 0)
{
System.out.println(num + " is divisible by 8.");
}
else
{
System.out.println(num + " is not divisible by 8.");
}
}
}

The Variable Description Table for Program 5


Sr. No. Variable Name Variable Type Purpose
1 num Integer To read and store the number
Program 6 Write a program using Java language to display the weekdays as per
the numbers entered from the keyboard. The entered numbers should
be between 1 and 7.
(Note: 1 represents Sunday)
Note: Use switch–case statement.

import java.util.*;

public class Day

public static void main(String args[])

Scanner sc = new Scanner (System.in);

System.out.println("Please input a number(1 to 7) to print the day of the week");

int number = sc.nextInt();

switch(number)//Switch expression

//Case statements

case 1: System.out.println("Sunday");

break;

case 2: System.out.println("Monday");

break;

case 3: System.out.println("Tuesday");

break;
case 4: System.out.println("Wednesday");

break;

case 5: System.out.println("Thursday");

break;

case 6: System.out.println("Friday");

break;

case 7: System.out.println("Saturday");

break;

//Default case statement

default : System.out.println("Not a valid day number");

The Variable Description Table for Program 6


Sr. No. Variable Name Variable Type Purpose

1 number Integer It will store the day number


Program 7 Write a program using Java language to print the following pattern:

55555
4444
333
22
1

public class Pattern7


{
public static void main (String args[])
{
int i, j;
for(i=5; i>=1; i--) //outer loop to print each row
{
for(j=1; j<=i; j++) // inner loop to print each number
{
System.out.print(i +" ");
}
System.out.println(); //moves cursor to the next line
}
}
}

The Variable Description Table for Program 7


Sr. No. Variable Name Variable Type Purpose
To iterate the outer loop and get the
1 i Integer
number to be printed
2 j Integer To iterate the inner loop
Program 8 Write a program using Java language to enter a string and check
whether it is a Palindrome or not. ( “ RADAR” is a palindrome string
as the reverse of this string is same as the original string)

import java.util.Scanner;

public class Palindrome

public static void main (String args[])

Scanner sc = new Scanner(System.in);

System.out.println("Please enter a Word to check");

String word = sc.nextLine(); //to take the input

String rev = "";

word = word.toUpperCase(); //to change the word to upper case

int i = 0;

int l = word.length();

for(i=l-1; i>=0; i--)

rev = rev + word.charAt(i); //to get the reversed word

if (word.equals(rev)) //to check the Strings to be same

System.out.println("The given word " +word +" is a palindrome");

else

System.out.println("The given word " +word +" is not a palindrome");


}

The Variable Description Table for Program 8


Sr. No. Variable Name Variable Type Purpose
1 word String To store the input word from the user

2 rev String To store the reverse of the word given

3 l Integer To store the length of the word

4 i Interger To iterate the for loop


Program 9 Write a program using Java language to generate first ten numbers of
a Fibonacci series. Example: 0, 1, 1, 2, 3, 5...

public class Fibonacci

public static void main (String args[])

int i, a=0, b=0, c=1;

System.out.println("The fibonacci series is :");

System.out.print(+b +" " +c); //to print the first two digits

for(i=1; i<=8; i++)

a=b; //to make the second no. the first

b=c; // to make the third no. the second

c=(a+b); // to store the fibonacci no.

System.out.print(" " +c);

The Variable Description Table for Program 9


Sr. No. Variable Name Variable Type Purpose
1 i Integer To iterate the ‘for’ loop
2 a Integer To store the first number

3 b Integer To store the second number

4 c Integer To store the Fibonacci number


Program 10 Write a program using Java language to generate the factorial of
a given number. (Factorial of 3 means = 1*2*3 )

import java.util.*;

public class Factorial

public static void main (String args[])

Scanner scan = new Scanner (System.in);

System.out.println("Enter any Natural No.");

int num = scan.nextInt(); //to take input from the user

int fac = 1; //to store the factorial

int i;

for (i=1; i<=num; i++)

fac = fac*i; // generates the factorial of the number

System.out.println("The factorial of " +num +" is " +fac);

The Variable Description Table for Program 10


Sr. No. Variable Name Variable Type Purpose
To iterate the loop and help generate the
1 i Integer
factorial

To generate and store the factorial of the


2 fac Integer
number
Program 11 Define a class Student described as below
Data members / instance variables: Name, age, m1, m2, m3 (marks in 5 subjects),
maximum, average
Member Methods: (i) A parameterized constructor to initialize the data members
(ii) To accept the details of a student
(iii) To compute the average and the maximum out of five numbers
(iv) To display the name, age, marks in five subjects, maximum and average
Write main method to create an object of a class and call the above member
method.

import java.util.Scanner;
public class Student
{
private String name;
private int age;
private int m1, m2, m3;
private int maximum;
private double average;

public Student(String n, int a, int s1, int s2, int s3)


{
name = n;
age = a;
m1 = s1;
m2 = s2;
m3 = s3;
}

public Student() //This method initializes the variables


{
name = "";
age = 0;
m1 = 0;
m2 = 0;
m3 = 0;
maximum = 0;
average = 0;
}

public void accept() //This method accepts the details of a student.


{
Scanner sc = new Scanner(System.in);
System.out.print("Enter name: ");
name = sc.nextLine();
System.out.print("Enter age: ");
age = sc.nextInt();
System.out.print("Enter Subject 1 Marks: ");
m1 = sc.nextInt();
System.out.print("Enter Subject 2 Marks: ");
m2 = sc.nextInt();
System.out.print("Enter Subject 3 Marks: ");
m3 = sc.nextInt();
}

public void compute() //This method computes the average and the maximum
out of three numbers
{
maximum = Math.max(m1, Math.max(m2, m3)); //calculates the maximum of
the three no.s
average = (m1 + m2 + m3) / 3.0;
}

public void display()


//This method displays the name, age, marks in five subjects, maximum and
average.
{
System.out.println("Name: " + name);
System.out.println("Age: " + age);
System.out.println("Subject 1 Marks: " + m1);
System.out.println("Subject 2 Marks: " + m2);
System.out.println("Subject 3 Marks: " + m3);
System.out.println("Maximum Marks: " + maximum);
System.out.println("Average Marks: " + average);
}

public static void main(String args[])


{
Student obj1 = new Student();
obj1.accept();
obj1.compute();
obj1.display();
}
}

The Variable Description Table for Program 11


Sr. No. Variable Name Variable Type Purpose
1 name String Stores the name of the student

2 age Integer Stores the age of the student

3 m1 Integer Stores the marks in Subject 1

4 m2 Integer Stores the marks in Subject 1

5 m3 Integer Stores the marks in Subject 1


Stores the maximum marks of the
6 maximum Integer
student
7 average Double Stores the average of the marks
Program 12 Write a program using Java language to input 10 numbers in an
array and then count the total number of odd and even numbers.
Print the even and odd numbers with an appropriate message.

import java.util.Scanner;
public class EvenOdd
{
public static void main(String args[])
{
Scanner sc = new Scanner(System.in);
int[] numbers = new int[10];
int evenCount = 0;
int oddCount = 0;

System.out.println("Enter 10 numbers:");
for (int i = 0; i < 10; i++)
{
numbers[i] = sc.nextInt(); //takes 10 different numbers
}

System.out.println("Even numbers:");
for (int i = 0; i < 10; i++)
{
if (numbers[i] % 2 == 0) //checks whether number is even or not
{
System.out.println(numbers[i]);
evenCount++; //calculates the amount of even numbers
}
}
System.out.println("Total even numbers: " + evenCount);

System.out.println("Odd numbers:");
for (int i = 0; i < 10; i++)
{
if (numbers[i] % 2 != 0) //checks whether number is odd or not
{
System.out.println(numbers[i]);
oddCount++; //calculates the amount of odd numbers
}
}
System.out.println("Total odd numbers: " + oddCount);
}
}

The Variable Description Table for Program 12


Sr. No. Variable Name Variable Type Purpose
To read and store the numbers given by
1 Numbers Integer
the user
2 oddCount Integer To count the odd numbers

3 evenCount Integer To count the even numbers


Program 13 Write a program using Java language to create an array to store 20
numbers and print the largest integer and the smallest number in
the array.

import java.util.*;

public class Arr

public static void main(String args[])

Scanner sc = new Scanner (System.in);

int[] num = new int[20]; // Create an array to store 20 numbers

int i = 0;

for (i = 0; i < 20; i++) //Initialize the array

num[i] = sc.nextInt(); // Fill array with numbers from user input

int largest = num[i];

int smallest = num[i]; // Initialize variables to store the largest and smallest
numbers

for (i = 0; i < 20; i++) // Find the largest and smallest numbers in the array

if (num[i] > largest)

largest = num[i];

if (num[i] < smallest)

smallest = num[i];
}

System.out.println("Largest number in the array : " + largest);

// Print the largest and smallest numbers

System.out.println("Smallest number in the array : " + smallest);

The Variable Description Table for Program 13


Sr. No. Variable Name Variable Type Purpose
1 num Integer To store the numbers given by the user

2 i Integer To iterate the ‘for’ loops

3 largest Integer To find and store the largest no. in the array

To find and store the smallest no. in the


4 smallest Integer
array
Program 14 Define a class employee having the following description:

Data members / instance variables:


int pan to store personal account number
String name to store name
double taxincome to store annual taxable income
double tax to store tax that is calculated

Member functions: Input( ) store the pan number, name, taxable income
calc( ) calculate tax for an employee
display( ) output details of an employee

Write a program using Java language to compute the tax according to the given
conditions and display the output as per given format:

Total Annual Taxable Income Tax Rate

Upto Rs. 3 lac No tax


From 4,00,001 – 7,00,000 10% of the income exceeding Rs. 3 lac
From 7,00,001 – 8,00,000 15% of the income exceeding Rs. 7,00,000
Above Rs. 8,00,000 Rs. 10,000 + 20% of the income exceeding Rs.
8,00,000

Output: Pan Number Name Tax-income Tax


_________ _____ _________ ___

import java.util.Scanner;

public class Employee


{
private int pan;
private String name;
private double taxincome;
private double tax;
void input() // Method to input employee details
{
Scanner sc = new Scanner(System.in);
System.out.println("Enter PAN number: ");
pan = sc.nextInt();
System.out.println("Enter name: ");
name = sc.nextLine();
System.out.println("Enter taxable income: ");
taxincome = sc.nextDouble();
}

void calc() // Method to calculate tax based on income


{
if (taxincome <= 300000)
{
tax = 0;
} else if (taxincome <= 700000) {
tax = (10/100) * (taxincome - 300000);
} else if (taxincome <= 800000) {
tax = (10/100) * (700000 - 300000) + (15/100) * (taxincome - 700000);
} else {
tax = 10000 + 0.2 * (taxincome - 800000);
}
}

void display() // Method to display employee details and tax


{
System.out.println("Pan Number\tName\tTax-income\tTax");
System.out.println("_________\t_____\t___________\t___");
System.out.println(pan + "\t" + name + "\t" + taxincome + "\t" + tax);
}

public static void main(String args[])


{
Employee obj1 = new Employee(); // Create an instance of Employee
obj1.input(); // Call input method to get employee details
obj1.calc(); // Calculate tax using calc method
obj1.display(); // Display employee details and tax
}
}

The Variable Description Table for Program 14


Sr. No. Variable Name Variable Type Purpose
1 pan String To store the personal account number

2 name Integer To store the name of the employee

To store the taxable income of the


3 taxincome Integer
employee

To calculate and store the tax


4 tax Integer
accountable
Program 15 Write a program using Java language to input a string and then
display it in the reverse order.
Example: Input = “HELLO” Output = “OLLEH

import java.util.Scanner;
public class Reverse
{
public static void main (String args[])
{
Scanner sc = new Scanner(System.in);
System.out.println("Please enter a Word");
String word = sc.nextLine(); //to take the input
String rev = "";
word = word.toUpperCase(); //to change the word to upper case
int i = 0;
int l = word.length();
for(i=l-1; i>=0; i--)
{
rev = rev + word.charAt(i); //to get the reversed word
}
System.out.println("The reversed word : " +rev);
}
}

The Variable Description Table for Program 15


Sr. No. Variable Name Variable Type Purpose
1 word String To store the input word from the user
2 rev String To store the reverse of the word given
3 l Integer To store the length of the word
4 i Integer To iterate the for loop
Program 16 Write a program using Java language to display the sum of the
squares of first ten odd numbers.

public class Square

public static void main(String args[])

int sum = 0; // Initialize the variable to store the sum

for (int i =1; i<20; i+=2) // Increment i by 2 to get the next odd number

int square = i * i; // Calculate the square of the current odd number

sum = sum + square; // Add the square to the sum

System.out.println("Sum of the squares of the first ten odd numbers is : " + sum);

The Variable Description Table for Program 16


Sr. No. Variable Name Variable Type Purpose
1 sum Integer To store the sum of the squares
To calculate and store the square of the
2 square Integer
number
Program 17 Write a program using Java language to input a string and the replace
all the vowels of this string with ‘Z’.
(Entered string = “GOOD”; Modified string = “GZZD”)

import java.util.Scanner;

public class Replace

public static void main(String args[])

Scanner sc = new Scanner(System.in);

System.out.println("Enter a string: ");

String str = sc.nextLine(); //take input from user

String modifiedstr = str.replaceAll("[aeiouAEIOU]", "Z");

// replaceAll method of string class replaces all vowels with Z

System.out.println("Modified string: " + modifiedstr); // print the modified string

The Variable Description Table for Program 17


Sr. No. Variable Name Variable Type Purpose
1 str String To get the word from the user

2 modifiedstr String To store the modified word


Program 18 Write a program using Java language to input a string and then
display the total number of words in this string.

import java.util.Scanner;

public class WordCount

public static void main(String[] args)

Scanner sc = new Scanner(System.in);

System.out.println("Enter a string: ");

String str = sc.nextLine(); // take input from the


user

int wordCount = str.split("\\s+").length;

// Split the input string into words using spaces as delimiters and return the count of
words

System.out.println("Total number of words: " + wordCount); //display the


wordcount

The Variable Description Table for Program 18


Sr. No. Variable Name Variable Type Purpose
1 str String To get the word from the user
To store the number of words in the
2 wordCount Int
String
Program 19 Write a program using Java language to look for number 7 in an array of 10
numbers. Also count how many times it occurs in the array.

import java.util.Scanner;
public class SevenCount
{
public static void main(String args[])
{
Scanner sc = new Scanner(System.in);
int[] arr = new int[10]; // Declare an array to store 10 numbers
int count = 0;
System.out.println("Enter 10 numbers:");
for (int i = 0; i < arr.length; i++) //reads input from the user
{
arr[i] = sc.nextInt();
if (arr[i] == 7)
{
count++; // to count the occurrences of the number in an array
}
}

The Variable Description Table for Program 19


Sr. No. Variable Name Variable Type Purpose
1 arr Integer To get the numbers from the user
2 count Integer To store the frequency of number 7
3 i Integer To iterate the for loop
System.out.println("The number 7 occurs " + count + " times in the array.");
}
}

Program 20 Write a program using Java language to convert the given decimal number
into binary number.

import java.util.Scanner;

public class Binary

public static void main(String args[])

Scanner sc = new Scanner(System.in);

System.out.print("Enter a decimal number: ");

int decimal = sc.nextInt(); //get the decimal number from the user

String binary = Integer.toBinaryString(decimal);

// toBinaryString() method of the Integer class converts the decimal number to


binary

System.out.println("Binary equivalent: " + binary);

The Variable Description Table for Program 20


Sr. No. Variable Name Variable Type Purpose
To store the decimal number given by
1 decimal Integer
user
To store the binary number in string
2 binary String
format
S. NO. TITLE PAGE NO.

Write a program using Java language to calculate total number of vowels and 1-2
1.
consonants present in the given string.

Write a program using Java language to display the given string in the vertical
2. 3
manner.

Write a program using Java language to input the marks in Computer


3. Applications of a student out of 100 and then generate a suitable grade 4-5
obtained by him.

Write a program using Java language to generate a menu driven program to


4. calculate the sum, product and average of three random numbers according to 6-7
the choice entered by the user of this program

Write a program using Java language to verify whether the entered number is
5. divisible by 8 or not. Display an appropriate message. The program must stop 8
when the number 0 is entered from the keyboard.

Write a program using Java language to display the weekdays as per the
6. numbers entered from the keyboard. The entered numbers should be between 9-10
1and 7.

7. Write a program using Java language to print pattern. 11

Write a program using Java language to enter a string and check whether it is a
8. 12-13
Palindrome or not.

Write a program using Java language to generate first ten numbers of a


9. 14
Fibonacci series.

Write a program using Java language to generate the factorial of a given


10. 15
number.

11. Write a java program to generate a student’s report card. 16-18

Write a program using Java language to create an array to store 20 numbers


12. 19-20
and print the largest integer and the smallest number in the array.
13. Write a program using Java language to compute income tax. 21-22

14. 23-25
Write a program using Java language to input a string and then display it in the
reverse order.

15. 26
Write a program using Java language to display the sum of the squares of first
ten odd numbers.

16. 27
Write a program using Java language to display the sum of the squares of first
ten odd numbers.

17. 28
Write a program using Java language to input a string and the replace all the
vowels of this string with ‘Z’.

18. 29
Write a program using Java language to input a string and then display the
total number of words in this string.

19. 30
Write a program using Java language to look for number 7 in an array of 10
numbers. Also count how many times it occurs in the array.

20. 31
Write a program using Java language to convert the given decimal number
into binary number.

You might also like