LAB ACTIVITY [2025-2026]
COMPUTER APPLICATION
CLASS-10
TOPICS
CLASS AS THE BASIS OF ALL COMPUTATION(OBJECTS AND CLASSES)
01.Define a class called Library with the following description:
Instance Variables/Data Members:
int accNum — stores the accession number of the book.
String title — stores the title of the book.
String author — stores the name of the author.
Member methods:
void input() — To input and store the accession number, title and author.
Void compute() — To accept the number of days late, calculate and display the fine charged at the rate
of Rs. 2 per day.
Void display() — To display the details in the following format:
Accession Number Title Author
Write a main method to create an object of the class and call the above member methods.
import java.util.Scanner;
public class Library
{
private int accNum;
private String title;
private String author;
void input() {
Scanner in = new Scanner(System.in);
System.out.print("Enter book title: ");
title = in.nextLine();
System.out.print("Enter author: ");
author = in.nextLine();
System.out.print("Enter accession number: ");
accNum = in.nextInt();
}
void compute() {
Scanner in = new Scanner(System.in);
System.out.print("Enter number of days late: ");
int days = in.nextInt();
int fine = days * 2;
System.out.println("Fine = Rs." + fine);
}
void display() {
System.out.println("Accession Number\tTitle\tAuthor");
System.out.println(accNum + "\t\t" + title + "\t" + author);
}
public static void main(String args[]) {
Library obj = new Library();
obj.input();
obj.display();
obj.compute();
}
}
02.Define a class named movieMagic with the following description:
Data Members Purpose
int year To store the year of release of a movie
String title To store the title of the movie
To store the popularity rating of the movie
float rating
(minimum rating=0.0 and maximum rating=5.0)
Member
Purpose
Methods
Default constructor to initialize numeric data members to 0 and String data
movieMagic()
member to "".
void accept() To input and store year, title and rating
To display the title of the movie and a message based on the rating as per the table
void display()
given below
Ratings Table
Rating Message to be displayed
0.0 to 2.0 Flop
2.1 to 3.4 Semi-Hit
3.5 to 4.4 Hit
4.5 to 5.0 Super-Hit
Write a main method to create an object of the class and call the above member methods.
import java.util.Scanner;
public class movieMagic
{
private int year;
private String title;
private float rating;
public movieMagic() {
year = 0;
title = "";
rating = 0.0f;
}
public void accept() {
Scanner in = new Scanner(System.in);
System.out.print("Enter Title of Movie: ");
title = in.nextLine();
System.out.print("Enter Year of Movie: ");
year = in.nextInt();
System.out.print("Enter Rating of Movie: ");
rating = in.nextFloat();
}
public void display() {
String message = "Invalid Rating";
if (rating <= 2.0f)
message = "Flop";
else if (rating <= 3.4f)
message = "Semi-Hit";
else if (rating <= 4.4f)
message = "Hit";
else if (rating <= 5.0f)
message = "Super-Hit";
System.out.println(title);
System.out.println(message);
}
public static void main(String args[]) {
movieMagic obj = new movieMagic();
obj.accept();
obj.display();
}
}
03.Define a class named BookFair with the following description:
Instance variables/Data members:
String Bname — stores the name of the book
double price — stores the price of the book
Member methods:
(i) BookFair() — Default constructor to initialize data members
(ii) void Input() — To input and store the name and the price of the book.
(iii) void calculate() — To calculate the price after discount. Discount is calculated based on the following criteria.
Price Discount
Less than or equal to ₹1000 2% of price
More than ₹1000 and less than or equal to ₹3000 10% of price
More than ₹3000 15% of price
(iv) void display() — To display the name and price of the book after discount.
Write a main method to create an object of the class and call the above member methods.
import java.util.Scanner;
public class BookFair
{
private String bname;
private double price;
public BookFair() {
bname = "";
price = 0.0;
}
public void input() {
Scanner in = new Scanner(System.in);
System.out.print("Enter name of the book: ");
bname = in.nextLine();
System.out.print("Enter price of the book: ");
price = in.nextDouble();
}
public void calculate() {
double disc;
if (price <= 1000)
disc = price * 0.02;
else if (price <= 3000)
disc = price * 0.1;
else
disc = price * 0.15;
price -= disc;
}
public void display() {
System.out.println("Book Name: " + bname);
System.out.println("Price after discount: " + price);
}
public static void main(String args[]) {
BookFair obj = new BookFair();
obj.input();
obj.calculate();
obj.display();
}
}
04.Define a class ElectricBill with the following specifications:
class : ElectricBill
Instance variables / data member:
String n — to store the name of the customer
int units — to store the number of units consumed
double bill — to store the amount to be paid
Member methods:
void accept( ) — to accept the name of the customer and number of units consumed
void calculate( ) — to calculate the bill as per the following tariff:
Number of units Rate per unit
First 100 units Rs.2.00
Next 200 units Rs.3.00
Above 300 units Rs.5.00
A surcharge of 2.5% charged if the number of units consumed is above 300 units.
void print( ) — To print the details as follows:
Name of the customer: ………………………
Number of units consumed: ………………………
Bill amount: ………………………
Write a main method to create an object of the class and call the above member methods.
import java.util.Scanner;
public class ElectricBill
{
private String n;
private int units;
private double bill;
public void accept() {
Scanner in = new Scanner(System.in);
System.out.print("Enter customer name: ");
n = in.nextLine();
System.out.print("Enter units consumed: ");
units = in.nextInt();
}
public void calculate() {
if (units <= 100)
bill = units * 2;
else if (units <= 300)
bill = 200 + (units - 100) * 3;
else {
double amt = 200 + 600 + (units - 300) * 5;
double surcharge = (amt * 2.5) / 100.0;
bill = amt + surcharge;
}
}
public void print() {
System.out.println("Name of the customer\t\t: " + n);
System.out.println("Number of units consumed\t: " + units);
System.out.println("Bill amount\t\t\t: " + bill);
}
public static void main(String args[]) {
ElectricBill obj = new ElectricBill();
obj.accept();
obj.calculate();
obj.print();
}
}
05.Design a class RailwayTicket with following description:
Instance variables/data members:
String name — To store the name of the customer
String coach — To store the type of coach customer wants to travel
long mobno — To store customer’s mobile number
int amt — To store basic amount of ticket
int totalamt — To store the amount to be paid after updating the original amount
Member methods:
void accept() — To take input for name, coach, mobile number and amount.
void update() — To update the amount as per the coach selected (extra amount to be added in the amount as
follows)
Type of Coaches Amount
First_AC 700
Second_AC 500
Type of Coaches Amount
Third_AC 250
sleeper None
void display() — To display all details of a customer such as name, coach, total amount and mobile number.
Write a main method to create an object of the class and call the above member methods.
import java.util.Scanner;
public class RailwayTicket
{
private String name;
private String coach;
private long mobno;
private int amt;
private int totalamt;
private void accept() {
Scanner in = new Scanner(System.in);
System.out.print("Enter name: ");
name = in.nextLine();
System.out.print("Enter coach: ");
coach = in.nextLine();
System.out.print("Enter mobile no: ");
mobno = in.nextLong();
System.out.print("Enter amount: ");
amt = in.nextInt();
}
private void update() {
if(coach.equalsIgnoreCase("First_AC"))
totalamt = amt + 700;
else if(coach.equalsIgnoreCase("Second_AC"))
totalamt = amt + 500;
else if(coach.equalsIgnoreCase("Third_AC"))
totalamt = amt + 250;
else if(coach.equalsIgnoreCase("Sleeper"))
totalamt = amt;
}
private void display() {
System.out.println("Name: " + name);
System.out.println("Coach: " + coach);
System.out.println("Total Amount: " + totalamt);
System.out.println("Mobile number: " + mobno);
}
public static void main(String args[]) {
RailwayTicket obj = new RailwayTicket();
obj.accept();
obj.update();
obj.display();
}
}
06.Design a class name ShowRoom with the following description:
Instance variables / Data members:
String name — To store the name of the customer
long mobno — To store the mobile number of the customer
double cost — To store the cost of the items purchased
double dis — To store the discount amount
double amount — To store the amount to be paid after discount
Member methods:
ShowRoom() — default constructor to initialize data members
void input() — To input customer name, mobile number, cost
void calculate() — To calculate discount on the cost of purchased items, based on following criteria
Cost Discount (in percentage)
Less than or equal to ₹10000 5%
More than ₹10000 and less than or equal to ₹20000 10%
More than ₹20000 and less than or equal to ₹35000 15%
More than ₹35000 20%
void display() — To display customer name, mobile number, amount to be paid after discount.
Write a main method to create an object of the class and call the above member methods.
ANS-
import java.util.Scanner;
public class ShowRoom
{
private String name;
private long mobno;
private double cost;
private double dis;
private double amount;
public ShowRoom()
{
name = "";
mobno = 0;
cost = 0.0;
dis = 0.0;
amount = 0.0;
}
public void input() {
Scanner in = new Scanner(System.in);
System.out.print("Enter customer name: ");
name = in.nextLine();
System.out.print("Enter customer mobile no: ");
mobno = in.nextLong();
System.out.print("Enter cost: ");
cost = in.nextDouble();
}
public void calculate() {
int disPercent = 0;
if (cost <= 10000)
disPercent = 5;
else if (cost <= 20000)
disPercent = 10;
else if (cost <= 35000)
disPercent = 15;
else
disPercent = 20;
dis = cost * disPercent / 100.0;
amount = cost - dis;
}
public void display() {
System.out.println("Customer Name: " + name);
System.out.println("Mobile Number: " + mobno);
System.out.println("Amout after discount: " + amount);
}
public static void main(String args[]) {
ShowRoom obj = new ShowRoom();
obj.input();
obj.calculate();
obj.display();
}
}
ARRAY
01. Write a program to input 10 integer elements in an array and sort them in descending order using bubble
sort technique.
02.Write a program to input twenty names in an array. Arrange these names in descending order of letters, using
the bubble sort technique.
import java.util.Scanner;
public class ArrangeNames
{
public static void main(String args[]) {
Scanner in = new Scanner(System.in);
String names[] = new String[20];
System.out.println("Enter 20 names:");
for (int i = 0; i < names.length; i++) {
names[i] = in.nextLine();
}
//Bubble Sort
for (int i = 0; i < names.length - 1; i++) {
for (int j = 0; j < names.length - 1 - i; j++) {
if (names[j].compareToIgnoreCase(names[j + 1]) < 0) {
String temp = names[j + 1];
names[j + 1] = names[j];
names[j] = temp;
}
}
}
System.out.println("\nSorted Names");
for (int i = 0; i < names.length; i++) {
System.out.println(names[i]);
}
}
}
03. Write a program to perform binary search on a list of integers given below, to search for an element input by
the user. If it is found display the element along with its position, otherwise display the message "Search element
not found".
5, 7, 9, 11, 15, 20, 30, 45, 89, 97
import java.util.Scanner;
public class BinarySearch
{
public static void main(String args[]) {
Scanner in = new Scanner(System.in);
int arr[] = {5, 7, 9, 11, 15, 20, 30, 45, 89, 97};
System.out.print("Enter number to search: ");
int n = in.nextInt();
int l = 0, h = arr.length - 1, index = -1;
while (l <= h) {
int m = (l + h) / 2;
if (arr[m] < n)
l = m + 1;
else if (arr[m] > n)
h = m - 1;
else {
index = m;
break;
}
if (index == -1) {
System.out.println("Search element not found");
}
else {
System.out.println(n + " found at position " + index);
}
}
}
04. Write a program to input and sort the weight of ten people. Sort and display them in descending order using
the selection sort technique.
import java.util.Scanner;
public class SelectionSort
{
public static void main(String args[]) {
Scanner in = new Scanner(System.in);
double weightArr[] = new double[10];
System.out.println("Enter weights of 10 people: ");
for (int i = 0; i < 10; i++) {
weightArr[i] = in.nextDouble();
}
for (int i = 0; i < 9; i++) {
int idx = i;
for (int j = i + 1; j < 10; j++) {
if (weightArr[j] > weightArr[idx])
idx = j;
}
double t = weightArr[i];
weightArr[i] = weightArr[idx];
weightArr[idx] = t;
}
System.out.println("Sorted Weights Array:");
for (int i = 0; i < 10; i++) {
System.out.print(weightArr[i] + " ");
}
}
}
05. Write a program to accept the names of 10 cities in a single dimensional string array and their STD (Subscribers
Trunk Dialling) codes in another single dimension integer array. Search for the name of a city input by the user in
the list. If found, display "Search Successful" and print the name of the city along with its STD code, or else display
the message "Search unsuccessful, no such city in the list".
import java.util.Scanner;
public class StdCodes
{
public static void main(String args[]) {
final int SIZE = 10;
Scanner in = new Scanner(System.in);
String cities[] = new String[SIZE];
String stdCodes[] = new String[SIZE];
System.out.println("Enter " + SIZE +
" cities and their STD codes:");
for (int i = 0; i < SIZE; i++) {
System.out.print("Enter City Name: ");
cities[i] = in.nextLine();
System.out.print("Enter its STD Code: ");
stdCodes[i] = in.nextLine();
}
System.out.print("Enter name of city to search: ");
String city = in.nextLine();
int idx;
for (idx = 0; idx < SIZE; idx++) {
if (city.compareToIgnoreCase(cities[idx]) == 0) {
break;
}
}
if (idx < SIZE) {
System.out.println("Search Successful");
System.out.println("City: " + cities[idx]);
System.out.println("STD Code: " + stdCodes[idx]);
}
else {
System.out.println("Search Unsuccessful");
}
}
}
06. 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".
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
import java.util.Scanner;
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");
}
}
07.Write a program to initialize the seven Wonders of the World along with their locations in two different arrays.
Search for a name of the country input by the user. If found, display the name of the country along with its
Wonder, otherwise display "Sorry not found!".
Seven Wonders:
CHICHEN ITZA, CHRIST THE REDEEMER, TAJ MAHAL, GREAT WALL OF CHINA, MACHU PICCHU, PETRA, COLOSSEUM
Locations:
MEXICO, BRAZIL, INDIA, CHINA, PERU, JORDAN, ITALY
Examples:
Country name: INDIA
Output: TAJ MAHAL
Country name: USA
Output: Sorry Not found!
import java.util.Scanner;
public class 7Wonders
{
public static void main(String args[]) {
String wonders[] = {"CHICHEN ITZA", "CHRIST THE REDEEMER", "TAJMAHAL",
"GREAT WALL OF CHINA", "MACHU PICCHU", "PETRA", "COLOSSEUM"};
String locations[] = {"MEXICO", "BRAZIL", "INDIA", "CHINA", "PERU", "JORDAN",
"ITALY"};
Scanner in = new Scanner(System.in);
System.out.print("Enter country: ");
String c = in.nextLine();
int i;
for (i = 0; i < locations.length; i++) {
if (locations[i].equals(c)) {
System.out.println(locations[i] + " - " + wonders[i]);
break;
}
}
if (i == locations.length)
System.out.println("Sorry Not Found!");
}
}
08.Write a program to input integer elements into an array of size 20 and perform the following operations:
Display largest number from the array.
Display smallest number from the array.
Display sum of all the elements of the array
import java.util.Scanner;
public class SDAMinMaxSum
{
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);
}
}
09.Define a class to perform binary search on a list of integers given below, to search for an element input by
the user, if it is found display the element along with its position, otherwise display the message "Search
element not found".
2, 5, 7, 10, 15, 20, 29, 30, 46, 50
import java.util.Scanner;
public class BinarySearch
{
public static void main(String args[]) {
Scanner in = new Scanner(System.in);
int arr[] = {5, 7, 9, 11, 15, 20, 30, 45, 89, 97};
System.out.print("Enter number to search: ");
int n = in.nextInt();
int l = 0, h = arr.length - 1, index = -1;
while (l <= h) {
int m = (l + h) / 2;
if (arr[m] < n)
l = m + 1;
else if (arr[m] > n)
h = m - 1;
else {
index = m;
break;
}
if (index == -1) {
System.out.println("Search element not found");
}
else {
System.out.println(n + " found at position " + index);
}
}
}
STRING HANDLING
01. Write a program to accept a word and convert it into lower case, if it is in upper case. Display the new
word by replacing only the vowels with the letter following it.
Sample Input: computer
Sample Output: cpmpvtfr
import java.util.Scanner;
public class VowelReplace
{
public static void main(String args[]) {
Scanner in = new Scanner(System.in);
System.out.print("Enter a word: ");
String str = in.nextLine();
str = str.toLowerCase();
String newStr = "";
int len = str.length();
for (int i = 0; i < len; i++) {
char ch = str.charAt(i);
if (str.charAt(i) == 'a' ||
str.charAt(i) == 'e' ||
str.charAt(i) == 'i' ||
str.charAt(i) == 'o' ||
str.charAt(i) == 'u') {
char nextChar = (char)(ch + 1);
newStr = newStr + nextChar;
}
else {
newStr = newStr + ch;
}
}
System.out.println(newStr);
}
}
02. Write a program to accept a string. Convert the string into upper case letters. Count and output the
number of double letter sequences that exist in the string.
Sample Input: "SHE WAS FEEDING THE LITTLE RABBIT WITH AN
APPLE" Sample Output: 4
import java.util.Scanner;
public class LetterSeq
{
public static void main(String args[]) {
Scanner in = new Scanner(System.in);
System.out.print("Enter string: ");
String s = in.nextLine();
String str = s.toUpperCase();
int count = 0;
int len = str.length();
for (int i = 0; i < len - 1; i++) {
if (str.charAt(i) == str.charAt(i + 1))
count++;
}
System.out.println("Double Letter Sequence Count = " + count);
}
}
03.Write a program that encodes a word into Piglatin. To translate word into Piglatin word, convert the word into
uppercase and then place the first vowel of the original word as the start of the new word along with the
remaining alphabets. The alphabets present before the vowel being shifted towards the end followed by "AY".
Sample Input 1: London
Output: ONDONLAY
Sample Input 2: Olympics
Output: OLYMPICSAY
import java.util.Scanner;
public class PigLatin
{
public static void main(String args[]) {
Scanner in = new Scanner(System.in);
System.out.print("Enter word: ");
String word = in.next();
int len = word.length();
word=word.toUpperCase();
String piglatin="";
int flag=0;
for(int i = 0; i < len; i++)
{
char x = word.charAt(i);
if(x=='A' || x=='E' || x=='I' || x=='O' || x=='U')
{
piglatin=word.substring(i) + word.substring(0,i) + "AY";
flag=1;
break;
}
}
if(flag == 0)
{
piglatin = word + "AY";
}
System.out.println(word + " in Piglatin format is " + piglatin);
}
}
04. 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.
import java.util.Scanner;
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");
}
}
}
05. Write a program in Java to accept a string in lower case and change the first letter of every word to upper
case. Display the new string.
Sample input: we are in cyber world
Sample output: We Are In Cyber
World
import java.util.Scanner;
public class String
{
public static void main(String args[]) {
Scanner in = new Scanner(System.in);
System.out.println("Enter a sentence:");
String str = in.nextLine();
String word = "";
for (int i = 0; i < str.length(); i++) {
if (i == 0 || str.charAt(i - 1) == ' ') {
word += Character.toUpperCase(str.charAt(i));
}
else {
word += str.charAt(i);
}
}
System.out.println(word);
}
}
1. This type of practical file should be used.
2. The ruled pages are to be used for code documentation purposes.
3. No programming questions should be written in the file.
4. Activities should be numbered as Activity 1, Activity 2, and so on.
5. The VDT (Variable, Data, Type) table coding should be completed On the left side
(white page) after completing each documentation.
6. The submission date will be announced later,