Acropolis Institute of Management Studies &
Research, Indore
Bachelors Of Computer Application
Subject:- Internet Application Using Java Programming
Course code:- S2-BCAB2T
Class:- BCA II Year
Department:- FCA
Session:- 2022-23
Submitted To Submitted By
[Link] Kumar Tanish Shrotriya
S.N Topic Date Remarks
o
1. Write a program to print
numbers into words using
Nested if and Switch case.
2. Write a program called pass
fail which prints 'pass' if the
int variable 'mark' is more
than or equal to 50; or prints
'fail' otherwise.
3. write a program called odd even
which prints 'odd number' if
the int variable 'number'
is odd, or 'even number'
otherwise.
4. write a program to find sum and average of
10 no. using array
5. Write a program to display reverse of a digit
no.
6. write a program to display grade according to
the marks obtained by the student.
7. find the factorial of number if
number is given by user using
command line argument.
8. write a program to print Fibonacci series.
9. write a program to display table s from 2 to
10.
10 write a program to take an input from user
. and check given number is prime or not.
11 write a program to implement method
. overriding.
12 Write a program to convert given string into
. uppercase and lowercase and get the length
of string using array .
13 Write a program to overload volume method
. to find out volume of cube and cuboid.
14 write a program to design a class using
. abstract methods and class.
15 write a program to implement multiple
. inheritance using interface.
Q1. Write a program to print numbers into words
using Nested if and Switch case.
import [Link];
public class PrintNumberInWord {
public static void main(String[] args)
{
int num;
Scanner reader = new Scanner([Link]);
[Link]("Enter Number: ");
num = [Link]();
useNestedIf(num);
useSwitchCase(num);
}
private static void useNestedIf(int number)
{
String numberStr = null;
if (0 == number) {
numberStr = "ZERO";
} else if (1 == number) {
numberStr = "ONE";
} else if (2 == number) {
numberStr = "TWO";
} else if (3 == number) {
numberStr = "THREE";
} else if (4 == number) {
numberStr = "FOUR";
} else if (5 == number) {
numberStr = "FIVE";
} else if (6 == number) {
numberStr = "SEX";
} else if (7 == number) {
numberStr = "SEVEN";
} else if (8 == number) {
numberStr = "EIGHT";
} else if (9 == number) {
numberStr = "NINE";
} else {
numberStr = "OTHER";
}
[Link]("(a) Use a \"nested-if\" statement: " +
numberStr);
}
private static void useSwitchCase(int number)
{
String numberStr = null;
switch (number) {
case 0: numberStr = "ZERO"; break;
case 1: numberStr = "ONE"; break;
case 2: numberStr = "TWO"; break;
case 3: numberStr = "THREE"; break;
case 4: numberStr = "FOUR"; break;
case 5: numberStr = "FIVE"; break;
case 6: numberStr = "SEX"; break;
case 7: numberStr = "SEVEN"; break;
case 8: numberStr = "EIGHT"; break;
case 9: numberStr = "NINE"; break;
default: numberStr = "OTHER"; break;
}
[Link]("(b) Use a \"switch-case\" statement: " +
numberStr);
}
}
Q2. Write a program called pass fail which prints
'pass' if the int variable 'mark' is more than or
equal to 50; or prints 'fail' otherwise.
import [Link];
public class PassFail
{
public static void main(String[] args)
{
int num;
Scanner reader = new Scanner([Link]);
[Link]("Enter score: ");
num = [Link]();
if (num>=37)
{
[Link]("Pass!");
}
else
[Link]("Fail!");
}
}
Q3 write a program called odd even which prints 'odd
number' if the int variable 'number'
is odd, or 'even number' otherwise.
import [Link];
public class OddEven {
public static void main(String[] args) {
Scanner reader = new Scanner([Link]);
[Link]("Enter a number: ");
int num = [Link]();
if(num % 2 == 0)
[Link](num + " is Even Number ");
else
[Link](num + " is Odd Number ");
}
}
Q4. write a program to find sum and average of 10 no. using array
//Java program to calculate the average of array elements
import [Link];
public class Main
{
// Function that returns the average of an array.
static double averageCalculate(int a[], int n)
{
// Find sum of array element
int sum = 0;
for (int i = 0; i < n; i++)
{
sum += a[i];
}
[Link]("The total sum of all the elements in the array is "+sum);
return (double)sum / n;
}
//driver code
public static void main (String[] args)
{
Scanner sc=new Scanner([Link]);
int n; //Declare array size
[Link]("Enter the total number of elements in the array ");
n=[Link](); //Initialize the array size
int arr[] = new int[n]; //Declare array
[Link]("Enter the array elements ");
for(int i=0 ; i<n ; i++) //Initialize the array
{
arr[i]=[Link]();
}
[Link]("The average of all the elements in an array is
"+averageCalculate(arr, n));
}
}
Q5. Write a program to display reverse of a digit no.
public class ReverseArray {
public static void main(String[] args) {
//Initialize array
int [] arr = new int [] {1, 2, 3, 4, 5};
[Link]("Original array: ");
for (int i = 0; i < [Link]; i++) {
[Link](arr[i] + " ");
}
[Link]();
[Link]("Array in reverse order: ");
//Loop through the array in reverse order
for (int i = [Link]-1; i >= 0; i--) {
[Link](arr[i] + " ");
}
}
}
Q6. write a program to display grade according to the marks obtained by the
student.
import [Link];
public class GradeCalculator {
public static void main(String[] args) {
Scanner input = new Scanner([Link]);
[Link]("Enter marks obtained: ");
double marks = [Link]();
String grade = calculateGrade(marks);
[Link]("Grade: " + grade);
}
public static String calculateGrade(double marks) {
String grade;
if (marks >= 90) {
grade = "A+";
} else if (marks >= 80) {
grade = "A";
} else if (marks >= 70) {
grade = "B";
} else if (marks >= 60) {
grade = "C";
} else if (marks >= 50) {
grade = "D";
} else if (marks >= 40) {
grade = "E";
} else {
grade = "F";
}
return grade;
}
}
Q7. find the factorial of number if number is given by user using command
line argument.
public class FactorialCalculator {
public static void main(String[] args) {
if ([Link] != 1) {
[Link]("Usage: java FactorialCalculator <number>");
[Link](1);
}
int number = [Link](args[0]);
int factorial = 1;
if (number < 0) {
[Link](" Enter a positive integer:”);
[Link](1);
} else if (number == 0) {
[Link]("Factorial of 0 is 1.");
[Link](0);
}
for (int i = 1; i <= number; i++) {
factorial *= i;
}
[Link]("Factorial of " + number + " is: " + factorial);
}
}
Q8. write a program to print Fibonacci series.
//Java Program to print Fibonacci series
import [Link].*;
public class Main
{
public static void main(String[] args)
{
//Take input from the user
//Create instance of the Scanner class
Scanner sc=new Scanner([Link]);
int t1 = 0, t2 = 1;
[Link]("Enter the number of terms: ");
int n=[Link](); //Declare and Initialize the number of terms
[Link]("First " + n + " terms of fibonnaci series: ");
//Print the fibonacci series
for (int i = 1; i <= n; ++i)
{ [Link](t1 + " ");
int sum = t1 + t2;
t1 = t2;
t2 = sum;
}
}
}
Q9. write a program to display table s from 2 to 10.
public class MultiplicationTables {
public static void main(String[] args) {
for (int i = 2; i <= 10; i++) {
[Link]("Table of " + i + ":");
for (int j = 1; j <= 10; j++) {
int result = i * j;
[Link](i + " x " + j + " = " + result);
}
[Link]();
}
}
}
Q10. write a program to take an input from user and check given number is
prime or not.
import [Link];
public class PrimeNumberChecker {
public static void main(String[] args) {
Scanner input = new Scanner([Link]);
[Link]("Enter a positive integer: ");
int num = [Link]();
boolean isPrime = checkPrime(num);
if (isPrime) {
[Link](num + " is a prime number.");
} else {
[Link](num + " is not a prime number.");
} }
public static boolean checkPrime(int num) {
if (num <= 1) {
return false; // Numbers less than or equal to 1 are not prime
}
for (int i = 2; i <= [Link](num); i++) {
if (num % i == 0) {
return false; // If the number is divisible by any number from 2 to sqrt(num), it's
not prime
}
}
return true; // Otherwise, it's prime }}
Q11. write a program to implement method overriding.
import [Link].*;
class Animal {
public void displayInfo() {
[Link]("I am an animal.");
}
}
class Dog extends Animal {
public void displayInfo() {
[Link]("I am a dog.");
}
}
class Main {
public static void main(String[] args) {
Dog d1 = new Dog();
[Link]();
}
}
Q12. Write a program to convert given string into uppercase and lowercase
and get the length of string using array .
import [Link].*;
public class StringConverter {
public static void main(String[] args) {
String input = "Hello, World!";
char[] charArray = [Link]();
int length = [Link];
[Link]("Original String: " + input);
[Link]("Length of String: " + length);
[Link]("Uppercase String: ");
for (int i = 0; i < length; i++) {
char c = [Link](charArray[i]);
[Link](c);
charArray[i] = c;
}
[Link]();
[Link]("Lowercase String: ");
for (int i = 0; i < length; i++) {
char c = [Link](charArray[i]);
[Link](c);
charArray[i] = c;
}
[Link]();}
Q13. Write a program to overload volume method to find out volume of cube
and cuboid.
import [Link].*;
public class VolumeCalculator {
public static void main(String[] args) {
double side = 5.0;
double length = 10.0;
double breadth = 7.0;
double height = 3.0;
double volumeCube = calculateVolume(side);
double volumeCuboid = calculateVolume(length, breadth, height);
[Link]("Volume of Cube: " + volumeCube);
[Link]("Volume of Cuboid: " + volumeCuboid);
}
public static double calculateVolume(double side) {
return side * side * side;
}
public static double calculateVolume(double length, double breadth, double height) {
return length * breadth * height;
}
}
Q14. write a program to design a class using abstract methods and class.
abstract class Demo {
// method of abstract class
public void display() {
[Link]("This is Java Programming");
}
}
class Main extends Demo {
public static void main(String[] args) {
// create an object of Main
Main obj = new Main();
// access method of abstract class
// using object of Main class
[Link]();
}
}
Q15. write a program to implement multiple inheritance using interface.
interface Printable {
void print();
}
interface Showable{
void show();
}
class A7 implements Printable,Showable{
public void print(){[Link]("Hello");}
public void show(){[Link]("Welcome");}
public static void main(String args[]){
A7 obj = new A7();
[Link]();
[Link]();
}
}
}
}