0% found this document useful (0 votes)
3 views

Computer Applications

Uploaded by

sofiamadeena
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Computer Applications

Uploaded by

sofiamadeena
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 42

COMPUTER

APPLICATIONS
BOARD PROJECT 2024-
2025

NAME: SHAIK AAFREEN


CLASS:10
SECTION:A
ROLL NO.:24
SCHOOL:

INTERNAL EXAMINER EXTERNAL EXAMINER


ACKNOWLEDGEME
NTS:
Firstly, I extend my heartfelt thanks to my computer teacher, Ms.
Shilpa, whose dedication and guidance have inspired me to
explore the world of technology with curiosity and confidence.
Your patience and expertise have made a significant impact on
my learning.

I am also grateful to my coordinator, Ms. Anuradha, for your


unwavering support and encouragement. Your organizational
skills and leadership have helped me navigate my academic
challenges with ease.

A special thank you to my principal, Ms. Maneesha, for fostering


an environment of growth and learning. Your vision and
commitment to excellence have motivated me to strive for my
best.

Lastly, I want to express my deepest appreciation to my family


and friends. Your love, encouragement, and belief in me have
been my greatest source of strength. Thank you for always being
there, cheering me on through every step of my journey.
Q1. The coordinates of 2 points A and B on a straight line are given as
(x1,y1) and (x2,y2). Write a program to calculate the slope(m) of the line by
using formula :
Slope= (y2-y1)/(x2-x1)
Take the coordinates (x1,y1) and (x2,y2) as input.
Solution:
import java.util.*;
public class SlopeCalculator
{
public static void main(String[] args)
{
Scanner in = new Scanner(System.in);

System.out.print("Enter the x-coordinate of point A (x1): ");


double x1 = in.nextDouble();
System.out.print("Enter the y-coordinate of point A (y1): ");
double y1 = scanner.nextDouble();

System.out.print("Enter the x-coordinate of point B (x2): ");


double x2 = scanner.nextDouble();
System.out.print("Enter the y-coordinate of point B (y2): ");
double y2 = scanner.nextDouble();

if (x2 - x1 != 0)
{
double slope = (y2 - y1) / (x2 - x1);
System.out.println("The slope (m) of the line is: " + slope);
}
else {
System.out.println("The slope is undefined (vertical line).");
}
}
}
Variable description table:
variable datatype description
x1 double x-coordinate of point A
x2 Double x-coordinate of point B
y1 Double y-coordinate of point A
y2 double y-coordinate of point B
slope double The calculated slope (m)
of the line

Output:
Q2.write a program to input the sum. Calculate and display the compound
interest in 3 years , when the rates for the successive years are r1%,r2% and
r3% respectively.
Solution:
import java.util.*;
public class CompoundInterestCalculator
{
public static void main(String[] args)
{
Scanner in = new Scanner(System.in);
System.out.print("Enter the principal amount (sum): ");
double principal = in.nextDouble();
System.out.print("Enter the interest rate for year 1 (r1%): ");
double rate1 = in.nextDouble();
System.out.print("Enter the interest rate for year 2 (r2%): ");
double rate2 = in.nextDouble();
System.out.print("Enter the interest rate for year 3 (r3%): ");
double rate3 =in.nextDouble();
double amountAfterYear1 = principal + (principal * rate1 / 100);
double amountAfterYear2 = amountAfterYear1 + (amountAfterYear1 *
rate2 / 100);
double amountAfterYear3 = amountAfterYear2 + (amountAfterYear2 *
rate3 / 100);
double compoundInterest = amountAfterYear3 - principal;
System.out.printf("The compound interest after 3 years is: %.2f\n",
compoundInterest);

}
}
Variable description table:
variable datatype description
principal doubl The initial amount of
.
e money (sum) to invest
rate1 The interest rate for the
double
first year (in percent).
The interest rate for the
rate2 double second year (in
percent).
double
The interest rate for the
rate
third year (in percent).
3
Total amount after the
amountAfterYear1 double
first year.
Total amount after the
amountAfterYear2 double
second year.
Total amount after the
amountAfterYear3 double
third year.
double The total compound
compoundInter interest earned after
est three years.

Output:
Q3. A bank announces new rates for Term Deposit Schemes for their
customers and Senior Citizens as given below:

Term Rate of Interest (General) Rate of Interest (Senior Citizen)


Up to 1 year 7.5% 8.0%
Up to 2 years 8.5% 9.0%
Up to 3 years 9.5% 10.0%
More than 3 years 10.0% 11.0%
The 'senior citizen' rates are applicable to the customers whose age is 60
years or more. Write a program to accept the sum (p) in term deposit
scheme, age of the customer and the term. The program displays the
information in the following format:

Amount Deposited Term Age Interest earned Amount Paid


xxx xxx xxx xxx

solution:
import java.util.Scanner;

public class BankDeposit


{
public static void main(String args[]) {

Scanner in = new Scanner(System.in);

System.out.print("Enter sum: ");


double sum = in.nextDouble();

System.out.print("Enter age: ");


int age = in.nextInt();

System.out.print("Enter term: ");


double term = in.nextDouble();

double si = 0.0;

if (term <= 1 && age < 60)


si = (sum * 7.5 * term) / 100;
else if (term <= 1 && age >= 60)
si = (sum * 8.0 * term) / 100;
else if (term <= 2 && age < 60)
si = (sum * 8.5 * term) / 100;
else if (term <= 2 && age >= 60)
si = (sum * 9.0 * term) / 100;
else if (term <= 3 && age < 60)
si = (sum * 9.5 * term) / 100;
else if (term <= 3 && age >= 60)
si = (sum * 10.0 * term) / 100;
else if (term > 3 && age < 60)
si = (sum * 10.0 * term) / 100;
else if (term > 3 && age >= 60)
si = (sum * 11.0 * term) / 100;

double amt = sum + si;

System.out.println("Amount Deposited: " + sum);


System.out.println("Term: " + term);
System.out.println("Age: " + age);
System.out.println("Interest Earned: " + si);
System.out.println("Amount Paid: " + amt);
}
}

Variable description table:


variable datatype description
sum double The principal amount
deposited by the user
age Int The age of user used to
determine interest rates
Term Double The duration of deposit
in years
si Double The simple interest
earned based on the
deposit parameters
amt Double The total amount to be
paid back, including the
principal and interest

Output:

Q4. A number is said to be Multiple Harshad number, when divided by the


sum of its digits, produces another 'Harshad Number'. Write a program to
input a number and check whether it is a Multiple Harshad Number or not.
(When a number is divisible by the sum of its digit, it is called 'Harshad
Number').
Sample Input: 6804
Hint: 6804 ⇒ 6+8+0+4 = 18 ⇒ 6804/18 = 378
378 ⇒ 3+7+8= 18 ⇒ 378/18 = 21
21 ⇒ 2+1 = 3 ⇒ 21/3 = 7
Sample Output: Multiple Harshad Number

Solution
import java.util.*;

public class MultipleHarshad


{
public static void main() {

Scanner in = new Scanner(System.in);


System.out.print("Enter number to check: ");
int num = in.nextInt();
int dividend = num;
int divisor;
int count = 0;

while (dividend > 1) {


divisor=0;
int t = dividend;
while (t > 0) {
int d = t % 10;
divisor += d;
t /= 10;
}

if (dividend % divisor == 0 && divisor != 1) {


dividend = dividend / divisor;
count++;
}
else {
break;
}
}

if (dividend == 1 && count > 1)


System.out.println(num + " is Multiple Harshad Number");
else
System.out.println(num + " is not Multiple Harshad Number");
}
}
Variable description table:
Variable datatype description
The number input by
num int the user that will be
checked.
The number currently
dividend int being checked in the
while loop.
The sum of the digits of
divisor int
the dividend.
Counter to keep track of
how many times the
count int
dividend can be divided
by its digit sum.
Temporary variable
used to calculate the
t int
sum of digits of the
dividend.
A single digit extracted
d int from t during digit sum
calculation.

Output:

Q5. Using the switch statement, write a menu driven program for the
following:

(a) To print the Floyd's triangle:


1
23
456
7 8 9 10
11 12 13 14 15

(b) To display the following pattern:


I
IC
ICS
ICSE

For an incorrect option, an appropriate error message should be displayed.

Solution
import java.util.*;

public class Pattern


{
public static void main()
{
Scanner in = new Scanner(System.in);
System.out.println("Type 1 for Floyd's triangle");
System.out.println("Type 2 for an ICSE pattern");

System.out.print("Enter your choice: ");


int ch = in.nextInt();

switch (ch) {
case 1:
int a = 1;
for (int i = 1; i <= 5; i++) {
for (int j = 1; j <= i; j++) {
System.out.print(a++ + "\t");
}
System.out.println();
}
break;

case 2:
String s = "ICSE";
for (int i = 0; i < s.length(); i++) {
for (int j = 0; j <= i; j++) {
System.out.print(s.charAt(j) + " ");
}
System.out.println();
}
break;

default:
System.out.println("Incorrect Choice");
}
}
}

Variable description table:


variable datatype description
The user's choice for
which pattern to display
ch int
(1 for Floyd's triangle, 2
for ICSE pattern).
A counter used to
a int generate numbers in
Floyd's triangle.
i int Loop variable for the
outer loop in both
patterns.
Loop variable for the
j int inner loop in both
patterns.
The string "ICSE" used
s String for generating the ICSE
pattern.

Output:

Q6. Write a program to input two characters from the keyboard. Find the
difference (d) between their ASCII codes. Display the following messages:
If d = 0 : both the characters are same.
If d \< 0 : first character is smaller.
If d > 0 : second character is smaller.
Sample Input :
D
P
Sample Output :
d = (68 - 80) = -12
First character is smaller

Solution:
import java.util.*;

public class ASCIIDiff


{
public static void main(String args[]) {
Scanner in = new Scanner(System.in);
System.out.print("Enter first character: ");
char ch1 = in.next().charAt(0);
System.out.print("Enter second character: ");
char ch2 = in.next().charAt(0);

int d = (int)ch1 - (int)ch2;


if (d > 0)
System.out.println("first character is smaller");
else if (d < 0)
System.out.println("second character is smaller");
else
System.out.println("Both the characters are same");
}
}

Variable description table:


variable datatype description
ch1 char
The first character input by the
user.
ch2 char
The second character input by the
user.
d int
The difference in ASCII values
between ch1 and ch2.

Output:
Q7. Using switch case statement, write a menu driven program to perform
the following tasks:
(a) To generate and print the letters from A to Z along with their Unicode.
Letters Unicode
A 65
B 66
….. ……..
….. ……..
Z 90

(b) To generate and print the letters from z to a along with their Unicode.
Letters Unicode
z 122
y 121
….. ……..
….. ……..
a 97

Solution:
import java.util.*;

public class LettersNUnicode


{
public static void main(String args[]) {
Scanner in = new Scanner(System.in);

System.out.println("Enter 1 for A to Z with unicode");


System.out.println("Enter 2 for z to a with unicode");

System.out.print("Enter your choice: ");


int ch = in.nextInt();

switch (ch) {
case 1:
System.out.println("Letters" + "\t" + "Unicode");
for(int i = 65; i <= 90; i++)
System.out.println((char)i + "\t" + i);
break;

case 2:
System.out.println("Letters" + "\t" + "Unicode");
for (int i = 122; i >= 97; i--)
System.out.println((char)i + "\t" + i);
break;

default:
System.out.println("Incorrect Choice");
}
}
}

Variable description table:


variable Datatype description
ch int
An integer variable that stores the
user's menu choice (1 or 2).
An integer variable used as a
i int loop counter for iterating through
ASCII values of characters.
Output:
Q8. Write a program to accept a list of 20 integers. Sort the first 10 numbers
in ascending order and next the 10 numbers in descending order by using
'Bubble Sort' technique. Finally, print the complete list of integers.
Solution:
import java.util.*;

public class SDABubbleSort


{
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();
}

for (int i = 0; i < arr.length / 2 - 1; i++) {


for (int j = 0; j < arr.length / 2 - i - 1; j++) {
if (arr[j] > arr[j + 1]) {
int t = arr[j + 1];
arr[j + 1] = arr[j];
arr[j] = t;
}
}
}

for (int i = 0; i < arr.length / 2 - 1; i++) {


for (int j = arr.length / 2; j < arr.length - i - 1; j++) {
if (arr[j] < arr[j + 1]) {
int t = arr[j + 1];
arr[j + 1] = arr[j];
arr[j] = t;
}
}
}

System.out.println("\nSorted Array:");
for (int i = 0; i < arr.length; i++) {
System.out.print(arr[i] + " ");
}
}
}

Variable description table:


variable datatype description
An array of integers with a fixed
arr int[] size of 20, used to store user-
inputted numbers.
An integer variable used as a
i int loop counter for iterating through
the array.
An integer variable used as a
j int loop counter for inner loops
when sorting the array.
A temporary variable used for
t int swapping elements during the
bubble sort process.

Output:

Q9. 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".
Sample Input:

n[0] n[1] n[2] n[3] n[4] n[5] n[6] n[7] n[8] n[9]
1982 1987 1993 1996 1999 2003 2006 2007 2009 2010

Solution:
import java.util.*;

public class GraduationYear


{
public static void main(String args[]) {
Scanner in = 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 = in.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");
}
}

Variable description table:


variable datatype description
Array storing graduation years in
n int[] ascending order, which will be
searched.
The graduation year entered by
year int the user that needs to be searched
within the array n.
l int
The lower bound index for the
binary search, initially set to 0.
The upper bound index for the
h int binary search, initially set to the
last index of the array n.
Stores the index of the year in
idx int
the array if found, otherwise
remains -1 indicating the year
was not found.
The middle index calculated in
each iteration of the binary
m int search to check if the year
matches, or to adjust l or h for
the search range.
Output:

Q10. If arrays M and M + N are as shown below, write a program in Java to


find the array N.

M = {{-1, 0, 2}, M + N = {{-6, 9, 4},


{-3, -1, 6}, {4, 5, 0},
{4, 3, -1}} {1, -2, -3}}

Solution:
public class SubtractDDA
{
public static void main(String args[]) {

int arrM[][] = {
{-1, 0, 2},
{-3, -1, 6},
{4, 3, -1}
};

int arrSum[][] = {
{-6, 9, 4},
{4, 5, 0},
{1, -2, -3}
};

int arrN[][] = new int[3][3];

for (int i = 0; i < 3; i++) {


for (int j = 0; j < 3; j++) {
arrN[i][j] = arrSum[i][j] - arrM[i][j];
}
}

System.out.println("Array N:");
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
System.out.print(arrN[i][j]);
System.out.print(' ');
}
System.out.println();
}
}
}

Variable description table:


variable datatype Description
A 3x3 2D array initialized with
arrSum int[][] specific integer values,
representing the second matrix.
A 3x3 2D array that stores the
result of element-wise
arrN int[][]
subtraction of arrM from
arrSum.
i int
Loop counter for the row index,
used to traverse the arrays.
j int
Loop counter for the column
index, used to traverse the arrays.

Output:

Q11. Write a program in Java to accept a word and display the ASCII code of
each character of the word.
Sample Input: BLUEJ
Sample Output:
ASCII of B = 66
ASCII of L = 76
ASCII of U = 85
ASCII of E = 69
ASCII of J = 74

Solution:
import java.util.*;

public class ASCIICode


{
public static void main(String args[]) {
Scanner in = new Scanner(System.in);
System.out.println("Enter a word:");
String word = in.nextLine();

int len = word.length();

for (int i = 0; i < len; i++) {


char ch = word.charAt(i);
System.out.println("ASCII of " + ch
+ " = " + (int)ch);
}
}
}
Variable description table:
variable datatype description
word String
Stores the input word entered by
the user.
Length of the input string word,
len int used to determine the number of
characters to process in the loop.
Loop counter used to iterate
i int through each character in the
string word.
Stores the current character in
ch char word being processed in the
loop.

Output:
Q12. Special words are those words which start and end with the same letter.
Example: EXISTENCE, COMIC, WINDOW
Palindrome words are those words which read the same from left to right and
vice-versa.
Example: MALYALAM, MADAM, LEVEL, ROTATOR, CIVIC
All palindromes are special words but all special words are not palindromes.

Write a program to accept a word. Check and display whether the word is a
palindrome or only a special word or none of them.

Solution:

import java.util.*;

public class SpecialPalindrome

public static void main(String args[]) {

Scanner in = new Scanner(System.in);

System.out.print("Enter a word: ");


String str = in.next();

str = str.toUpperCase();

int len = str.length();

if (str.charAt(0) == str.charAt(len - 1)) {

boolean isPalin = true;

for (int i = 1; i < len / 2; i++) {

if (str.charAt(i) != str.charAt(len - 1 - i)) {

isPalin = false;

break;

if (isPalin) {

System.out.println("Palindrome");

else {

System.out.println("Special");

else {

System.out.println("Neither Special nor Palindrome");

}
}

Variable description table:

variable Datatype description


Stores the input word entered by
str String the user, converted to uppercase
for consistent comparison.
Length of the input string str,
len int used to determine the number of
characters and positions to
compare.
Flag variable to indicate if the
word is a palindrome. Initially set
isPalin boolean to true, it changes to false if
any character does not match its
counterpart.
Loop counter variable used to
i int compare characters from the start
and end of the word.

Output:
Q13. Write a class with the name Perimeter using method overloading that
computes the perimeter of a square, a rectangle and a circle.
Formula:
Perimeter of a square = 4 * s
Perimeter of a rectangle = 2 * (l + b)
Perimeter of a circle = 2 * (22/7) * r
Solution:
import java.util.*;

public class Perimeter


{
public double perimeter(double s) {
double p = 4 * s;
return p;
}

public double perimeter(double l, double b) {


double p = 2 * (l + b);
return p;
}

public double perimeter(int c, double pi, double r) {


double p = c * pi * r;
return p;
}

public static void main(String args[]) {


Scanner in = new Scanner(System.in);
Perimeter obj = new Perimeter();

System.out.print("Enter side of square: ");


double side = in.nextDouble();
System.out.println("Perimeter of square = " + obj.perimeter(side));

System.out.print("Enter length of rectangle: ");


double l = in.nextDouble();
System.out.print("Enter breadth of rectangle: ");
double b = in.nextDouble();
System.out.println("Perimeter of rectangle = " + obj.perimeter(l, b));
System.out.print("Enter radius of circle: ");
double r = in.nextDouble();
System.out.println("Perimeter of circle = " + obj.perimeter(2, 3.14159,
r));
}
}
Variable description table:
variable datatype description
Side length of a square, used in
s double
the perimeter method to
calculate the perimeter of a
square.
Length of a rectangle, used in the
l double perimeter method to calculate
the perimeter of a rectangle.
Breadth of a rectangle, used in
b double
the perimeter method to
calculate the perimeter of a
rectangle.
Constant value representing 2 for
c int
calculating the perimeter of a
circle, used in the perimeter
method.
Value of π (pi), used in the
pi double perimeter method to calculate
the perimeter of a circle.
Radius of a circle, used in the
r double perimeter method to calculate
the perimeter of a circle.
Stores the calculated perimeter in
p double each perimeter method before
returning the result.
side double
Side length of a square entered
by the user.
l double
Length of a rectangle entered by
the user.
b double
Breadth of a rectangle entered by
the user.
r double
Radius of a circle entered by the
user.
Output:
Q14. Design a class overloading and a method display( ) as follows:
void display(String str, int p) with one String argument and one integer
argument. It displays all the uppercase characters if 'p' is 1 (one) otherwise,
it displays all the lowercase characters.
void display(String str, char chr) with one String argument and one character
argument. It displays all the vowels if chr is 'v' otherwise, it displays all the
alphabets.
Solution:
import java.util.*;
public class Overloading
{
void display(String str, int p) {

int len = str.length();

for (int i = 0; i < len; i++) {


char ch = str.charAt(i);
if (p == 1 && Character.isUpperCase(ch)) {
System.out.println(ch);
}
else if (p != 1 && Character.isLowerCase(ch)) {
System.out.println(ch);
}
}

void display(String str, char chr) {

int len = str.length();


for (int i = 0; i < len; i++) {
char ch = str.charAt(i);
ch = Character.toUpperCase(ch);
if (chr != 'v' && Character.isLetter(str.charAt(i)))
System.out.println(str.charAt(i));
else if (ch == 'A' ||
ch == 'E' ||
ch == 'I' ||
ch == 'O' ||
ch == 'U') {
System.out.println(str.charAt(i));
}
}

public static void main(String args[]) {


Scanner in = new Scanner(System.in);
System.out.print("Enter string: ");
String s = in.nextLine();

Overloading obj = new Overloading();


System.out.println("p=1");
obj.display(s, 1);
System.out.println("\np!=1");
obj.display(s, 0);
System.out.println("\nchr='v'");
obj.display(s, 'v');
System.out.println("\nchr!='v'");
obj.display(s, 'u');
}
}
Variable description table:
variable datatype description
Parameter in the first display
p int
method that determines whether
to display uppercase (p=1) or
lowercase characters (p!=1).
Parameter in the second
display method that determines
chr char the type of characters to display:
vowels if chr='v', otherwise all
alphabetic characters.
Length of the input string str,
len int used to determine the number of
characters to process in the loop.
Loop counter used to iterate
i int through each character in the
string str.
Stores the current character from
ch char str being processed in each loop
iteration.
s String
The string input by the user to be
passed to the display methods.

Output:
Q15. Bank charges interest for the vehicle loan as given below:

Rate of
Number of years
interest

Up to 5 years 15%

More than 5 and up to 10 12%


Rate of
Number of years
interest

years

Above 10 years 10%

Write a program to model a class with the specifications given below:

Class name: Loan

Data
Purpose
Members

Time for which loan is


int time
sanctioned

double
Amount sanctioned
principal

double rate Rate of interest

double
To store the interest
interest

Amount to pay after given


double amt
time
Member
Purpose
Methods

void getdata() To accept principal and time

To find interest and amount.


Interest =
void
(Principal*Rate*Time)/100
calculate()
Amount = Principal +
Interest

To display interest and


void display()
amount

Solution:
import java.util.*;

public class Loan


{
private int time;
private double principal;
private double rate;
private double interest;
private double amt;

public void getdata() {


Scanner in = new Scanner(System.in);
System.out.print("Enter principal: ");
principal = in.nextInt();
System.out.print("Enter time: ");
time = in.nextInt();
}

public void calculate() {


if (time <= 5)
rate = 15.0;
else if (time <= 10)
rate = 12.0;
else
rate = 10.0;

interest = (principal * rate * time) / 100.0;


amt = principal + interest;
}

public void display() {


System.out.println("Interest = " + interest);
System.out.println("Amount Payable = " + amt);
}

public static void main(String args[]) {


Loan obj = new Loan();
obj.getdata();
obj.calculate();
obj.display();
}
}
Variable description table:
variable datatype description
time int
Stores the loan duration (in
years) entered by the user.
principal double
Stores the principal loan amount
entered by the user.
Stores the interest rate
rate double determined based on the loan
duration (time).
Stores the calculated interest
interest double amount based on principal,
rate, and time.
Stores the total amount payable,
amt double which is the sum of principal
and interest.

Output:
Q16. Define a class called Student to check whether a student is eligible for
taking admission in class XI with the following specifications:

Data Members Purpose


String name to store name
int mm to store marks secured in Maths
int scm to store marks secured in Science
double comp to store marks secured in Computer
Member Methods Purpose
Student( ) parameterised constructor to initialize the data members by
accepting the details of a student
check( ) to check the eligibility for course based on the table given below
void display() to print the eligibility by using check() function in nested form
Marks Eligibility
90% or more in all the subjects Science with Computer
Average marks 90% or more Bio-Science
Average marks 80% or more and less than 90% Science with Hindi
Write the main method to create an object of the class and call all the
member methods.

Solution:
import java.util.*;

public class Student


{
private String name;
private int mm;
private int scm;
private int comp;

public Student(String n, int m, int sc, int c) {


name = n;
mm = m;
scm = sc;
comp = c;
}

private String check() {


String course = "Not Eligible";
double avg = (mm + scm + comp) / 3.0;

if (mm >= 90 && scm >= 90 && comp >= 90)


course = "Science with Computer";
else if (avg >= 90)
course = "Bio-Science";
else if (avg >= 80)
course = "Science with Hindi";

return course;
}

public void display() {


String eligibility = check();
System.out.println("Eligibility: " + eligibility);
}

public static void main(String args[]) {

Scanner in = new Scanner(System.in);


System.out.print("Enter Name: ");
String n = in.nextLine();
System.out.print("Enter Marks in Maths: ");
int maths = in.nextInt();
System.out.print("Enter Marks in Science: ");
int sci = in.nextInt();
System.out.print("Enter Marks in Computer: ");
int compSc = in.nextInt();

Student obj = new Student(n, maths, sci, compSc);


obj.display();
}
}
Variable description table:
variable datatype description
name String
Stores the name of the student
entered by the user.
mm int
Stores the marks obtained by the
student in Mathematics.
scm int
Stores the marks obtained by the
student in Science.
comp int
Stores the marks obtained by the
student in Computer Science.
Stores the eligibility result of the
course String student based on their marks in
different subjects.
Stores the average marks of the
avg double student across Mathematics,
Science, and Computer Science.
Stores the result of the check
eligibility String method to determine which
course the student is eligible for,
based on their marks.
n String
Holds the student's name entered
by the user in the main method.
maths int
Holds the marks in Mathematics
entered by the user.
sci int
Holds the marks in Science
entered by the user.
compSc int
Holds the marks in Computer
Science entered by the user.

Output:

Q17. Write a class program with the following specifications:


Class name — Matrix
Data members — int array m[][] with 3 rows and 3 columns
Member functions:
void getdata() — to accept the numbers in the array
void rowsum() — to find and print the sum of the numbers of each row
void colsum() — to find and print the sum of numbers of each column
Use a main function to create an object and call member methods of the
class.
Solution:
import java.util.*;

public class Matrix


{
private final int ARR_SIZE = 3;
private int[][] m;

public Matrix() {
m = new int[ARR_SIZE][ARR_SIZE];
}

public void getdata() {


Scanner in = new Scanner(System.in);
for (int i = 0; i < ARR_SIZE; i++) {
System.out.println("Enter elements of row "
+ (i+1) + ":");
for (int j = 0; j < ARR_SIZE; j++) {
m[i][j] = in.nextInt();
}
}
}

public void rowsum() {


for (int i = 0; i < ARR_SIZE; i++) {
int rSum = 0;
for (int j = 0; j < ARR_SIZE; j++) {
rSum += m[i][j];
}
System.out.println("Row " + (i+1) + " sum: " + rSum);
}
}

public void colsum() {


for (int i = 0; i < ARR_SIZE; i++) {
int cSum = 0;
for (int j = 0; j < ARR_SIZE; j++) {
cSum += m[j][i];
}
System.out.println("Column " + (i+1) + " sum: " + cSum);
}
}

public static void main(String args[]) {


Matrix obj = new Matrix();
obj.getdata();
obj.rowsum();
obj.colsum();
}
}

Variable Description table:


Variable datatype description
Constant representing the size of
ARR_SIZE int the matrix (3x3 matrix in this
case).
m int[][]
2D array to store the elements of
the matrix entered by the user.
i int
Loop variable used to iterate over
rows in the matrix.
j int
Loop variable used to iterate over
columns in the matrix.
Variable to store the sum of
rSum int
elements in each row of the
matrix, calculated in the rowsum
method.
Variable to store the sum of
cSum int
elements in each column of the
matrix, calculated in the colsum
method.
Output:
BIBLIOGRAPHY:
1. BLUEJ
2. APC UNDERSTANDING COMPUTER APPLICATIONS
3. GOOGLE.COM
4. KNOWLEDGEBOAT.COM
5. SHALAA.COM

You might also like