COMPUTER PROJECT (Complete Combined)
COMPUTER PROJECT (Complete Combined)
COMPUTER SCIENCE
PROJECT
Principal’s Sign. -
School’s Stamp –
QUESTION
Write a program to declare a square
matrix A[][] of order M x M, where ‘M’ is
the number of rows and the number of
columns, such that M must be greater than
2 and less than 10. Accept the value of M
as user input. Allow the user to input
integers into the matrix. Perform the
following tasks:
1.) Display the original matrix.
2.) Rotate the matrix 90 degree
clockwise.
3.) Find the sum of the elements of
the four corners of the matrix.
ALGORITHM
__________________________________
__________________________________
import java.io.*;
import java.util.*;
import java.lang.*;
class rotateMatrix
{
int A[][], M, i, j;
Scanner sc=new Scanner(System.in);
void accept()
{
System.out.print(“Enter no. of rows:”);
M=sc.nextInt();
check();
}
void check
{
if (m<=2||m>10)
System.out.println (“Invalid Input.”);
else {
a = new int[M][M];
M--;
for(i=0; i<=M; i++)
{ for(j=0; j<=M; j++)
{ System.out.print(“Enter value:”);
A[i][j]=sc.nextInt();
} }
show();
} }
void show()
{
System.out.println (“The original Matrix:”);
for(i=0; i<=M; i++)
{ for(j=0; j<=M; j++)
{
System.out.print(“ ”+A[i][j]);
}
System.out.println (); }
System.out.println (“The matrix after rotation:”);
for(i=0; i<=M; i++)
{ for(j=0; j<=M; j++)
{
System.out.print(“ ”+A[M-j][i]);
}
System.out.println();
} }
public static void main()
{
rotateMatrix one=new rotateMatrix();
one.accept();
} }
OUTPUT
QUESTION
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
nar[x++]=arr[i][j];
}
}
for(i=0;i<x;i++)
{
for(j=0;j<x-1;j++)
{
if(nar[j]>nar[j+1])
{
temp=nar[j];
nar[j]=nar[j+1];
nar[j+1]=temp;
}
}
}
System.out.println("NEW OR SORTED ARRAY IS:");
System.out.println();
int a=0;
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
arr[i][j]=nar[a++];
System.out.print(arr[i][j]+" ");
}
System.out.println();
}
}
}
OUTPUT
QUESTION
Write a program to input a
sentence and print the NUMBER
OF WORDS in it and show that
how many words starts with
CAPITAL LETTER.
ALGORITHM
Step1: Start. .
Step2: In a constructor initialize the
frequency.
Step3: Take a sentence from user as an input.
Step4: Convert the sentence into an array.
Step5: Check for the white spaces in the
array.
Step6: Then check the next letter of the white
space.
Step7: Insert a white space in the starting.
Step8: At every white space it increases the
count by 1 i.e. each word is counted.
Step9: If the function : “boolean isCap(String
W)” returns true then frequency is increased
by 1 i.e. numder of letters starting with capital
letter.
Step10: 10. Print the result.
Step11: End.
import java.util.*;
import java.io.*;
import java.lang.*;
class StringProg
{
String sent;
int len, freq;
Scanner ob = new Scanner(System.in);
StringProg()
{
freq=0;
}
void input()
{
System.out.println("Enter a sentence");
sent=ob.nextLine();
}
boolean isCap(String W)
{
if(Character.isUpperCase(W.charAt(0))) return true;
else return false;
}
void display()
{
String z[]=sent.split(" ");
len = z.length;
for(int i=0;i<len;i++)
if(isCap(z[i])) freq++;
System.out.println("Sentence is "+ sent);
System.out.println("Frequency of Capital character is "+ freq);
}
public static void main(String arg[])
{
StringProg obj1 = new StringProg();
obj1.input();
obj1.display();
}
}
OUTPUT
QUESTION
Write a program to perform the
following tasks :
1) Input the size of 2 SQUARE
MATRIX.
2) In a new FUNCTION take
input of values of the 2 matrices.
3) In another function DISPLAY
the 2 matrices. 4) Do the
PRODUCT of 2 matrices
according to mathematical rules
and display it. (USE MAIN
FUNCTION ALSO.)
ALGORITHM
Step1: Start. .
Step2: Input size of 2 matrices.
Step3: Take the values of the matrices as a
user input.
Step4: Calculate the product of the 2 matrices
using:
• 1 st row * 1 st column.
• 2 nd row * 2 nd column.
• 2 nd row * 1st column.
• 2 nd row * 2nd column.
(AS PER THE SIZE OF THE MATRIX.)
Step5: Store the value in another matrix.
Step6: Print the matrix.
Step7: End.
import java.util.*;
class MATmultiply
{ int a[][], b[][], c[][];
int n,m;
int i,j,k;
Scanner ob = new Scanner(System.in);
MATmultiply(int mm, int nn)
{ m=mm;
n=nn;
a = new int[m][n];
b = new int[n][m];
c = new int[m][m]; }
void input()
{ System.out.print("Please enter values for first matrices ");
for(i=0;i<m;i++) //rows
for(j=0;j<n;j++) // columns
a[i][j]= ob.nextInt();
System.out.print("Please enter values for second matrices ");
for(i=0;i<n;i++) //rows
for(j=0;j<m;j++) // columns
b[i][j]= ob.nextInt(); }
void display()
{ System.out.println("Values for first matrices");
for(i=0;i<m;i++)
{ for(j=0;j<n;j++)
{ System.out.print(a[i][j]+"\t"); }
System.out.println(); }
System.out.println("Values for second matrices ");
for(i=0;i<n;i++) {
for(j=0;j<m;j++) {
System.out.print(b[i][j]+"\t"); }
System.out.println(); } }
void prod()
{ for(i=0;i<m;i++)
for(j=0;j<m;j++) {
for(k=0;k<n;k++)
c[i][j]= c[i][j] + a[i][k] * b[k][j]; }
System.out.println("Product of both matrices are ");
for(i=0;i<m;i++) {
for(j=0;j<m;j++) {
System.out.print(c[i][j]+"\t"); }
System.out.println(); } }
public static void main(String arg[]) {
MATmultiply obj= new MATmultiply(3,3);
obj.input();
obj.display();
obj.prod();
}
}
OUTPUT
QUESTION
DateNumber()
{
month=1;
day=0;
year=0;
}
void input()
{
System.out.println("Enter number of days from 1st January");
n=ob.nextInt();
System.out.println("Enter yyyy");
year=ob.nextInt();
}
void calc()
{
int arr[] =
{0,31,28,31,30,31,30,31,31,30,31,30,31};
if(year%4==0) arr[2]=29;
while(n>arr[month])
{
n=n-arr[month];
month++;
}
day=n;
System.out.println("Date in dd / mm / yyyy format is ");
System.out.println(day + "/" + month + "/" +
year);
}
Step1: Start.
Step2:Input name and days late.
Step3:Input type of book “M” for
Magazine & “T” for text book.
Step4:Using switch case check the type of
book.
Step5:Then check the category i.e. how
much fine per day has to imposed.
Step6:Total fine = fine per day*No. of
days.
Step7:Print the output.
Step8:Else display “invalid book type”.
Step9:End.
import java.util.Scanner;
public class fine
{
public static void main() {
Scanner in = new Scanner(System.in);
System.out.print("Enter name: ");
String name = in.nextLine();
System.out.print("Days late: ");
int days = in.nextInt();
System.out.println("Type M for Magazine");
System.out.println("Type T for Text book");
System.out.print("Enter book type: ");
char type = in.next().charAt(0);
int fine = 0;
switch (type) {
case 'M':
if (days <= 5)
fine = 1;
else if (days <= 10)
fine = 2;
else if (days <= 15)
fine = 3;
else if (days <= 20)
fine = 5;
else
fine = 6;
break;
case 'T':
if (days <= 5)
fine = 2;
else if (days <= 10)
fine = 3;
else if (days <= 15)
fine = 4;
else if (days <= 20)
fine = 6;
else
fine = 7;
break;
default:
System.out.println("Invalid book type");
}