Trending ▼   ResFinder  

ICSE Class X Mid-term 2025 : Computer Applications

28 pages, 0 questions, 0 questions with responses, 0 total responses,    0    0
Ankit Nandy
  
+Fave Message
 Home > ankit_nandy >

Formatting page ...

MODERN ENGLISH ACADEMY COMPUTER APPLICATION PROJECT Name Riitoban Dutta Class X SEC A ROLL NO 35 UID 8451560 QUESTION 1: 1) Program Definition: The program defines a class ElectricBill to calculate and display the electricity bill based on the number of units consumed by a customer. The class includes methods to accept customer details, calculate the bill based on a specified tariff, and print the bill details. The main method demonstrates the usage of this class by creating an object and invoking the relevant methods. 2) Program Coding: import java.util.Scanner; class ElectricBill { // Instance variables 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 // Method to accept the name of the customer and number of units consumed void accept() { Scanner sc = new Scanner(System.in); System.out.print("Enter the name of the customer: "); n = sc.nextLine(); System.out.print("Enter the number of units consumed: "); units = sc.nextInt(); } // Method to calculate the bill as per the given tariff void calculate() { if (units <= 100) { bill = units * 2.00; } else if (units <= 300) { bill = 100 * 2.00 + (units - 100) * 3.00; } else { bill = 100 * 2.00 + 200 * 3.00 + (units - 300) * 5.00; bill += bill * 0.025; // Adding 2.5% surcharge } } // Method to print the details of the bill void print() { System.out.println("Name of the customer: " + n); System.out.println("Number of units consumed: " + units); System.out.println("Bill amount: Rs. " + bill); } // Main method to create an object and call the methods public static void main(String[] args) { ElectricBill eb = new ElectricBill(); eb.accept(); eb.calculate(); eb.print(); } } 3) Variable Description :TYPE String int double 4)Output: NAME n units bill FUNCTION Stores the name of the customer. Stores the number of units consumed by the customer. Stores the total amount to be paid by the customer based on the consumed units and the specified tariff. QUESTION 2 : 1) Program Definition :The program defines a class RailwayTicket to handle the ticket booking for a railway journey. The class includes methods to accept customer details, update the ticket amount based on the type of coach selected, and display the details of the ticket. The main method demonstrates the usage of this class by creating an object and invoking the relevant methods. 2) Program Coding :import java.util.Scanner; class RailwayTicket { // Instance variables String name; // To store the name of the customer String coach; // To store the type of coach the customer wants to travel long mobno; // To store customer's mobile number int amt; // To store the basic amount of ticket int totalamt; // To store the amount to be paid after updating the original amount // Method to accept the name, coach, mobile number, and amount void accept() { Scanner sc = new Scanner(System.in); System.out.print("Enter the name of the customer: "); name = sc.nextLine(); System.out.print("Enter the type of coach (First_AC/Second_AC/Third_AC/sleeper): "); coach = sc.nextLine(); System.out.print("Enter the mobile number of the customer: "); mobno = sc.nextLong(); System.out.print("Enter the basic amount of the ticket: "); amt = sc.nextInt(); } // Method to update the amount as per the coach selected void update() { switch (coach) { case "First_AC": totalamt = amt + 600; break; case "Second_AC": totalamt = amt + 400; break; case "Third_AC": totalamt = amt + 275; break; case "sleeper": totalamt = amt; // No extra charge for sleeper break; default: System.out.println("Invalid coach type entered."); totalamt = amt; // No extra amount added if invalid coach type break; } } // Method to print the ticket details void print() { System.out.println("Name of the customer: " + name); System.out.println("Type of coach: " + coach); System.out.println("Mobile number: " + mobno); System.out.println("Total amount to be paid: Rs. " + totalamt); } // Main method to create an object and call the methods public static void main(String[] args) { RailwayTicket rt = new RailwayTicket(); rt.accept(); rt.update(); rt.print(); } } 3) Variable Description :Type String String Name name coach Function Stores the name of the customer. Stores the type of coach the customer wants to travel (e.g., First_AC, Second_AC, Third_AC, sleeper). long int int mobno amt totalamt Stores the customer's mobile number. Stores the basic amount of the ticket. Stores the total amount to be paid after adding any extra charges based on the coach selected. 4)Output QUESTION 3 : 1) Program Definition :The program defines a class OverloadCheck that demonstrates function overloading by defining multiple versions of a method named check(). One version of the method calculates the frequency of a specified character in a string, and the other version displays all the vowels in a given string after converting it to lowercase. 2) Program Coding :class OverloadCheck { // Method to find and print the frequency of a character in a string void check(String str, char ch) { int count = 0; for (int i = 0; i < str.length(); i++) { if (str.charAt(i) == ch) { count++; } } System.out.println("ch = '" + ch + "'"); System.out.println("Number of '" + ch + "' present is = " + count); } // Method to display only vowels from a string after converting it to lowercase void check(String s1) { String vowels = ""; s1 = s1.toLowerCase(); for (int i = 0; i < s1.length(); i++) { char ch = s1.charAt(i); if (ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u') { vowels += ch + " "; } } System.out.println("Vowels: " + vowels.trim()); } // Main method to test the overloaded check methods public static void main(String[] args) { OverloadCheck oc = new OverloadCheck(); // Test the first version of the check method String str = "success"; char ch1 = 's'; oc.check(str, ch1); // Test the second version of the check method String s1 = "computer"; oc.check(s1); } } 3) Variable Description :Type String Name str char ch A character whose frequency is to be found in the string str. int count A counter to keep track of the frequency of the character ch in the string str. String s1 A string input for the second check() method to display vowels. String vowels A string to store the vowels found in s1. char ch1 4)Output:- Function A string input for the first check() method to find the frequency of a character. A character used to iterate through the string s1 to check for vowels QUESTION 4 : 1) Program Definition :The program defines a class VolumeCalculator that demonstrates function overloading by defining multiple versions of a method named volume(). Each version of the method calculates the volume of a different geometric shape: a sphere, a cylinder, and a cuboid. 2) Program Coding :class VolumeCalculator { // Method to calculate the volume of a sphere double volume(double R) { return (4.0 / 3.0) * (22.0 / 7.0) * Math.pow(R, 3); } // Method to calculate the volume of a cylinder double volume(double H, double R) { return (22.0 / 7.0) * Math.pow(R, 2) * H; } // Method to calculate the volume of a cuboid double volume(double L, double B, double H) { return L * B * H; } // Main method to test the overloaded volume methods public static void main(String[] args) { VolumeCalculator vc = new VolumeCalculator(); // Test the volume method for a sphere double sphereVolume = vc.volume(7); // Radius = 7 System.out.println("Volume of the sphere: " + sphereVolume); // Test the volume method for a cylinder double cylinderVolume = vc.volume(10, 7); // Height = 10, Radius = 7 System.out.println("Volume of the cylinder: " + cylinderVolume); // Test the volume method for a cuboid double cuboidVolume = vc.volume(5, 3, 2); // Length = 5, Breadth = 3, Height = 2 System.out.println("Volume of the cuboid: " + cuboidVolume); } } 3) Variable Description :Name double Type R double H double L double double double double 4)Output: B sphereVolume cylinderVolume cuboidVolume Function Radius used in the sphere and cylinder volume calculations. Height used in the cylinder and cuboid volume calculations. Length used in the cuboid volume calculation. Breadth used in the cuboid volume calculation. Stores the calculated volume of the sphere. Stores the calculated volume of the cylinder. Stores the calculated volume of the cuboid. QUESTION 5 : 1) Program Definition :The program accepts a string in lowercase and changes the first letter of every word to uppercase. It then displays the modified string. 2) Program Coding :import java.util.Scanner; public class ChangeCase { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); // Prompt user to enter a string in lowercase System.out.print("Enter a string in lowercase: "); String input = scanner.nextLine(); String result = ""; boolean newWord = true; for (int i = 0; i < input.length(); i++) { char ch = input.charAt(i); // Convert the first character of each word to uppercase if (newWord && ch != ' ') { ch = Character.toUpperCase(ch); newWord = false; } else if (ch == ' ') { newWord = true; } result += ch; } // Display the modified string System.out.println("Modified string: " + result); } } 3) Variable Description :- Type String String boolean int char Name input result newWord i ch 4) Output:- Function Stores the input string provided by the user. Stores the input string provided by the user. Stores the input string provided by the user. Loop variable used to iterate through the characters of the input string. Loop variable used to iterate through the characters of the input string. QUESTION 6 : 1) Program Definition :This program takes a sentence as input, converts it to uppercase, and then counts and displays the number of words starting with the letter 'C'. 2) Program Coding :import java.util.Scanner; public class WordCounter { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); // Prompt user to enter a sentence System.out.print("Enter a sentence: "); String sentence = scanner.nextLine(); // Convert the sentence to uppercase String uppercaseSentence = sentence.toUpperCase(); System.out.println("Uppercase sentence: " + uppercaseSentence); // Split the sentence into words String[] words = sentence.split(" "); // Count the words starting with letter 'C' int count = 0; for (String word : words) { if (word.startsWith("C")) { count++; } } // Display the count System.out.println("Total number of words starting with letter 'C' = " + count); } } 3) Variable Description : Scanner scanner: Scanner object used to read input from the user. String sentence: Stores the input sentence provided by the user. String uppercaseSentence: Stores the uppercase version of the input sentence. String[] words: Array to store the individual words extracted from the input sentence. int count: Counter variable to count the number of words starting with the letter 'C'. String word: Temporary variable to store each word during iteration. Type Name Function String String String[] sentence uppercaseSentence words int count String word Stores the input sentence provided by the user. Stores the uppercase version of the input sentence. Array to store the individual words extracted from the input sentence. Array to store the individual words extracted from the input sentence. Array to store the individual words extracted from the input sentence. 4)Output: QUESTION 7 : 1) Program Definition :This program takes ten words as input from the user and arranges them in descending order of alphabets using the Selection Sort technique. It then prints the sorted array. 2) Program Coding :import java.util.Scanner; public class SelectionSortWords { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); // Input ten words into an array String[] words = new String[10]; System.out.println("Enter ten words:"); for (int i = 0; i < 10; i++) { words[i] = scanner.nextLine(); } // Sort the array using Selection Sort (descending order) for (int i = 0; i < words.length - 1; i++) { int maxIndex = i; for (int j = i + 1; j < words.length; j++) { if (words[j].compareTo(words[maxIndex]) > 0) { // Compare words to find the largest maxIndex = j; } } // Swap the found largest element with the first element String temp = words[i]; words[i] = words[maxIndex]; words[maxIndex] = temp; } // Print the sorted array System.out.println("Sorted words in descending order:"); for (String word : words) { System.out.println(word); } } } 3) Variable Description :Type String[] int 4) Output Name words i int j int maxIndex String temp Function Array to store the input words. Loop variable for iteration during input and sorting. This variable is used as a loop counter to iterate through the remaining elements of the words array in the inner loop. It helps in finding the largest word to be swapped in the selection sort algorithm. This variable stores the index of the largest word found in the unsorted portion of the array during each iteration of the selection sort. This temporary variable is used to hold a word during the swapping process. It stores the current word while the largest word found (words[maxIndex]) is swapped into the correct position. Question 8 : 1) Program Definition :This program takes a string input from the user and finds the longest word in the string. It then prints the longest word. 2) Program Coding :- import java.util.Scanner; public class LongestWord { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); // Input a string System.out.print("Enter a string: "); String input = scanner.nextLine(); // Find the longest word String longestWord = findLongestWord(input); // Print the longest word System.out.println("Longest word: " + longestWord); } // Function to find the longest word in a string public static String findLongestWord(String input) { String longestWord = ""; String currentWord = ""; for (int i = 0; i < input.length(); i++) { char ch = input.charAt(i); if (ch != ' ') { currentWord += ch; } else { if (currentWord.length() > longestWord.length()) { longestWord = currentWord; } currentWord = ""; } } // Check the last word if it's longer than the longest word found so far if (currentWord.length() > longestWord.length()) { longestWord = currentWord; } return longestWord; } } 3) Variable Description :- Name String String String int char Type input longestWord currentWord i ch 4)Output: Function Stores the input string provided by the user. Stores the input string provided by the user. Stores the input string provided by the user. Loop variable used for iteration over characters in the input string. Temporary variable to store each character of the input string during iteration. Question 9 : 1) Program Definition :Program to count & print all the Palindrome words from a String. import java.util.Scanner; 2) Program Coding :public class PalindromeWords { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); System.out.print("Enter a string: "); String input = scanner.nextLine(); int palindromeCount = 0; String currentWord = ""; boolean buildingPalindrome = false; System.out.println("Palindrome words:"); for (int i = 0; i < input.length(); i++) { char ch = input.charAt(i); if (Character.isLetter(ch)) { currentWord += ch; buildingPalindrome = true; } else { if (buildingPalindrome) { if (isPalindrome(currentWord)) { System.out.println(currentWord); palindromeCount++; } currentWord = ""; } buildingPalindrome = false; } } if (buildingPalindrome && isPalindrome(currentWord)) { System.out.println(currentWord); palindromeCount++; } System.out.println("Total palindrome words: " + palindromeCount); } public static boolean isPalindrome(String word) { int left = 0, right = word.length() - 1; while (left < right) { if (word.charAt(left++) != word.charAt(right--)) return false; } return true; } } 3) Variable Description :Type Name Function String input int palindromeCount String currentWord boolean buildingPalindrome int i char ch int left int right Stores the input string provided by the user. Counts the number of palindrome words found in the string. Stores the current word being built while iterating through the string. Stores the current word being built while iterating through the string. Loop variable used for iteration over characters in the input string. Temporary variable to store each character of the input string during iteration. Temporary variable to store each character of the input string during iteration. Pointer to the rightmost character of the word during palindrome checking. 4) Output: Question 10 : 1) Program Definition :Program topic: Binary Search Program to search a string from a string array using BINARY SEARCH technique import java.util.Scanner; 2) Program Coding :- import java.util.Scanner; public class BinarySearchString { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); // Input size of the string array System.out.print("Enter the size of the string array: "); int size = scanner.nextInt(); scanner.nextLine(); // Consume newline String[] stringArray = new String[size]; // Input sorted string array System.out.println("Enter the sorted string array:"); for (int i = 0; i < size; i++) { stringArray[i] = scanner.nextLine(); } // Input string to search System.out.print("Enter the string to search: "); String searchKey = scanner.nextLine(); // Perform binary search int index = binarySearch(stringArray, searchKey); // Print result if (index != -1) { System.out.println("String found at index " + index); } else { System.out.println("String not found"); } } // Function to perform binary search on a sorted string array public static int binarySearch(String[] arr, String key) { int low = 0; int high = arr.length - 1; while (low <= high) { int mid = low + (high - low) / 2; int cmp = key.compareTo(arr[mid]); if (cmp < 0) { high = mid - 1; } else if (cmp > 0) { low = mid + 1; } else { return mid; // Key found } } return -1; // Key not found } } 3) Variable Description :Type int String[] String int int int int int 4)Output:- Name size stringArrary searchKey index low high mid cmp Function Stores the size of the string array. Array to store the sorted string elements. Stores the string to be searched Stores the string to be searched Lower bound of the search range. Upper bound of the search range. Middle index of the search range. Result of the comparison between the search key and the middle element. TOPIC SL NO 1) 2) 3) 4) 5) 6) 7) 8) 9) 10) Date TOPIC Electricity Bill Railway Ticket Overload Check Volume Check Changing Case in String Counting Characters in String Convert to Uppercase Selection Sort Finding length of a string i) Palindrome Words ii) Binary Search Signatu re INT EXT

Formatting page ...

Formatting page ...

Formatting page ...

Formatting page ...

Formatting page ...

Formatting page ...

Formatting page ...

Formatting page ...

Formatting page ...

Formatting page ...

Formatting page ...

Formatting page ...

Formatting page ...

Formatting page ...

Formatting page ...

Formatting page ...

Formatting page ...

Formatting page ...

Formatting page ...

Formatting page ...

Formatting page ...

Formatting page ...

Formatting page ...

Formatting page ...

Formatting page ...

Formatting page ...

Formatting page ...

 

  Print intermediate debugging step

Show debugging info


 

 

© 2010 - 2025 ResPaper. Terms of ServiceContact Us Advertise with us

 

ankit_nandy chat