TermWork Java ANISH
TermWork Java ANISH
Problem Statement 1. Write a Java Program to input any string and count the number
of occurrences of each Character.
Objective: To develop a Java program that takes a string as input and counts the
occurrences of each character in the string.
import java.util.Scanner;
class CharacterFrequency {
System.out.println("\nCharacter Frequencies:");
scanner.close(); } }
OUTPUT:
Gaurav joshi MCA-B Roll_no:05
Problem Statement 2. Write a Java program that prints the numbers from 1 to 50.
But for multiples of three print "T" instead of the number and for the multiples of five print
"F". For numbers which are multiples of both three and five print "TF".
Objective: To develop a Java program that prints numbers from 1 to 50 while replacing:
Multiples of 3 with "T"
if (i % 3 == 0 && i % 5 == 0) {
System.out.print("TF ");
} else if (i % 3 == 0) {
System.out.print("T ");
} else if (i % 5 == 0) {
System.out.print("F ");
} else {
OUTPUT:
Gaurav joshi MCA-B Roll_no:05
if (inputStr.equals(anotherStr)) {
} else {
}
Gaurav joshi MCA-B Roll_no:05
if (Character.isDigit(ch)) digits++;
scanner.close();
}
Gaurav joshi MCA-B Roll_no:05
OUTPUT:
Gaurav joshi MCA-B Roll_no:05
Objective: To design a Java class Employee that stores and manages employee tax
details.
class Employee {
pan = scanner.nextLine();
name = scanner.nextLine();
taxIncome = scanner.nextDouble();
TaxCalc(); }
tax = 0; // No tax
Gaurav joshi MCA-B Roll_no:05
} else {
}
Gaurav joshi MCA-B Roll_no:05
OUTPUT:
Gaurav joshi MCA-B Roll_no:05
Problem Statement 5. Write a Java program to create a class called Shape with
methods called getPeri() and getArea(). Create a subclass called Circle that overrides the
getPeri() and getArea() methods to calculate the perimeter and area of a circle.
class Shape {
return 0; }
return 0;
this.radius = radius;
@Override
@Override
System.out.println("\nCircle Details:");
circle.display();
scanner.close();
OUTPUT:
Gaurav joshi MCA-B Roll_no:05
Problem Statement 6. Write a Java program to create a class known as "Bank" with
methods called deposit() and withdraw(). Create a subclass called CustAccount that
overrides the withdraw() method. Make sure that withdrawal is not possible if balance in the
account is less than Rs. 250.
class Bank {
this.balance = initialBalance;
if (amount > 0) {
balance += amount;
} else {
balance -= amount;
} else {
super(initialBalance);
@Override
balance -= amount;
} else {
int choice;
do {
System.out.println("1. Deposit");
System.out.println("2. Withdraw");
System.out.println("4. Exit");
choice = scanner.nextInt();
switch (choice) {
case 1:
customer.deposit(depositAmount);
break;
case 2:
customer.withdraw(withdrawAmount);
break;
case 3:
customer.displayBalance();
break;
case 4:
break;
default:
scanner.close();
OUTPUT:
Gaurav joshi MCA-B Roll_no:05
Gaurav joshi MCA-B Roll_no:05
Problem Statement 7. Write a Java program to create an abstract class Animal with
an abstract method called sound(). Create subclasses Tiger and Dog that extend the Animal
class and implement the sound() method to make a specific sound for each animal.
Objective: To develop a Java program that demonstrates the concept of abstraction using
abstract classes and methods.
@Override
void sound() {
System.out.println("Tiger roars!"); }
@Override
void sound() {
System.out.println("Dog barks!");
tiger.sound();
dog.sound();
OUTPUT:
Gaurav joshi MCA-B Roll_no:05
Objective: To develop a Java program that demonstrates the use of interfaces and
polymorphism by implementing different sorting algorithms.
@Override
int n = array.length;
array[j + 1] = temp;
@Override
int n = array.length;
int minIndex = i;
minIndex = j;
array[minIndex] = array[i];
array[i] = temp;
OUTPUT:
Gaurav joshi MCA-B Roll_no:05
try {
if (args.length == 0) {
if (maxMarks <= 0) {
System.out.println("\nStudent Result:");
scanner.close();
Gaurav joshi MCA-B Roll_no:05
} catch (NumberFormatException e) {
} catch (IllegalArgumentException e) {
System.out.println(e.getMessage());
} catch (Exception e) {
OUTPUT:
Gaurav joshi MCA-B Roll_no:05
Problem Statement 10. Write a program in Java to accept and print the employee
details during runtime. The details will include employee id, name, designation, dept_ Id. The
program should raise an exception if user inputs incomplete or incorrect data. The entered
value should meet the following conditions:
Objective: To develop a Java program that accepts and validates employee details at
runtime while ensuring proper exception handling.
super(message);
class Employee {
try {
empId = Integer.parseInt(scanner.nextLine());
name = scanner.nextLine();
if (!name.matches("[A-Z]+")) {
designation = scanner.nextLine();
deptId = Integer.parseInt(scanner.nextLine());
} catch (NumberFormatException e) {
System.out.println("\nEmployee Details:");
try {
emp.acceptDetails();
Gaurav joshi MCA-B Roll_no:05
emp.displayDetails();
} catch (InvalidEmployeeDataException e) {
OUTPUT: