Professional Documents
Culture Documents
Computer Project Class 10 Term1
Computer Project Class 10 Term1
CODE:
public class q1
{
double volume(double r) {
double vol = (4 / 3.0) * (22 / 7.0) * r * r * r;
return vol;
}
VDT:-
ALGORITHM:
1. Start
2. Initialize class
3. Overloading function ‘volume’
4. Finding volume of different shapes in the function
5. Initializing main method
6. Calling each function and entering values
7. Showing required answer
8. Stop
2. Write a program to accept name and total marks of N number of students in two
single subscript array name[] and totalmarks[ ].
Calculate and print:
(i) The average of the total marks obtained by N Number of students.
[average = (sum of total marks of all the students)/N]
(ii) Deviation of each student’s total marks with the average.
[deviation = total marks of a student – average]
CODE:
import java.util.Scanner;
public class q2
{
public static void main(String args[]) {
Scanner in = new Scanner(System.in);
System.out.print("Enter number of students: ");
int n = in.nextInt();9
VDT:
CODE:
import java.util.Scanner;
public class q3
{
public long fact(int n) {
long f = 1;
for (int i = 1; i <= n; i++) {
f *= i;
}
return f;
}
public static void main(String args[]) {
q3 obj = new q3();
Scanner in = new Scanner(System.in);
System.out.print("Enter m: ");
int m = in.nextInt();
System.out.print("Enter n: ");
int n = in.nextInt();
double s = (double)(obj.fact(n)) / (obj.fact(m) * obj.fact(n - m));
System.out.println("S=" + s);
}
}
OUTPUT:-
VDT:
VARIABLE DATATYPE FUNCTION
m int Store a value
ALGORITHM:
1. Start
2. Define function fact ( n)
3. f <- 1,i<-1
4. If i<=n then goto line 5 otherwise line
5. f*=i
6. i<-i+1 goto line 4
7. Return f
8. End function fact()
9. Accept m
10. Accept n
11. s<-fact(n)/(fact(m)*fact(n-m))
12. Display s
13. Stop
CODE:
import java.util.Scanner;
public class q4
{
public static void main(String args[]) {
Scanner in = new Scanner(System.in);
int arr[] = new int[20];
System.out.println("Enter 20 numbers:");
for (int i = 0; i < 20; i++) {
arr[i] = in.nextInt();
}
int min = arr[0], max = arr[0], sum = 0;
for (int i = 0; i < arr.length; i++) {
if (arr[i] < min)
min = arr[i];
sum += arr[i];
}
VDT:
5. Write a program to input and store roll numbers, names and marks in
3 subjects of n
number students in five single dimensional array and display the remark
based on
average marks as given below :
(The maximum marks in the subject are 100)
CODE:
import java.util.Scanner;
public class q5
{
public static void main(String args[]) {
OUTPUT:-
VDT:
ALGORITHM:
1. Start
2. Define n and enter the value of the no of students.
3. Declare rollNo[n],name[n],s1[n],s2[n],s3[n], avg[n].
4. i<-0
5. If i<n then goto line 5 otherwise line 9
6. Accept rollNo[i], name[i], s1[i], s2[i], s3[i]
7. avg[i]<-(s1[i]+s2[i]+s3[i])/3
8. i<-i+1. Go to 5
9. i<-0
10. If i<n go to line 11 otherwise line 16
11. If avg[i] <40 print rollno[i], name[i], “poor”
12. Else if avg[i]<60 print rollno[i], name[i], ,”pass”
13. Else if avg[i]<-75 print rollno[i], name[i], “First Class”
14. Else if avg[i]<85 print rollno[i], name[i], “Distinction”
15. Else print rollno[i], name[i], “excellent”
16. i<-i+1 goto 10
17. end
CODE:
import java.util.Scanner;
public class q6
{
public static void main(String args[])
{
Scanner in = new Scanner(System.in);
int arr[] = new int[20];
System.out.println("Enter 20 numbers");
for (int i = 0; i < arr.length; i++) {
arr[i] = in.nextInt();
}
int oddSum = 0, evenSum = 0;
for (int i = 0; i < arr.length; i++) {
if (arr[i] % 2 == 0)
evenSum += arr[i];
else
oddSum += arr[i];
}
System.out.println("Sum of Odd numbers = " + oddSum);
System.out.println("Sum of Even numbers = " + evenSum);
}
}
OUTPUT:-
VDT:
ALGORITHM:
1. Start
2. Define class
3. Define function main()
4. even<-0
5. odd<-0
6. Display enter 20 no.s
7. i<-0
8. a[i] <-accept no.
9. i<-i+1.
10. Repeat steps 8 to 9 till i <20
11. i<-0
12. if(a[i] mod 2==0)
13. even<-even+a[i]
14. else
15. odd<-odd+a[i]
16. i<-i+1
17. repeat steps 12 to 16 till i<20
18. end if
19. display even
20. display odd
21. End main
22. End class
23. Stop
CODE:
import java.util.Scanner;
public class Hcflcm
{
int a , b ;
public Hcflcm(int x, int y) {
a = x;
b = y;
}
public void calculate() {
int x = a, y = b;
while (y != 0) {
int t = y;
y = x % y;
x = t;
}
int hcf = x;
int lcm = (a * b) / hcf;
System.out.println("HCF = " + hcf);
System.out.println("LCM = " + lcm);
}
public static void main(String args[]) {
Scanner in = new Scanner(System.in);
System.out.print("Enter first number: ");
int x = in.nextInt();
System.out.print("Enter second number: ");
int y = in.nextInt();
Hcflcm obj = new q7(x,y);
obj.calculate();
}
}
OUTPUT:-
VDT:
ALGORITHM:
1. Start
2. Define class Hcflcm
3. Declare int a and b
4. Create constructor Hcflcm(int x , int y)
5. a<-x , b<-y.
6. End constructor Hcflm.
7. Define function calculate()
8. x<-a , y<-b
9. If y<>0 then go to 10 otherwise goto 13
10. t<-y
11. y<-x%y
12. x<-t goto 9
13. Display x as “HCF”
14. Display (a*b)/x as “LCM”
15. End function calculate()
16. Define main
17. Declare x1,y1
18. Input x1,y1
19. Send values to constructor Hcflcm.
20. Call function calculate()
21. Stop
CODE:
import java.util.Scanner;
public class Calculate
{
private int num;
private int f;
private int rev;
public Calculate(int n) {
num = n;
f = 0;
rev = 0;
}
public int prime() {
f = 1;
if (num == 0 || num == 1)
f = 0;
else
for (int i = 2; i <= num / 2; i++) {
if (num % i == 0) {
f = 0;
break;
}
}
return f;
}
public int reverse() {
int t = num;
while (t != 0) {
int digit = t % 10;
rev = rev * 10 + digit;
t /= 10;
}
return rev;
}
public void display() {
if (f == 1 && rev == num)
System.out.println(num + " is prime palindrome");
else
System.out.println(num + " is not prime palindrome");
}
ALGORITHM:
1. Start
2. Import scanner
3. Declare class Calculate
4. Define int num,f,rev
5. New constructor Calculate(int n)
6. declare these h=n,f=0,rev=0
7. End Calculate()
8. New function prime()
9. Calculate and return 1 if number is prime
10. End function prime().
11. New function reverse()
12. Find the reverse of num.
13. End function reverse()
14. New function display()
15. if f=1 and rev =num then print ‘prime palindrome else print ‘not prime
palindrome’.
16. End function display()
17. New main
18. Scanner in
19. Declare x ––
20. Input x
21. Send x to Calculate()
22. Call other functions.
23. End
OUTPUT:-
VDT:
ALGORITHM:
1. Start
2. Import scanner
3. Declare class
4. Define String name , double price , amt , dis.
5. New constructor Laptop(String name , double p)
6. declare these name = n; price = p; dis=0.0; amt=0.0;
7. End Laptop()
8. New function Compute()
9. Calculate the discount and the amount
10. End function Compute().
11. New function Display()
12. To print the values
13. End functionDisplay()
14. New main
15. Scanner in
16. Take the inputs
17. Send n1,p1 to Laptop()
18. Call other functions.
19. End
10. A special two-digit number is such that when the sum of its digits
is added to the
product of its digits, the result is equal to the original two-digit
number. Example:
Consider the number 59.
Sum of digits = 5 + 9=14
Product of its digits = 5 x 9 = 45
Sum of the sum of digits and product of digits = 14 + 45 = 59
Write a program to accept a two-digit number. Add the sum of its digits
to the
product of its digits. If the value is equal to the number input,
output the message
“Special 2-digit number” otherwise, output the message “Not a special
2-digit number”.
CODE:
import java.util.Scanner;
public class q10
{
public void checkNumber() {
Scanner in = new Scanner(System.in);
System.out.print("Enter a 2 digit number: ");
int orgNum = in.nextInt();
int num = orgNum;
int count = 0, digitSum = 0, digitProduct = 1;
while (num != 0) {
int digit = num % 10;
num /= 10;
digitSum += digit;
digitProduct *= digit;
count++; }
if (count != 2)
System.out.println("Invalid input, please enter a 2-digit number");
else if ((digitSum + digitProduct) == orgNum)
System.out.println("Special 2-digit number");
else
System.out.println("Not a special 2-digit number");
}
}
OUTPUT:-
VDT:
ALGORITHM:
1. Start Initialize class
2. Take number(2-digit)
5. Counting length
CODE:
import java.util.Scanner;
public class q11
{
double area(double a, double b, double c) {
double s = (a + b + c) / 2;
double x = s * (s-a) * (s-b) * (s-c);
double result = Math.sqrt(x);
return result;
}
double area (double a, double b, double height) {
double result = (1.0 / 2.0) * height * (a + b);
return result;
}
double area (double diagonal1, double diagonal2) {
double result = 1.0 / 2.0 * diagonal1 * diagonal2;
return result;}
}
OUTPUT:-
VDT:
ALGORITHM:
1. Start
5. Stop
12. Using the switch statement, write a menu driven program to calculate the
maturity amount of a Bank Deposit.
The user is given the following options:
1. Term Deposit
2. Recurring Deposit
For option 1, accept principal (P), rate of interest(r) and time period in
years(n). Calculate and output the maturity amount(A) receivable using
the formula:
A = P[1 + r / 100]n
For option 2, accept Monthly Installment (P), rate of interest (r) and
time period in months (n). Calculate and output the maturity amount
(A) receivable using the formula:
A = P x n + P x (n(n+1) / 2) x r / 100 x 1 / 12
For an incorrect option, an appropriate error message should be
displayed.
CODE:
import java.util.Scanner;
public class q12
{
public static void main(String args[]) {
Scanner in = new Scanner(System.in);
System.out.println("Type 1 for Term Deposit");
System.out.println("Type 2 for Recurring Deposit");
System.out.print("Enter your choice: ");
int ch = in.nextInt();
double p = 0.0, r = 0.0, a = 0.0;
int n = 0;
switch (ch) {
case 1:
System.out.print("Enter Principal: ");
p = in.nextDouble();
System.out.print("Enter Interest Rate: ");
r = in.nextDouble();
System.out.print("Enter time in years: ");
n = in.nextInt();
a = p * Math.pow(1 + r / 100, n);
System.out.println("Maturity amount = " + a);
break;
case 2:
System.out.print("Enter Monthly Installment: ");
p = in.nextDouble();
System.out.print("Enter Interest Rate: ");
r = in.nextDouble();
System.out.print("Enter time in months: ");
n = in.nextInt();
a = p * n + p * ((n * (n + 1)) / 2) * (r / 100) * (1 / 12.0);
System.out.println("Maturity amount = " + a);
break;
default:
System.out.println("Invalid choice");
}
}
}
OUTPUT
VDT:
ALGORITHM:
1. START
2. INITIALIZE CLASS
3. MAIN METHOD
4. TAKING INPUT
7. RETURNING ANSWER
8. END
13. Write a program to accept the year of graduation from school as an integer value
from, the user. Using the Binary Search technique on the sorted array of integers
given below.
Output the message “Record exists” If the value input is located in the array. If not,
output the message “Record does not exist”.{1982, 1987, 1993, 1996. 1999, 2003,
2006, 2007, 2009, 2010}
CODE:
import java.util.Scanner;
public class q13
{
public static void main() {
Scanner sc = new Scanner(System.in);
int n[] = {1982, 1987, 1993, 1996, 1999, 2003, 2006, 2007, 2009, 2010};
System.out.print("Enter graduation year to search: ");
int year = sc.nextInt();
int l = 0, h = n.length - 1, idx = -1;
while (l <= h) {
int m = (l + h) / 2;
if (n[m] == year) {
idx = m;
break;
}
else if (n[m] < year) {
l = m + 1;
}
else {
h = m - 1;
}
}
if (idx == -1)
System.out.println("Record does not exist");
else
System.out.println("Record exists");
}
}
OUTPUT:
VDT:
ALGORITHM:
1. Start
2. Define class
3. Define function main()
4. lb=0;
5. k=0
6. p=0
7. ub=0
8. i=0
9. display enter number in the cell.
10. m[i]sc.nextInt();
11. i=i+1.
12. Repeat steps 6 and 7 till i<10.
13. Display enter no. to be searched
14. nsaccept no.
15. p(lb+ub)/2
16. if(m[p]>ns)
17. ubp-1.
18. If(m[p]<ns)
19. lbp+1.
20. If(m[p]==ns)
21. K=1.
22. Break the program.
23. End if for line 18.
24. Repeat steps 15 to 21 till lb<=ub.
25. If(k==1)
26. Display record exists
27. Else
28. Display record does not exist
29. End if
30. End main
31. End class
32. Stop
14. Define a class named Fruit Juice with the following description:
Instance variables / data members :
int product_code — stores the product code number
String flavour — stores the flavour of the juice (E.g. orange, apple,
etc.)
String pack_type — stores the type of packaging (E.g. tetra-pack, PET
bottle, etc.)
int pack_size — stores package size (E.g. 200 ml, 400 ml, etc.)
int product_price — stores the price of the product
Member methods :
(i) FruitJuice() — Default constructor to initialize integer data
members to 0 and
String data members to “ ”.
(ii) void input( ) — To input and store the product code, flavour, pack
type, pack
size and product price.
(iii) void discount( ) — To reduce the product price by 10.
(iv) void display() — To display the product code, flavour, pack type,
pack size
and product price.
CODE:
import java.util.Scanner;
public class FruitJuice
{
int product_code;
String flavour;
String pack_type;
int pack_size;
int product_price;
public FruitJuice() {
product_code = 0;
flavour = "";
pack_type = "";
pack_size = 0;
product_price = 0;
}
OUTPUT:
VDT:
ALGORITHM:
1. Start
2. Initialize class
3. Taking inputs
6. Returning bill
7. Stop
15. A tech number has even number of digits. If the number is split in
two equal halves,
then the square of sum of these halves is equal to the number itself.
Write a program to
generate and print all four digits tech numbers.
Example
Consider the number : 3025
Square of sum of the halves of 3025=(30+25)2= (55)2
=3025 is a tech number.
CODE:
public class q15
{
public static void main(String args[]) {
for (int i = 1000; i <= 9999; i++) {
int secondHalf = i % 100;
int firstHalf = i / 100;
int sum = firstHalf + secondHalf;
if (i == sum * sum)
System.out.println(i);
}
}
}
OUTPUT:
VDT:
ALGORITHM:
1. Start
2. Initialize class
6. Returning result
7. Stop