10TH Computer Applications Project 2023

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 70

SILICON VALLEY SCHOOL

2023-2024
COMPUTER APPLICATIONS
PROJECT

Name:
R.No:
Class:

1
ACKNOWLEDGEMENT

2
JAVA
PROGRAMMING

3
S.N TITLE PAGE NO
o

01 JAVA PROGRAMS

• ASSIGNMENT STATEMENT

• FUNCTION ARGUMENTS

• SERIES

• PATTERN

• READING STATEMENT

• BINARY SEARCH

• CONSTRUCTORS

• FUNCTION OVERLOADING

02 APPLICATION BASED MODULE

03 CONCLUSION

04 BIBILOGRAPHY

4
1. Write a java program to find the difference between the simple
interest and compound interest when principle, rate, time are given.

public class Interest

public static void main (String args[])

int p,t;

double r,si, amt, ci,d=0;

p = 3000;

r = 10;

t = 2;

amt= p*(Math.pow(1+r/100, t));

ci = amt-p;

si = p*r*t/100;

d = ci-si;

System.out.println("The compound interest="+(float)ci);

System.out.println("The simple interest=" +si);

System.out.println("The difference between simple interest and

compound interest =" +(float)d);

5
Variable List:
Name of the Data Purpose/Description
variable Type
p int To store value of principle amount p
t int To store value of time t
r double To store rate and percentage r
si double To calculate and store the simple
interest
ci double To calculate and store the compound
interest
d double To calculate the difference between
simple and compound interest
amt double To store the final amount

OUTPUT:

6
2. Write a java program to find out the area, perimeter and diagonal of
a Rectangle.
public class Rectangle
{

public static void main(String args[])


{
int l,b,ar,p;

double d;

l = 24;

b = 10;

ar = 1*b;

p= 2*(1+b);

d = Math.sqrt(1*1+b*b);

System.out.println("The area of rectangle: "+ar);


System.out.println("The perimeter of rectangle: "+p);
System.out.println ("The diagonal of rectangle: "+d);

7
Variable List:
Name of the Data Purpose/Description
variable Type
l int To store value of length l
b int To store value of breadth b
ar int To store value of area ar
p int To store value of perimeter p
d double To calculate and store the value of
diagonal of rectangle d

OUTPUT:

8
3. A computer manufacturing company announces a special offer to
their customers on purchasing laptops and the printers accordingly:
On Laptop : discount-15%
On Printer: discount-10%
Write a Java program to calculate the discount, if a customer
purchases a Laptop and Printer.
public class Computer
{
public static void main (int c, int p)
{

int r1=15, r2=10;

double d1, d2, m=0, n=0;

d1 =(double)r1/100*c;

d2 =(double)r2/100*p;

m= c-d1;

n=p-d2;

System.out.println("The price of laptop after discount+" +m);


System.out.println("The price of printer after discount="+n);
}
}

9
Variable List:
Name of the Data Purpose/Description
variable Type
c int To store price of computer c
p int To store price of printer p
r1 int To store value of computer rate of discount r1
r2 int To store value of computer rate of discount r2
d1 double To calculate and store the value of discount of
computer
d2 double To calculate and store the value of discount of
printer
m double To calculate and store the final amount of
computer
n double To calculate and store the final amount of printer

OUTPUT:

10
4. Write a program to input two unequal numbers. Display the numbers
after swapping their values in the variables without using a third
variable.
Sample Input: a = 76, b = 65
Sample Output: a = 65, b = 76

import java.util.Scanner;

public class NumberSwap


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

Scanner in = new Scanner(System.in);

System.out.println("Please provide two unequal numbers");

System.out.print("Enter the first number: ");


int firstNum = in.nextInt();

System.out.print("Enter the second number: ");


int secondNum = in.nextInt();

if (firstNum == secondNum)
{
System.out.println("Invalid Input. Numbers are equal.");
return;
}

firstNum = firstNum + secondNum;


secondNum = firstNum - secondNum;
firstNum = firstNum - secondNum;

System.out.println("First Number: " + firstNum);


System.out.println("Second Number: " + secondNum);
}
}

11
Variable List:
Name of the Data Purpose/Description
variable Type
firstNum int To store the value for first number
secondNum int To store the value for second number

Output

12
5. For every natural number m>1; 2m, m 2-1 and m2+1 form a
Pythagorean triplet. Write a program to input the value of 'm'
through console to display a 'Pythagorean Triplet'.
Sample Input: 3
Then 2m=6, m2-1=8 and m2+1=10
Thus 6, 8, 10 form a 'Pythagorean Triplet'.
import java.util.Scanner;

public class Triplet


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

Scanner in = new Scanner(System.in);

System.out.print("Enter the value of m: ");


int m = in.nextInt();

if (m < 2)
{
System.out.println("Invalid Input, m should be greater than 1");
return;
}

int a = 2 * m;
int b = (int)(Math.pow(m, 2) - 1);
int c = (int)(Math.pow(m, 2) + 1);
System.out.println("Pythagorean Triplets: " + a + ", " + b + ", " + c);

}
}

13
Variable List:
Name of the Data Purpose/Description
variable Type
m int To store the value for first number
a int To store the value for first Triplet number
b int To store the value for second Triplet number
c int To store the value for third Triplet number

OUTPUT:

14
6. A courier company charges differently for 'Ordinary' booking and
'Express' booking based on the weight of the parcel as per the tariff
given below:

Weight of parcel Ordinary Express booking


booking

Up to 100 gm ₹80 ₹100

101 to 500 gm ₹150 ₹200

501 gm to 1000 gm ₹210 ₹250

More than 1000 gm ₹250 ₹300

Write a program to input weight of a parcel and type of


booking (`O' for ordinary and 'E' for express). Calculate and
print the charges accordingly.

import java.util.Scanner;

public class CourierCompany


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

Scanner in = new Scanner(System.in);

System.out.print("Enter weight of parcel: ");


double wt = in.nextDouble();

System.out.print("Enter type of booking: ");


char type = in.next().charAt(0);

double charge = 0;

if (wt <= 0)
charge = 0;
else if (wt <= 100 && type == 'O')
charge = 80;
else if (wt <= 100 && type == 'E')
charge = 100;
else if (wt <= 500 && type == 'O')
charge = 150;
else if (wt <= 500 && type == 'E')

15
charge = 200;
else if (wt <= 1000 && type == 'O')
charge = 210;
else if (wt <= 1000 && type == 'E')
charge = 250;
else if (wt > 1000 && type == 'O')
charge = 250;
else if (wt > 1000 && type == 'E')
charge = 300;

System.out.println("Parcel charges = " + charge);


}
}

Variable List:
Name of the Data Type Purpose/Description
variable
m int To store the value for first number
a int To store the value for first Triplet number
b int To store the value for second Triplet number
c int To store the value for third Triplet number

OUTPUT

16
7. Write a menu driven program to calculate:

1. Area of a circle = p*r2, where p = (22/7)


2. Area of a square = side*side
3. Area of a rectangle = length*breadth

Enter 'c' to calculate area of circle, 's' to calculate area of


square and 'r' to calculate area of rectangle.

import java.util.Scanner;

public class MenuArea


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

Scanner in = new Scanner(System.in);

System.out.println("Enter c to calculate area of circle");


System.out.println("Enter s to calculate area of square");
System.out.println("Enter r to calculate area of rectangle");
System.out.print("Enter your choice: ");
char choice = in.next().charAt(0);

switch(choice)
{
case 'c':
System.out.print("Enter radius of circle: ");
double r = in.nextDouble();
double ca = (22 / 7.0) * r * r;
System.out.println("Area of circle = " + ca);
break;

case 's':
System.out.print("Enter side of square: ");
double side = in.nextDouble();
double sa = side * side;
System.out.println("Area of square = " + sa);
break;

case 'r':
System.out.print("Enter length of rectangle: ");
17
double l = in.nextDouble();
System.out.print("Enter breadth of rectangle: ");
double b = in.nextDouble();
double ra = l * b;
System.out.println("Area of rectangle = " + ra);
break;

default:
System.out.println("Wrong choice!");
}
}
}

Variable List:
Name of the Data Type Purpose/Description
variable
choice char To enter your choice
r double To enter the value for radius
ca Double To calculate the area of circle
side double To enter the value for side
sa doube To calculate the area of square
l double To enter the value for length
b double To enter the value for breadth
ra double To calculate the area of rectangle

18
OUTPUT

19
8. The relative velocity of two trains travelling in opposite directions is
calculated by adding their velocities. In case, the trains are travelling
in the same direction, the relative velocity is the difference between
their velocities. Write a program to input the velocities and length of
the trains. Write a menu driven program to calculate the relative
velocities and the time taken to cross each other.

import java.util.Scanner;

public class Train


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

Scanner in = new Scanner(System.in);

System.out.println("1. Trains travelling in same direction");


System.out.println("2. Trains travelling in opposite direction");
System.out.print("Enter your choice: ");
int choice = in.nextInt();

System.out.print("Enter first train velocity: ");


double speed1 = in.nextDouble();
System.out.print("Enter first train length: ");
double len1 = in.nextDouble();

System.out.print("Enter second train velocity: ");


double speed2 = in.nextDouble();
System.out.print("Enter second train length: ");
double len2 = in.nextDouble();

double rSpeed = 0.0;

switch(choice)
{
case 1:
rSpeed = Math.abs(speed1 - speed2);
break;

case 2:
rSpeed = speed1 + speed2;
break;

default:
20
System.out.println("Wrong choice! Please select from 1 or 2.");
}

double time = (len1 + len2) / rSpeed;

System.out.println("Relative Velocity = " + rSpeed);


System.out.println("Time taken to cross = " + time);
}
}

Variable List:
Name of the Data Type Purpose/Description
variable
choice int To enter your choice
speed1 double To enter the value of velocity for first train
len1 double To enter the value of length for first train
side double To enter the value of velocity for second train
sa double To enter the value of length for second train
l double To enter the value for length
rSpeed double To calculate the relative velocity
time double To calculate the time taken to cross

21
OUTPUT

22
9. Write a program to enter two numbers and check whether they are
co-prime or not.
[Two numbers are said to be co-prime, if their HCF is 1 (one).]
Sample Input: 14, 15
Sample Output: They are co-prime.

import java.util.Scanner;

public class Coprime


{
public void checkCoprime()
{

Scanner in = new Scanner(System.in);


System.out.print("Enter a: ");
int a = in.nextInt();
System.out.print("Enter b: ");
int b = in.nextInt();

int hcf = 1;

for (int i = 1; i <= a && i <= b; i++)


{
if (a % i == 0 && b % i == 0)
hcf = i;
}

if (hcf == 1)
System.out.println(a + " and " + b + " are co-prime");
else
System.out.println(a + " and " + b + " are not co-prime");
}
}

23
Variable List:
Name of the Data Type Purpose/Description
variable
a int To enter the value for a
b int To enter the value for b
hcf int To find the factor

OUTPUT

24
10.Write a program to input a number and display it into its Binary
equivalent.
Sample Input: (21)10
Sample Output: (10101)2

import java.util.*;

public class DecimaltoBinary


{
public static void main(String args[])
{
Scanner in = new Scanner(System.in);
System.out.print("Enter the decimal number: ");
long decimal = in.nextLong();
long binary = 0, m = 1, rem = 0;

while(decimal > 0) {
rem = decimal % 2;
binary = binary + (rem * m);
m *= 10;
decimal /= 2;
}
System.out.println("Equivalent binary number: " + binary);
}
}

25
Variable List:
Name of the Data Type Purpose/Description
variable
decimal long To enter the decimal number
binary long To convert the decimal number to binary
m long To multiply the number
rem long To find the remainder

OUTPUT

26
11.Write a program to accept a number and check whether it is a 'Spy
Number' or not. (A number is spy if the sum of its digits equals the
product of its digits.)

Example: Sample Input: 1124


Sum of the digits = 1 + 1 + 2 + 4 = 8
Product of the digits = 1*1*2*4 = 8

import java.util.Scanner;

public class SpyNumber


{
public void spyNumCheck()
{

Scanner in = new Scanner(System.in);

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


int num = in.nextInt();

int digit, sum = 0;


int orgNum = num;
int prod = 1;

while (num > 0)


{
digit = num % 10;

sum += digit;
prod *= digit;
num /= 10;
}

if (sum == prod)
System.out.println(orgNum + " is Spy Number");
else
System.out.println(orgNum + " is not Spy Number");

}
}

27
Variable List:
Name of the Data Purpose/Description
variable Type
num int To enter the number
digit int To enter the digit
sum int To calculate the sum
prod int To calculate the product
orgNum int To store the original number

OUTPUT

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

(a) To find and display the sum of the series given below:

S = x1 - x2 + x3 - x4 + x5 - ....................... - x20

(b) To find and display the sum of the series given below:

S = 1/a2 + 1/a4 + 1/a6 + 1/a8 + ....................... to n terms

For an incorrect option, an appropriate error message should be


displayed.

import java.util.Scanner;

public class SeriesSum


{
public static void main(String args[])
{
Scanner in = new Scanner(System.in);
System.out.println("1. Sum of x^1 - x^2 + .... - x^20");
System.out.println("2. Sum of 1/a^2 + 1/a^4 + .... to n terms");
System.out.print("Enter your choice: ");
int ch = in.nextInt();

switch (ch)
{
case 1:
System.out.print("Enter the value of x: ");
int x = in.nextInt();
long sum1 = 0;
for (int i = 1; i <= 20; i++)
{
int term = (int)Math.pow(x, i);
if (i % 2 == 0)
sum1 -= term;
else
sum1 += term;
}
System.out.println("Sum = " + sum1);
break;

29
case 2:
System.out.print("Enter the number of terms: ");
int n = in.nextInt();
System.out.print("Enter the value of a: ");
int a = in.nextInt();
int c = 2;
double sum2 = 0;
for(int i = 1; i <= n; i++)
{
sum2 += (1/Math.pow(a, c));
c += 2;
}
System.out.println("Sum = " + sum2);
break;

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

Variable List:
Name of the Data Purpose/Description
variable Type
ch int To enter the choice
x int To enter the value of x
sum1 long To find the sum
a int To enter the value of a
term int To calculate the term
c int To store the temporary variable

30
OUTPUT

31
13.Write a program to input a set of 20 letters. Convert each letter into
upper case. Find and display the number of vowels and number of
consonants present in the set of given letters.

import java.util.Scanner;

public class LetterSet


{
public static void main(String args[])
{
Scanner in = new Scanner(System.in);
System.out.println("Enter any 20 letters");
int vc = 0, cc = 0;
for (int i = 0; i < 20; i++) {
char ch = in.next().charAt(0);
ch = Character.toUpperCase(ch);
if (ch == 'A' ||
ch == 'E' ||
ch == 'I' ||
ch == 'O' ||
ch == 'U')
vc++;
else if (ch >= 'A' && ch <= 'Z')
cc++;
}
System.out.println("Number of Vowels = " + vc);
System.out.println("Number of Consonants = " + cc);
}
}

Variable List:
Name of the Data Purpose/Description
variable Type
ch int To enter the characters
vc int To find the vowel characters
cc int To find the consonant characters

32
OUTPUT

33
14.Write a menu driven program to generate the upper case letters
from Z to A and lower case letters from 'a' to 'z' as per the user's
choice.
Enter '1' to display upper case letters from Z to A and Enter '2' to
display lower case letters from a to z.

import java.util.Scanner;

public class Letters


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

Scanner in = new Scanner(System.in);


System.out.println("Enter '1' to display upper case letters from Z to A");
System.out.println("Enter '2' to display lower case letters from a to z");

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


int ch = in.nextInt();
int count = 0;

switch (ch)
{

case 1:
for (int i = 90; i > 64; i--)
{
char c = (char)i;
System.out.print(c);
System.out.print(" ");
count++;

//Print 10 characters per line


if (count == 10) {
System.out.println();
count = 0;
}
}
break;

34
case 2:
for (int i = 97; i < 123; i++)
{
char c = (char)i;
System.out.print(c);
System.out.print(" ");
count++;

//Print 10 characters per line


if (count == 10)
{
System.out.println();
count = 0;
}
}
break;

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

Variable List:
Name of the Data Purpose/Description
variable Type
ch int To enter your choice
count int To count the characters

35
OUTPUT

36
15.Write a program to input integer elements into an array of size 20
and perform the following operations:

1. Display largest number from the array.


2. Display smallest number from the array.
3. Display sum of all the elements of the array

Answer

import java.util.Scanner;

public class MinMaxSum


{
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];

if (arr[i] > max)


max = arr[i];

sum += arr[i];
}

System.out.println("Largest Number = " + max);


System.out.println("Smallest Number = " + min);
System.out.println("Sum = " + sum);
}
}

37
Variable List:
Name of the Data Purpose/Description
variable Type
arr[] int To enter the numbers
min int To find the smallest number
max int To find the largest number
sum int To find the sum

OUTPUT

38
16.Write a program to input and store roll numbers, names and marks
in 3 subjects of n number of students in five single dimensional
arrays and display the remark based on average marks as given
below:

Average Marks Remark

85 — 100 Excellent

75 — 84 Distinction

60 — 74 First Class

40 — 59 Pass

Less than 40 Poor

import java.util.Scanner;

public class KboatAvgMarks


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

Scanner in = new Scanner(System.in);


System.out.print("Enter number of students: ");
int n = in.nextInt();

int rollNo[] = new int[n];


String name[] = new String[n];
int s1[] = new int[n];
int s2[] = new int[n];
int s3[] = new int[n];
double avg[] = new double[n];

for (int i = 0; i < n; i++)


{
System.out.println("Enter student " + (i+1) + " details:");
System.out.print("Roll No: ");
rollNo[i] = in.nextInt();
in.nextLine();
System.out.print("Name: ");
name[i] = in.nextLine();
System.out.print("Subject 1 Marks: ");

39
s1[i] = in.nextInt();
System.out.print("Subject 2 Marks: ");
s2[i] = in.nextInt();
System.out.print("Subject 3 Marks: ");
s3[i] = in.nextInt();
avg[i] = (s1[i] + s2[i] + s3[i]) / 3.0;
}
System.out.println("Roll No\tName\tRemark");
for (int i = 0; i < n; i++)
{
String remark;
if (avg[i] < 40)
remark = "Poor";
else if (avg[i] < 60)
remark = "Pass";
else if (avg[i] < 75)
remark = "First Class";
else if (avg[i] < 85)
remark = "Distinction";
else
remark = "Excellent";
System.out.println(rollNo[i] + "\t"
+ name[i] + "\t"
+ remark);
}
}
}
Variable List:
Name of the Data Purpose/Description
variable Type
n int To enter the number of students
rollNo int To enter the student roll numbers
Name String To enter the student name
s1,s2,s3 int To enter the subject marks
avg[i] double To find the average
remark String To enter the remarks

40
OUTPUT

41
42
17.Write a program in Java to enter a String/Sentence and display the
longest word and the length of the longest word present in the
String.
Sample Input: “TATA FOOTBALL ACADEMY WILL PLAY
AGAINST MOHAN BAGAN”
Sample Output: The longest word: FOOTBALL: The length of the
word: 8

import java.util.Scanner;

public class KboatLongestWord


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

str += " "; //Add space at end of string


String word = "", lWord = "";
int len = str.length();

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


{
char ch = str.charAt(i);
if (ch == ' ')
{

if (word.length() > lWord.length())


lWord = word;

word = "";
}
else
{
word += ch;
}
}

System.out.println("The longest word: " + lWord +


": The length of the word: " + lWord.length());
}

}
43
Variable List:
Name of the Data Purpose/Description
variable Type
str String To enter a word or sentence
len int To find the length of a word or sentence
ch double To find the characters
word String To find the word

OUTPUT

44
18.Write a program using a method Palin( ), to check whether a string
is a Palindrome or not. A Palindrome is a string that reads the same
from the left to right and vice versa.
Sample Input: MADAM, ARORA, ABBA, etc.

import java.util.Scanner;

public class StringPalindrome


{
public void palin()
{

Scanner in = new Scanner(System.in);


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

String str = s.toUpperCase();


int strLen = str.length();
boolean isPalin = true;

for (int i = 0; i < strLen / 2; i++) {


if (str.charAt(i) != str.charAt(strLen - 1 - i))
{
isPalin = false;
break;
}
}

if (isPalin)
System.out.println("It is a palindrome string.");
else
System.out.println("It is not a palindrome string.");
}
}

45
Variable List:
Name of the Data Type Purpose/Description
variable
s String To enter a word
strlen int To find the length of a word
isPalin boolean To find the given word is Palin or not

OUTPUT

46
19.Design a class to overload a function Joystring( ) as follows:

1. void Joystring(String s, char ch1, char ch2) with one string


argument and two character arguments that replaces the character
argument ch1 with the character argument ch2 in the given String s
and prints the new string.
Example:
Input value of s = "TECHNALAGY"
ch1 = 'A'
ch2 = 'O'
Output: "TECHNOLOGY"
2. void Joystring(String s) with one string argument that prints the
position of the first space and the last space of the given String s.
Example:
Input value of s = "Cloud computing means Internet based
computing"
Output:
First index: 5
Last Index: 36
3. void Joystring(String s1, String s2) with two string arguments that
combines the two strings with a space between them and prints the
resultant string.
Example:
Input value of s1 = "COMMON WEALTH"
Input value of s2 = "GAMES"
Output: COMMON WEALTH GAMES

(Use library functions)

47
public class StringOverload
{
public void joystring(String s, char ch1, char ch2)
{
String newStr = s.replace(ch1, ch2);
System.out.println(newStr);
}

public void joystring(String s)


{
int f = s.indexOf(' ');
int l = s.lastIndexOf(' ');
System.out.println("First index: " + f);
System.out.println("Last index: " + l);
}

public void joystring(String s1, String s2)


{
String newStr = s1.concat(" ").concat(s2);
System.out.println(newStr);
}

public static void main(String args[])


{
StringOverload obj = new StringOverload();
obj.joystring("TECHNALAGY", 'A', 'O');
obj.joystring("Cloud computing means Internet based computing");
obj.joystring("COMMON WEALTH", "GAMES");
}
}

48
Variable List:
Name of the Data Purpose/Description
variable Type
s String To enter a word
ch1 char To enter a character1
ch2 char To enter a character2
f int To find the first index
l int To find the last index
newStr String To replace a new String

OUTPUT

49
20.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
Purpose
Methods

parameterised constructor to initialize the data members by


Student( )
accepting the details of a student

to check the eligibility for course based on the table given


check( )
below

to print the eligibility by using check() function in nested


void display()
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.

50
import java.util.Scanner;

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

51
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 List:
Name of the Data Purpose/Description
variable Type
name String to store name
mm int to store marks secured in Maths
scm int to store marks secured in Science
comp int to store marks secured in Computer
course String to select the course
n String to enter the name
maths int to enter the marks in Maths
sci int to enter the marks in Science
compSc int to enter the marks in Computer Science

52
OUTPUT

53
21.Write a program to use a class Account with the following
specifications:

Class name — Account

Data members — int acno, float balance

Member Methods:

1. Account (int a, int b) — to initialize acno = a, balance = b


2. void withdraw(int w) — to maintain the balance with withdrawal
(balance - w)
3. void deposit(int d) — to maintain the balance with the deposit
(balance + d)

Use another class Calculate which inherits from class Account with the
following specifications:

Data members — int r,t ; float si,amt;

Member Methods:

1. void accept(int x, int y) — to initialize r=x,t=y,amt=0


2. void compute() — to find simple interest and amount
si = (balance * r * t) / 100;
a = a + si;
3. void display() — to print account number, balance, interest and
amount

main() function need not to be used

public class Account


{
protected int acno;
protected float balance;

public Account(int a, int b)


{
acno = a;
balance = b;
}

public void withdraw(int w)


{
balance -= w;
54
}

public void deposit(int d)


{
balance += d;
}
}
public class Calculate extends Account
{
private int r;
private int t;
private float si;
private float amt;

public Calculate(int a, int b)


{
super(a, b);
}

public void accept(int x, int y)


{
r = x;
t = y;
amt = 0;
}

public void compute()


{
si = (balance * r * t) / 100.0f;
amt = si + balance;
}

public void display()


{
System.out.println("Account Number: " + acno);
System.out.println("Balance: " + balance);
System.out.println("Interest: " + si);
System.out.println("Amount: " + amt);
}
}

55
Variable List:
Name of the Data Purpose/Description
variable Type
acno int To enter the account number
balance float To check the balance
a int To initialize the value for acno
b int To initialize the value for balance
w int To withdraw the amount
d int To deposit the amount
r int To enter the rate
t int To enter the time
si float To calculate simple interest
amt float To calculate amount
x int To assign the value of r
y int To assign the value of t

OUTPUT

56
APPLICATION BASED
MODULE

57
PROGRAM STATEMENT
Program that displays a menu driven
transaction on Bank account,
withdrawing money, deposit money and
many more.
The user enters the choice and
accordingly his/her account details are
displays.

58
//Bank Account Program
import java.io.*;
import java.util.*;
class Account
{
String Name,Password;
int AccNo,Money;
int dd,mm,yy;
public Account(String n,int an,int d,int m,int y,int mon,String p)
{
Name=n;
AccNo=an;
dd=d;
mm=m;
yy=y;
Money=mon;
Password=p;
}
public void displayData()
{

System.out.println(AccNo+"\t"+Name+"\t\t"+dd+"/"+mm+"/"+yy
+"\t"+Money+"\t\t"+Password);
}
}

public class Bank


{
public static Calendar c=Calendar.getInstance();
public static int date=c.get(Calendar.DATE);
public static int month=c.get(Calendar.MONTH);
public static int year=c.get(Calendar.YEAR);

59
public static InputStreamReader isr=new
InputStreamReader(System.in);
public static BufferedReader x=new BufferedReader(isr);
public static int Ano=1;
public static Account Acc[]=new Account[100];
public static void main() throws IOException
{
int ch=1;
startAccount();
do
{
System.out.println(" Welcome to State Bank ");
System.out.println(" --: OPTION MENU :-- ");
System.out.println(" 1. Create Account ");
System.out.println(" 2. Withdrawl ");
System.out.println(" 3. Deposited ");
System.out.println(" 4. Checking Account ");
System.out.println(" 5. Checking Master ");
System.out.println(" 6. Exit ");
System.out.print( "Enter Your Choice(1-6) : ");
ch=Integer.parseInt(x.readLine());
switch(ch)
{
case 1: createAccount(); break;
case 2: withdrawl(); break;
case 3: deposit(); break;
case 4: checkAccount(); break;
case 5: checkMaster(); break;
}
}while(ch<=5);
}
private static void createAccount() throws IOException
{

60
Calendar c=Calendar.getInstance();
int date=c.get(Calendar.DATE);
int month=c.get(Calendar.MONTH);
int year=c.get(Calendar.YEAR);
String n,p;
int m;
System.out.println("Your Account Number is : "+Ano);
System.out.print("Your Name : ");
n=x.readLine();
System.out.print("Opening Balance : ");
m=Integer.parseInt(x.readLine());
System.out.print("Your Password : ");
p=x.readLine();
Acc[Ano]=new Account(n,Ano,date,month,year,m,p);
Ano++;
}
private static void withdrawl() throws IOException
{
String p;
int no,amt;
System.out.print("Your Account Number : ");
no=Integer.parseInt(x.readLine());
System.out.print("Password : ");
p=x.readLine();
if(no<Ano && p.equals(Acc[no].Password))
{
System.out.println("Welcome "+Acc[no].Name);
System.out.print("Withdrawl Amount : ");
amt=Integer.parseInt(x.readLine());
if(amt<=Acc[no].Money)
Acc[no].Money-=amt;
else

61
System.out.println("Only "+Acc[no].Money+" amount left in
your Account");
}
else
System.out.println("Your are Unauthorized Customer");
}
private static void deposit() throws IOException
{
String p;
int no,amt;
System.out.print("Your Account Number : ");
no=Integer.parseInt(x.readLine());
System.out.print("Password : ");
p=x.readLine();
if(no<Ano && p.equals(Acc[no].Password))
{
System.out.println("Welcome "+Acc[no].Name);
System.out.print("Deposit Amount : ");
amt=Integer.parseInt(x.readLine());
Acc[no].Money+=amt;
}
else
System.out.println("Your are Unauthorized Customer");
}
private static void checkAccount() throws IOException
{
String p;
int no,amt;
System.out.print("Your Account No. : ");
no=Integer.parseInt(x.readLine());
System.out.print("Password : ");
p=x.readLine();
if(no<Ano && p.equals(Acc[no].Password))

62
{
System.out.println("Your Name : "+Acc[no].Name);
System.out.println("Balance Amount : "+Acc[no].Money);
int rate=(Acc[no].Money>=20000)?18:10;
System.out.println("Interest Rate : "+rate+"%");
int interest=Acc[no].Money*rate/100;
System.out.println("Current Balance :
"+(Acc[no].Money+interest));
}
else
System.out.println("Your are Unauthorized Customer");
}
private static void checkMaster()
{
System.out.println("Acc\tName\t\tDate\t\tMoney\t\tPassword");
for(int i=1;i<Ano;i++)
Acc[i].displayData();
}
private static void startAccount()
{
Acc[Ano]=new
Account("Sachin",Ano,date,month,year,500,"ABC"); Ano++;
Acc[Ano]=new
Account("Sourav",Ano,date,month,year,500,"XYZ"); Ano++;
Acc[Ano]=new
Account("Shewag",Ano,date,month,year,500,"MNO"); Ano++;
}
}

63
OUTPUT

64
65
66
67
CONCLUSION

68
BIBLIOGRAPHY
ICSE Understanding Computer
Applications with bluej

• Vijay Kumar Pandey


• Dilip Kumar Dey

www.google.com

69
70

You might also like