├── 2nd_Lowest_Salary ├── Question.txt └── Solution.java ├── Armstrong.java ├── Calculator.java ├── CharRepeat.java ├── Character_odd_place.java ├── Company_Employee ├── Answer.java └── Question.txt ├── Consecutive2vowels.java ├── Consonent_OddPosition.java ├── CountPrime.java ├── CountVowel.java ├── Count_LowerCase.java ├── Count_UpperCase.java ├── Count_Word.java ├── Count_Word_Vowel.java ├── Fibonacci.java ├── Find_CountWord.java ├── Find_UpperCase.java ├── FirstLetterOfEachWord.java ├── First_Longest_Nonrepeated_Substring.java ├── First_NonRepeated_Char.java ├── IPA1 ├── courseProgram.java └── courseProgram.txt ├── IPA10 ├── IPA10.java └── IPA10.txt ├── IPA11 ├── IPA11.java └── IPA11.txt ├── IPA12 ├── IPA12.java └── IPA12.txt ├── IPA13 ├── IPA13.java └── IPA13.txt ├── IPA14 ├── IPA14.java └── IPA14.txt ├── IPA15 ├── IPA15.java └── IPA15.txt ├── IPA16 ├── IPA16.java └── IPA16.txt ├── IPA17 ├── IPA17.java ├── IPA17.txt └── IPA17_AnotherSolution.java ├── IPA18 ├── IPA18.java └── IPA18.txt ├── IPA19 ├── IPA19.java └── IPA19.txt ├── IPA2 ├── Footwear.txt └── footwearProgram.java ├── IPA20 ├── IPA20.java └── IPA20.txt ├── IPA21 ├── IPA21.java └── IPA21.txt ├── IPA22 ├── IPA22.java └── IPA22.txt ├── IPA23 ├── IPA23.java └── IPA23.txt ├── IPA24 ├── IPA24.java └── IPA24.txt ├── IPA25 ├── IPA25.java └── IPA25.txt ├── IPA26 ├── IPA26.java └── IPA26.txt ├── IPA27 ├── IPA27.java └── IPA27.txt ├── IPA28 ├── IPA28.java └── IPA28.txt ├── IPA29 ├── Calculate_Interest.java └── Question_Calculate_Interest.txt ├── IPA3 ├── IPA3.java └── IPA3.txt ├── IPA30 ├── DocsWithOddPages.txt └── DocsWithOddPagesByAssId.java ├── IPA31 ├── Music_IPA.java └── Music_IPA.txt ├── IPA32 ├── MyClass.java └── MyClass.txt ├── IPA33 ├── NewspaperIPA.java └── NewspaperIPA.txt ├── IPA34 ├── PlayerDetails.java └── PlayerDetails.txt ├── IPA35 ├── RemoveCar.java └── RemoveCar.txt ├── IPA36 ├── Mobile.java └── Mobile.txt ├── IPA37 ├── IPA37.java └── IPA37.txt ├── IPA38 ├── IPA38.java └── IPA38.txt ├── IPA39 ├── IPA39.java └── IPA39.txt ├── IPA4 ├── IPA4.java └── IPA4.txt ├── IPA40 ├── IPA40.java └── IPA40.txt ├── IPA41 ├── IPA41.java └── IPA41.txt ├── IPA42 ├── IPA42.java └── IPA42.txt ├── IPA43 ├── IPA43.java └── IPA43.txt ├── IPA44 ├── IPA44.java └── IPA44.txt ├── IPA45 ├── Question.txt └── Solution.java ├── IPA46 ├── Answer.java └── Question.txt ├── IPA48 ├── IPA48.java └── IPA48.txt ├── IPA49 ├── Answer.java └── Question.txt ├── IPA5 ├── IPA5.java └── IPA5.txt ├── IPA50 ├── Answer.java └── Question.txt ├── IPA51 ├── Answer.java └── Question.txt ├── IPA52 ├── Question.txt └── Solution.java ├── IPA53 ├── IPA53.txt └── Solution.java ├── IPA54 ├── Question.txt └── Solution.java ├── IPA55 ├── Question.txt └── Solution.java ├── IPA6 ├── IPA6.java └── IPA6.txt ├── IPA7 ├── IPA7.java └── IPA7.txt ├── IPA8 ├── IPA8.java └── IPA8.txt ├── IPA9 ├── IPA9.java └── IPA9.txt ├── IPA_practice1.java ├── IPA_practice2.java ├── IndexNumber_Calculate.java ├── IntersectionOfSet.java ├── Large_Small.java ├── LargestWord.java ├── LastChar.java ├── Majority.java ├── Marge.java ├── MaxPrimeDiaMatrix.java ├── MaximumAscii.java ├── MaximumPrimeInDiagMatrix.java ├── Missing.java ├── Occurance.java ├── Odd_Reverse.java ├── Palindrome.java ├── Palindrome_in_String.java ├── PerfectNumber.java ├── PerfectSquareOrNot.java ├── PlayerIPA.java ├── README.md ├── Remove2ConsecutiveLetter.java ├── RemoveLetter.java ├── Remove_Duplicate.java ├── Remove_Vowel.java ├── RepeatString.java ├── RepeatedNumber.java ├── RepeatedSum_Digit.java ├── ReverseString.java ├── Same_1st_2nd_Letter.java ├── Set_Employees_By_Location.java ├── Smallest_Character.java ├── SortBookByPrice.java ├── SortingName.java ├── Space_Count.java ├── Split.java ├── StringToArray.java ├── SumEven.java ├── SumOfEvenDigit.java ├── SumOfNum.java ├── Sum_EvenInteger.java ├── Sum_Prime_Digits.java ├── Sum_Upto_n.java ├── Text To Voice └── Text_To_Speech.py ├── UniqueCharacters.java ├── avg.java ├── charCount.java ├── evencheck.java ├── practice1.java ├── practice2.java ├── practice3.java ├── table.java ├── test.java └── welcome.mp3 /2nd_Lowest_Salary/Question.txt: -------------------------------------------------------------------------------- 1 | Create a class Employee with below attributes: 2 | 3 | employeeId - int 4 | employeeName - String 5 | age - int 6 | gender - char 7 | salary - double 8 | 9 | where employeeId is the unique identifier of the employee, employeeName is the name of the employee, age is the age of 10 | the employee, gender is the gender of the employee and salary is the salary of the employee. 11 | 12 | The above attributes should be private, write getters, setters and parameterized constructor as required. 13 | 14 | Create class Solution with main method. 15 | Implement two static methods - getEmployeeWithSecondLowestSalary and countEmployeesBasedOnAge in Solution class. 16 | 17 | getEmployeeWithSecondLowestSalary method: 18 | This method will take an array of Employee objects as a parameter. 19 | The method will return the Employee object with the second lowest salary in the array of Employee objects. 20 | If there are less than two employees in the array, then the method should return null. 21 | 22 | countEmployeesBasedOnAge method: 23 | This method will take two input parameters - array of Employee objects and an integer parameter (for age). 24 | The method will return the count of employees from the array of Employee objects whose age matches with the input 25 | parameter. 26 | If no employee with the given age is present in the array of Employee objects, then the method should return 0. 27 | 28 | Note : 29 | 30 | Two employee objects can have the same salary. 31 | All the searches should be case insensitive. 32 | 33 | The above mentioned static methods should be called from the main method. 34 | 35 | For getEmployeeWithSecondLowestSalary method - The main method should print the employeeId followed by # and employeeName 36 | from the returned Employee object, if the returned value is not null. 37 | 38 | If the returned value is null then it should print "Null". 39 | 40 | For countEmployeesBasedOnAge method - The main method should print the count of employees as it is, if the returned value 41 | is greater than 0, otherwise it should print "No employee found for the given age". 42 | 43 | Before calling these static methods in main, use Scanner to read the number of objects and objects to read the values of 44 | Employee objects referring attributes in the above mentioned attribute sequence. 45 | 46 | Consider below sample input and output: 47 | 48 | Input: 49 | ------------- 50 | 4 51 | 101 52 | John 53 | 30 54 | M 55 | 10000.00 56 | 102 57 | Samantha 58 | 25 59 | F 60 | 15000.00 61 | 103 62 | Alex 63 | 28 64 | M 65 | 12000.00 66 | 104 67 | Lisa 68 | 30 69 | F 70 | 15000.00 71 | 30 72 | 73 | Output: 74 | ---------------- 75 | 103#Alex 76 | 2 -------------------------------------------------------------------------------- /Armstrong.java: -------------------------------------------------------------------------------- 1 | /*Write a Java program to check if a given number is an Armstrong number or not. 2 | 3 | Here's an example of the expected input and output: 4 | 5 | Input number: 153 6 | Output: "Yes, the number is an Armstrong number." 7 | 8 | */ 9 | 10 | import java.util.*; 11 | public class Armstrong { 12 | public static void main(String[] args) { 13 | Scanner sc = new Scanner(System.in); 14 | String num = sc.nextLine(); 15 | int sum = 0; 16 | for (int i = 0; i < num.length(); i++) { 17 | sum+= Math.pow(Integer.parseInt(String.valueOf(num.charAt(i))),3); 18 | } 19 | if(sum == Integer.parseInt(num)) 20 | { 21 | System.out.println("Yes, the number is an Armstrong number."); 22 | } 23 | else{ 24 | System.out.println("No, the number is not an Armstrong number."); 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Calculator.java: -------------------------------------------------------------------------------- 1 | /* 2 | Write a Java program to implement a simple calculator. The program should prompt the user to enter two numbers and an 3 | operator (+, -, *, or /) and then perform the corresponding operation and display the result. 4 | 5 | For example, if the user enters 4, 5, and +, the program should display 9 as the result. Similarly, if the user enters 10, 3, 6 | and *, the program should display 30 as the result. 7 | 8 | Your program should handle invalid inputs gracefully, for example, if the user enters an operator that is not one of the four 9 | allowed operators or if the user enters non-numeric inputs. 10 | */ 11 | import java.util.*; 12 | public class Calculator { 13 | public static void main(String[] args) { 14 | Scanner sc = new Scanner(System.in); 15 | System.out.print("Enter 1st number: "); 16 | int a = sc.nextInt();sc.nextLine(); 17 | System.out.print("Enter 2nd number: "); 18 | int b = sc.nextInt();sc.nextLine(); 19 | System.out.print("Enter operator: "); 20 | char op = sc.nextLine().charAt(0); 21 | 22 | if(op == '+') 23 | { 24 | System.out.println(a+" "+op+" "+b+" = "+(a+b)); 25 | } 26 | else if(op == '-') 27 | { 28 | System.out.println(a+" "+op+" "+b+" = "+(a-b)); 29 | } 30 | else if(op == '*') 31 | { 32 | System.out.println(a+" "+op+" "+b+" = "+(a*b)); 33 | } 34 | else if(op == '/') 35 | { 36 | System.out.println(a+" "+op+" "+b+" = "+(a/b)); 37 | } 38 | else 39 | { 40 | System.out.println("Invalid operator"); 41 | } 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /CharRepeat.java: -------------------------------------------------------------------------------- 1 | // aabbbcc = a2b3c2 2 | // abbccc = a1b2c3 3 | 4 | import java.util.*; 5 | public class CharRepeat { 6 | public static void main(String[]args) 7 | { 8 | Scanner sc= new Scanner(System.in); 9 | String s = sc.nextLine(); 10 | int i=0; 11 | int count = 0; 12 | char ch = s.charAt(i); 13 | for (int k = 0; k < s.length(); k++) 14 | { 15 | if(ch==s.charAt(k)) 16 | { 17 | count++; 18 | } 19 | else{ 20 | System.out.print(ch+""+count); 21 | ch = s.charAt(k); 22 | count =0; 23 | k--; 24 | } 25 | 26 | if(ch == s.charAt(s.length()-1) && k==s.length()-1) 27 | { 28 | System.out.println(ch+""+count); 29 | } 30 | 31 | } 32 | 33 | } 34 | } -------------------------------------------------------------------------------- /Character_odd_place.java: -------------------------------------------------------------------------------- 1 | /* Find Characters of a string at odd index 2 | * Arijit = rjt 3 | * priyanka = ryna 4 | */ 5 | 6 | import java.util.*; 7 | public class Character_odd_place { 8 | public static void main(String[] args) { 9 | Scanner sc = new Scanner(System.in); 10 | String s = sc.nextLine(); 11 | for (int i = 0; i < s.length(); i++) { 12 | if(i%2!=0) 13 | { 14 | System.out.print(s.charAt(i)); 15 | } 16 | } 17 | System.out.println(); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Company_Employee/Question.txt: -------------------------------------------------------------------------------- 1 | Create a class named "Employee" with the following attributes: 2 | 3 | id (int) 4 | name (String) 5 | designation (String) 6 | salary (double) 7 | 8 | The above attributes should be private, and the class should have a parameterized constructor to initialize them. 9 | 10 | Implement the following methods in the Employee class: 11 | 12 | getSalary(): This method should return the salary of the employee. 13 | getDesignation(): This method should return the designation of the employee. 14 | 15 | Create a class named "Company" with the following attributes: 16 | 17 | companyName (String) 18 | employees (Employee array) 19 | numEmployees (int) 20 | 21 | The above attributes should be private, and the class should have a parameterized constructor to initialize them. 22 | 23 | Implement the following methods in the Company class: 24 | 25 | getAverageSalary(): This method should return the average salary of all the employees in the company. 26 | getMaxSalary(): This method should return the highest salary of all the employees in the company. 27 | getEmployeesByDesignation(String designation): This method should return an array of all employees with the given designation. 28 | 29 | In the main method, use a Scanner object to read the values of the company name, number of employees, and the employee details 30 | (id, name, designation, and salary) in a loop. Once all employee details have been read, create a Company object and pass the 31 | appropriate parameters. Finally, call the three methods mentioned above and print the output. 32 | 33 | Note: 34 | 35 | All searches should be case-insensitive. 36 | You may assume that the input is valid and in the correct format. 37 | 38 | Sample input: 39 | --------------------- 40 | Enter company name: ABC Company 41 | Enter number of employees: 3 42 | Enter employee details: 43 | Employee 1: 44 | Enter id: 101 45 | Enter name: John Smith 46 | Enter designation: Manager 47 | Enter salary: 5000 48 | Employee 2: 49 | Enter id: 102 50 | Enter name: Jane Doe 51 | Enter designation: Engineer 52 | Enter salary: 4000 53 | Employee 3: 54 | Enter id: 103 55 | Enter name: Bob Johnson 56 | Enter designation: Engineer 57 | Enter salary: 4500 58 | 59 | Sample Output: 60 | -------------------- 61 | Average salary: 4500.0 62 | Max salary: 5000.0 63 | Employees with designation: Engineer 64 | ID: 102, Name: Jane Doe, Designation: Engineer, Salary: 4000.0 65 | ID: 103, Name: Bob Johnson, Designation: Engineer, Salary: 4500.0 -------------------------------------------------------------------------------- /Consecutive2vowels.java: -------------------------------------------------------------------------------- 1 | /*Count the number of words in a sentence that contain at least two consecutive vowels (a, e, i, o, u) in them. 2 | Here's a sample input and output: 3 | 4 | Input: I enjoy eating spaghetti and meatballs for dinner 5 | Output: 2 6 | 7 | Explanation: There are two words in the sentence that contain at least two consecutive vowels - "enjoy" and "meatballs". 8 | */ 9 | 10 | import java.util.*; 11 | public class Consecutive2vowels { 12 | public static void main(String[] args) { 13 | Scanner sc = new Scanner(System.in); 14 | String s = sc.nextLine().toLowerCase(); 15 | String[] str = s.split(" "); 16 | int count=0; 17 | for (int i = 0; i < str.length; i++) { 18 | for (int j = 1; j < str[i].length(); j++) { 19 | if(isVowel(str[i].charAt(j-1))==true && isVowel(str[i].charAt(j))==true) 20 | { 21 | count++; 22 | break; 23 | } 24 | } 25 | } 26 | System.out.println(count); 27 | } 28 | public static boolean isVowel(char c) 29 | { 30 | if(c=='a'||c=='e'||c=='i'||c=='o'||c=='u') 31 | { 32 | return true; 33 | } 34 | return false; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /Consonent_OddPosition.java: -------------------------------------------------------------------------------- 1 | /* Find the characters in odd position of a string which are consonent 2 | * 3 | * Input: Arijit Ghosh 4 | * Output: hs 5 | */ 6 | 7 | import java.util.Scanner; 8 | 9 | public class Consonent_OddPosition { 10 | /* 11 | public static void main(String[] args) 12 | { 13 | Scanner sc = new Scanner(System.in); 14 | String s = sc.nextLine(); 15 | String v = "aeiouAEIOU"; 16 | for (int i = 0; i < s.length(); i++) { 17 | if((i+1)%2!=0 && !v.contains(Character.toString(s.charAt(i))) && s.charAt(i)!=' ') 18 | { 19 | System.out.print(s.charAt(i)); 20 | } 21 | } 22 | } 23 | */ 24 | 25 | // Another Solution 26 | 27 | public static void main(String[] args) { 28 | Scanner sc = new Scanner(System.in); 29 | String s = sc.nextLine(); 30 | char[] ch = {'a', 'e', 'i', 'o', 'u', 'A','E', 'I', 'O', 'U'}; 31 | for (int i = 0; i < s.length(); i++) { 32 | boolean test = true; 33 | for (int j = 0; j < ch.length; j++) { 34 | if((i+1)%2==0 || s.charAt(i)==ch[j] || s.charAt(i)==' ') 35 | { 36 | test = false; 37 | } 38 | } 39 | if(test == true) 40 | { 41 | System.out.print(s.charAt(i)); 42 | } 43 | } 44 | } 45 | } 46 | 47 | 48 | -------------------------------------------------------------------------------- /CountPrime.java: -------------------------------------------------------------------------------- 1 | /* Count number of prime digit in a Number 2 | * Input : 254786135 3 | * Output : 5 4 | */ 5 | import java.util.*; 6 | public class CountPrime { 7 | public static void main(String[] args) 8 | { 9 | int count=0; 10 | Scanner sc = new Scanner(System.in); 11 | String s = sc.nextLine(); 12 | for (int i = 0; i < s.length(); i++) 13 | { 14 | int p = Integer.parseInt(String.valueOf(s.charAt(i))); 15 | if(isPrime(p)==true) 16 | { 17 | count++; 18 | } 19 | } 20 | System.out.println(count); 21 | } 22 | public static boolean isPrime(int n) 23 | { 24 | int c=0; 25 | for (int i = 2; i < n; i++) 26 | { 27 | if(n%i==0) 28 | { 29 | c++; 30 | } 31 | } 32 | if(c==0 && n>1) 33 | { 34 | return true; 35 | } 36 | else 37 | { 38 | return false; 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /CountVowel.java: -------------------------------------------------------------------------------- 1 | /* Count number of vowel, consonent and digit into a string */ 2 | 3 | import java.util.*; 4 | 5 | public class CountVowel { 6 | public static void main(String[] args) { 7 | Scanner sc = new Scanner(System.in); 8 | String s = sc.nextLine(); 9 | int v =0; 10 | int c=0; 11 | int num=0; 12 | for(int i=0; i=65 && s.charAt(i)<92) 14 | //if(Character.isUpperCase(s.charAt(i))) 15 | { 16 | count++; 17 | } 18 | } 19 | if(count==0) 20 | { 21 | System.out.println("No upper case available in string"); 22 | } 23 | else 24 | { 25 | System.out.println(count); 26 | } 27 | } 28 | } -------------------------------------------------------------------------------- /Count_Word.java: -------------------------------------------------------------------------------- 1 | /* Count number of word in a string 2 | *Note : Always ignore the spaces if more than 1 space given between two word 3 | 4 | Sample Input : 1 5 | ------------------------ 6 | Kalyani Goverment Engineering College 7 | 8 | Process 9 | --------------------------- 10 | [Kalyani, Goverment, Engineering, College] 11 | 12 | Output 13 | --------------------------- 14 | Number of word : 4 15 | ************************************* 16 | Sample Input : 2 17 | ------------------------ 18 | Kalyani Goverment Engineering College 19 | 20 | Process 21 | --------------------------- 22 | [Kalyani, Goverment, , Engineering, College] 23 | 24 | Output 25 | --------------------------- 26 | Number of word : 4 27 | */ 28 | 29 | import java.util.*; 30 | public class Count_Word 31 | { 32 | public static void main(String[] args) 33 | { 34 | Scanner sc = new Scanner(System.in); 35 | String s = sc.nextLine(); 36 | String[] arr = s.split(" "); 37 | int count=0; 38 | //System.out.println(Arrays.toString(arr)); 39 | for (int i = 0; i < arr.length; i++) { 40 | if(arr[i]!="") 41 | { 42 | count++; 43 | } 44 | } 45 | System.out.println("Number of word : "+count); 46 | } 47 | } -------------------------------------------------------------------------------- /Count_Word_Vowel.java: -------------------------------------------------------------------------------- 1 | /* Count the words in a sentence which are start with vowel. 2 | * 3 | * Input: Arijit is student of MCA 4 | * Output: 3 5 | * 6 | * Input: Sara plays tennis 7 | * Output: No such words 8 | */ 9 | 10 | import java.util.*; 11 | public class Count_Word_Vowel { 12 | public static void main(String[] args) 13 | { 14 | Scanner sc = new Scanner(System.in); 15 | String s = sc.nextLine().toLowerCase(); 16 | String[] arr = s.split(" "); 17 | int count=0; 18 | for (int i = 0; i < arr.length; i++) { 19 | char d = arr[i].charAt(0); 20 | if(d=='a' || d=='e' || d=='i' || d=='o' || d=='u') 21 | { 22 | count++; 23 | } 24 | } 25 | if(count>0) 26 | { 27 | System.out.println(count); 28 | } 29 | else 30 | { 31 | System.out.println("No such words"); 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /Fibonacci.java: -------------------------------------------------------------------------------- 1 | /* Write a Java program that takes a user input integer n and prints the Fibonacci series up to n. 2 | 3 | The Fibonacci series is a series of numbers in which each number is the sum of the two preceding numbers. 4 | The first two numbers in the series are 0 and 1. For example, the first 10 numbers in the Fibonacci series are: 5 | 0, 1, 1, 2, 3, 5, 8, 13, 21, 34. 6 | 7 | The program should use a for loop to generate the series. 8 | 9 | Sample Input: 10 | 20 11 | 12 | Sample Output: 13 | 0 1 1 2 3 5 8 13 14 | 15 | Explanation: 16 | The Fibonacci series up to 20 is: 0, 1, 1, 2, 3, 5, 8, 13. Therefore, the output is "0 1 1 2 3 5 8 13". 17 | */ 18 | import java.util.*; 19 | public class Fibonacci 20 | { 21 | public static void main(String[] args) { 22 | Scanner sc = new Scanner(System.in); 23 | int n = sc.nextInt(); 24 | int i = 0; 25 | int k = 1; 26 | System.out.print(i+" "); 27 | while(k='A' && s[i].charAt(0)<='Z') 14 | { 15 | System.out.println(s[i]); 16 | } 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /FirstLetterOfEachWord.java: -------------------------------------------------------------------------------- 1 | /* Find first letter of each word in a string 2 | Input : Kalyani Govt. Eng. College 3 | Output : KGEC 4 | */ 5 | 6 | import java.util.*; 7 | public class FirstLetterOfEachWord { 8 | public static void main(String[] args) { 9 | Scanner sc = new Scanner(System.in); 10 | String str = sc.nextLine(); 11 | String s = ""; 12 | s = s+str.charAt(0); 13 | for (int i = 0; i < str.length(); i++) { 14 | if(str.charAt(i)==' ') 15 | { 16 | s = s + str.charAt(i+1); 17 | } 18 | } 19 | System.out.println(s); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /First_Longest_Nonrepeated_Substring.java: -------------------------------------------------------------------------------- 1 | // Find the first non repeated character substring 2 | //Arijit = Arij 3 | import java.util.*; 4 | public class First_Longest_Nonrepeated_Substring { 5 | public static void main(String[] args) { 6 | Scanner sc= new Scanner(System.in); 7 | String str = sc.nextLine(); 8 | String s = ""; 9 | int i,j,count=0; 10 | for (i = 0; i < str.length(); i++) { 11 | for (j = 0; j <= i; j++) 12 | { 13 | if(i==j) 14 | { 15 | s = s + str.charAt(i); 16 | } 17 | else 18 | { 19 | if(str.charAt(i)==str.charAt(j)) 20 | { 21 | count++; 22 | break; 23 | } 24 | } 25 | } 26 | if(count>0) 27 | { 28 | break; 29 | } 30 | } 31 | System.out.println(s); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /First_NonRepeated_Char.java: -------------------------------------------------------------------------------- 1 | /*Write a Java program to find the first non-repeated character in a given string. 2 | 3 | Here's an example of the expected input and output: 4 | 5 | Input string: "minimum" 6 | Output: "n" 7 | 8 | */ 9 | 10 | import java.util.*; 11 | public class First_NonRepeated_Char { 12 | public static void main(String[] args) { 13 | Scanner sc = new Scanner(System.in); 14 | String s = sc.nextLine(); 15 | 16 | for (int i = 0; i < s.length(); i++) 17 | { 18 | int count=0; 19 | for (int j = 0; j < s.length(); j++) 20 | { 21 | if(i!=j && s.charAt(i)==s.charAt(j)) 22 | { 23 | count++; 24 | break; 25 | } 26 | } 27 | if(count==0) 28 | { 29 | System.out.println(s.charAt(i)); 30 | break; 31 | } 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /IPA1/courseProgram.txt: -------------------------------------------------------------------------------- 1 | create the class Course with the below Attributes. 2 | 3 | courseId- int 4 | courseName- String 5 | courseAdmin- String 6 | quiz- int 7 | handson -int 8 | 9 | The above methods should be private ,write getter and 10 | setter and parametrized constructor as required. 11 | 12 | create class courseProgram with main method. 13 | 14 | implement two static methods- 15 | findAvgOfQuizByAdmin method:this method will take array 16 | of Course objects and a String value as input parameters. 17 | This method will find out Average (as int) of Quiz questions 18 | for given Course Admin (String parametre passed) 19 | This method will return Average if found.if there is no course 20 | that matches then the method should return 0. 21 | 22 | sortCourseByHandsOn method: 23 | This method will take an Array of Course Objects and int 24 | value as input parameters. 25 | This methods should return an Array of Course objects in an 26 | ascending order of their handson which are less than the 27 | given handson(int parameter passed) value. if there is no 28 | such course then the method should return null. 29 | 30 | The above mentioned static methods should be called from 31 | main methods. 32 | 33 | for findAvgOfQuizByAdmin method: The main method 34 | should print the average if the returned value is not 0. 35 | if the returned value is 0 then it should print "No Course 36 | found." 37 | 38 | 39 | for sortCourseByHandsOn method: 40 | the main method should print the name 41 | of the Course from the returned Course object Array if the 42 | returned value is not null.if the returned value is null then 43 | it should print "No Course found with mentioned attribute." 44 | 45 | input1: 46 | 111 47 | kubernetes 48 | Nisha 49 | 40 50 | 10 51 | 321 52 | cassandra 53 | Roshini 54 | 30 55 | 15 56 | 457 57 | Apache Spark 58 | Nisha 59 | 30 60 | 12 61 | 987 62 | site core 63 | Tirth 64 | 50 65 | 20 66 | Nisha 67 | 17 68 | 69 | output1: 70 | 35 71 | kubernetes 72 | Apache Spark 73 | cassandra 74 | 75 | input2: 76 | 111 77 | kubernetes 78 | Nisha 79 | 40 80 | 10 81 | 321 82 | cassandra 83 | Roshini 84 | 30 85 | 15 86 | 457 87 | Apache Spark 88 | Nisha 89 | 30 90 | 12 91 | 987 92 | site core 93 | Tirth 94 | 50 95 | 20 96 | Shubhamk 97 | 5 98 | 99 | output 2: 100 | No Course found 101 | No Course found with mentioned attributes. -------------------------------------------------------------------------------- /IPA10/IPA10.txt: -------------------------------------------------------------------------------- 1 | Create a class called Employee with the below attributes: 2 | 3 | employeeld - int 4 | name - String 5 | branch - String 6 | rating - double 7 | company Transport - boolean 8 | The above attributes should be private. write getters, setters and parameterized constructor as required. 9 | 10 | Create class MyClass with main method. 11 | Implement two static methods findCountOfEmployeesUsingCompTransport and findEmployeeWithSecondHighestRating 12 | in MyClass class. 13 | 14 | findCountOfEmployeesUsingCompTransport method: 15 | ---------------------------------------------- 16 | This method will take an array of Employee object and a String parameter as input parameters. 17 | This method will calculate and return the count of Employees who are all using company transport 18 | in the given branch (String parameter passed). 19 | If no Employee in the given branch using company transport in the array of Employee objects, then 20 | the method should return 0. 21 | 22 | findEmployeeWithSecondHighestRating method: 23 | -------------------------------------------- 24 | This method will take an array of Employee objects as an input parameter. This method will return 25 | the object of the second highest rating employee from the array of Employee objects who are not using 26 | company transport. 27 | If all Employees using company transport in the array of Employee objects, then the method should return null. 28 | 29 | Note: All the searches should be case sensitive, companyTransport and rating combination of each Employee 30 | is unique. 31 | For findCountOfEmployeesUsingCompTransport method, The main method should print the returned count as it 32 | is if the returned value is greater than 0, else it should print "No such Employees". 33 | Ex: 2 , where 2 is the count 34 | For findEmployeeWithSecondHighestRating method: The main method should print the employeeld and name from 35 | the returned object if the returned value is not null. If the returned value is null, then it should 36 | print "All Employees using company transport". 37 | Ex: 1003 38 | Uma 39 | where 1003 is the employeeld and Uma is the name. 40 | Before calling these static methods in main, use Scanner object to read the values of four Employee 41 | objects referring attributes in the above mentioned attributes sequence. Next, read the value of String 42 | parameter for capturing branch. 43 | 44 | Input : 45 | 46 | 1001 47 | Ashwa 48 | IT 49 | 5 50 | true 51 | 1002 52 | Preeti 53 | IT 54 | 4 55 | true 56 | 1003 57 | Uma 58 | Admin 59 | 3 60 | false 61 | 1004 62 | Akash 63 | Hardware 64 | 4.5 65 | false 66 | IT 67 | 68 | 69 | 70 | Output : 71 | 72 | 2 73 | 1003 74 | Uma -------------------------------------------------------------------------------- /IPA11/IPA11.java: -------------------------------------------------------------------------------- 1 | package IPA11; 2 | import java.util.*; 3 | 4 | import PlayerIPA; 5 | public class IPA11 6 | { 7 | public static void main(String[] args) 8 | { 9 | Scanner sc = new Scanner(System.in); 10 | PlayerIPA[] p = new PlayerIPA[4]; 11 | for(int i=0; i<4; i++) 12 | { 13 | int a = sc.nextInt();sc.nextLine(); 14 | String b = sc.nextLine(); 15 | String c = sc.nextLine(); 16 | int d = sc.nextInt();sc.nextLine(); 17 | 18 | p[i] = new PlayerIPA(a,b,c,d); 19 | } 20 | String s = sc.nextLine(); 21 | String l = sc.nextLine(); 22 | 23 | int ans1 = findPointsForGivenSkill(p,s); 24 | if(ans1!=0) 25 | { 26 | System.out.println(ans1); 27 | } 28 | else 29 | { 30 | System.out.println("The given Skill is not available"); 31 | } 32 | 33 | int ans2 = getPlayerBasedOnLevel(p,s,l); 34 | if(ans2!=0) 35 | { 36 | System.out.println(ans2); 37 | } 38 | else 39 | { 40 | System.out.println("No player is available with specified level, skill and eligibility points"); 41 | } 42 | 43 | } 44 | public static int findPointsForGivenSkill(PlayerIPA[]p,String s) 45 | { 46 | int sum = 0; 47 | for(int i=0; i0) 55 | { 56 | return sum; 57 | } 58 | else 59 | { 60 | return 0; 61 | } 62 | } 63 | public static int getPlayerBasedOnLevel(PlayerIPA[]p,String s, String l) 64 | { 65 | for(int i=0; i=20) 68 | { 69 | return p[i].getPlayerId(); 70 | } 71 | } 72 | return 0; 73 | } 74 | 75 | } 76 | class PlayerIPA 77 | { 78 | private int playerId; 79 | private String skill; 80 | private String level; 81 | private int points; 82 | 83 | public PlayerIPA(int playerId, String skill, String level, int points) 84 | { 85 | this.playerId = playerId; 86 | this.skill = skill; 87 | this.level = level; 88 | this.points = points; 89 | } 90 | 91 | public int getPlayerId() 92 | { 93 | return playerId; 94 | } 95 | public void setPlayerId(int playerId) 96 | { 97 | this.playerId = playerId; 98 | } 99 | public String getSkill() 100 | { 101 | return skill; 102 | } 103 | public void setSkill(String skill) 104 | { 105 | this.skill = skill; 106 | } 107 | public String getLevel() 108 | { 109 | return level; 110 | } 111 | public void setLevel(String level) 112 | { 113 | this.level = level; 114 | } 115 | public int getPoints() 116 | { 117 | return points; 118 | } 119 | public void setPoints(int points) 120 | { 121 | this.points = points; 122 | } 123 | } -------------------------------------------------------------------------------- /IPA11/IPA11.txt: -------------------------------------------------------------------------------- 1 | Create a class Player with below attributes: 2 | 3 | playerId - int 4 | skill - String 5 | level - String 6 | points - int 7 | 8 | Write getters, setters and parameterized constructor in the above mentioned attribute 9 | sequence as required. 10 | 11 | Create class Solution with the main method. 12 | 13 | Implement two static methods - findPointsForGivenSkill and getPlayerBasedOnLevel in Solution class. 14 | 15 | findPointsForGivenSkill method: 16 | ------------------------------------ 17 | This method will take two input parameters - array of Player objects 18 | and string parameter skill. The method will return the sum of the points attribute from player objects 19 | for the skill passed as parameter. If no player with the given skill is present in the array of player 20 | objects, then the method should return 0. 21 | 22 | getPlayerBasedOnLevel method: 23 | ------------------------------------- 24 | This method will take two String parameters level and skill, along with the array of Player objects. 25 | The method will return the player object, if the input String parameters matches with the level and 26 | skill attribute of the player object and its point attribute is greater than or equal to 20. If any 27 | of the conditions are not met, then the method should return null. 28 | 29 | Note : No two player object would have the same value for skill and level attribute. All player object 30 | would have the points greater than 0. All the searches should be case insensitive. 31 | 32 | These above mentioned static methods should be called from the main method. 33 | 34 | For findPointsForGivenSkill method - The main method should print the points as it is if the returned 35 | price is greater than 0, or it should print "The given Skill is not available". 36 | 37 | For getPlayerBasedOnLevel method - The main method should print the playerId of the returned player object. 38 | If the returned value is null then it should print "No player is available with specified level, skill 39 | and eligibility points". 40 | 41 | Before calling these static methods in main, use Scanner object to read the values of four Player objects 42 | referring attributes in the above mentioned attribute sequence. Next, read the value for skill and level. 43 | Please consider the skill value read above as skill parameter for both the static methods. 44 | 45 | Input: 46 | ----------- 47 | 101 48 | Cricket 49 | Basic 50 | 20 51 | 102 52 | Cricket 53 | Intermediate 54 | 25 55 | 111 56 | Football 57 | Intermediate 58 | 50 59 | 113 60 | BaseBall 61 | Advanced 62 | 100 63 | Cricket 64 | Intermediate 65 | 66 | Output: 67 | -------------- 68 | 45 69 | 102 -------------------------------------------------------------------------------- /IPA12/IPA12.java: -------------------------------------------------------------------------------- 1 | import java.util.*;; 2 | public class IPA12 { 3 | public static void main(String[] args) { 4 | Scanner sc = new Scanner(System.in); 5 | Medicine[] m = new Medicine[4]; 6 | for (int i = 0; i < m.length; i++) 7 | { 8 | String a = sc.nextLine(); 9 | String b = sc.nextLine(); 10 | String c = sc.nextLine(); 11 | int d = sc.nextInt();sc.nextLine(); 12 | 13 | m[i] = new Medicine(a,b,c,d); 14 | } 15 | String dis = sc.nextLine(); 16 | int[] ans = getPriceByDisease(m,dis); 17 | if(ans!=null) 18 | { 19 | for (int i = 0; i < ans.length; i++) { 20 | System.out.println(ans[i]); 21 | } 22 | } 23 | else{ 24 | System.out.println("No medicine found"); 25 | } 26 | } 27 | public static int[] getPriceByDisease(Medicine[] m, String dis) 28 | { 29 | int[] p = new int[0]; 30 | for (int i = 0; i < m.length; i++) { 31 | if(m[i].getDisease().equalsIgnoreCase(dis)) 32 | { 33 | p = Arrays.copyOf(p, p.length+1); 34 | p[p.length-1]=m[i].getPrice(); 35 | Arrays.sort(p); 36 | } 37 | } 38 | if(p.length>0) 39 | { 40 | return p; 41 | } 42 | else{ 43 | return null; 44 | } 45 | } 46 | } 47 | class Medicine 48 | { 49 | String name; 50 | String batch; 51 | String disease; 52 | int price; 53 | 54 | public Medicine(String name, String batch, String disease, int price) 55 | { 56 | this.name = name; 57 | this.batch = batch; 58 | this.disease = disease; 59 | this.price = price; 60 | } 61 | 62 | public String getName() 63 | { 64 | return name; 65 | } 66 | public void setName(String name) 67 | { 68 | this.name = name; 69 | } 70 | public String getBatch() 71 | { 72 | return batch; 73 | } 74 | public void setBatch(String batch) 75 | { 76 | this.batch = batch; 77 | } 78 | public String getDisease() 79 | { 80 | return disease; 81 | } 82 | public void setDisease(String disease) 83 | { 84 | this.disease = disease; 85 | } 86 | public int getPrice() 87 | { 88 | return price; 89 | } 90 | public void setPrice(int price) 91 | { 92 | this.price = price; 93 | } 94 | } -------------------------------------------------------------------------------- /IPA12/IPA12.txt: -------------------------------------------------------------------------------- 1 | Create class Medicine with below attributes: 2 | 3 | MedicineName - String 4 | batch - String 5 | disease - String 6 | price - int 7 | 8 | Create class Solution and implement static method "getPriceByDisease" in the Solution class. 9 | This method will take array of Medicine objects and a disease String as parameters. 10 | And will return another sorted array of Integer objects where the disease String matches with the 11 | original array of Medicine object's disease attribute (case insensitive search). 12 | 13 | Write necessary getters and setters. 14 | 15 | Before calling "getPriceByDisease" method in the main method, read values for four Medicine objects 16 | referring the attributes in above sequence along with a String disease. Then call the "getPriceByDisease" 17 | method and print the result. 18 | 19 | Input 20 | ------------- 21 | 22 | dolo650 23 | FAC124W 24 | fever 25 | 100 26 | paracetamol 27 | PAC545B 28 | bodypain 29 | 150 30 | almox 31 | ALM747S 32 | fever 33 | 200 34 | aspirin 35 | ASP849Q 36 | flu 37 | 250 38 | fever 39 | 40 | Output 41 | --------- 42 | 100 43 | 200 -------------------------------------------------------------------------------- /IPA13/IPA13.txt: -------------------------------------------------------------------------------- 1 | Create a class AutonomousCar with the below attributes: 2 | 3 | carld – int 4 | brand – String 5 | noOfTestsConducted – int 6 | noOfTestsPassed- int 7 | environment – String 8 | 9 | Write getters, setters for the above attributes . Create constructor which takes parameter in the above sequence 10 | except grade. 11 | 12 | Create class Solution with main method. Implement two static methods – findTestPassedByEnv and updateCarGrade in 13 | Solution class. 14 | 15 | findTestPassedByEnv method: 16 | 17 | This method will take two input parameters -array of AutonomousCar objects and string parameter environment. The method 18 | will return the sum of the noOfTestsPassed attribute from autonomousCar objects for the environment passed as parameter. 19 | If no autonomousCar with the given environment is present in the array of AutonomousCar objects, then the method should 20 | return 0. 21 | 22 | updateCarGrade method: 23 | 24 | This method will take a String parameter brand, along with the array of AutonomousCar objects. The method will return 25 | the autonomousCar object, if the input String parameter matches with the brand attribute of the autonomousCar object. 26 | Before returning the object, the grade should be derived based on the rating calculation mentioned below. This grade 27 | value should be assigned to the object. If any of the above conditions are not met, then the method should return null. 28 | The grade attribute should be calculated as follows: rating .(noOfTestsPassed * 100)/noOfTestsConducted 29 | If the rating > = 80 then grade should be ‘A1’, otherwise the grade should be ‘B2’. 30 | 31 | The above mentioned static methods should be called from the main method. For findTestPassedByEnv method – The main 32 | method should print the totalTestPassed as it is, if the returned value is greater than 0, or it should print “There 33 | are no tests passed in this particular environment”. 34 | 35 | For updateCarGrade method – The main method should print the brand and grade of the returned autonomousCar object. 36 | The brand and grade should be concatinated with :: while printing. eg:- Tesla::A1, where Tesla is the brand and Al 37 | is the grade. 38 | 39 | If the returned value is null then it should print “No Car is available with the specified brand”. Before calling these 40 | static methods in main, use Scanner object to read the values of four autonomousCar objects referring attributes in the 41 | above mentioned attribute sequence (except grade attribute). Next, read the value for environment and brand. 42 | 43 | Input 44 | ---------------- 45 | 100 46 | Tesla 47 | 1000 48 | 500 49 | Hills 50 | 200 51 | Ford 52 | 2000 53 | 1500 54 | Desert 55 | 300 56 | Royce 57 | 3000 58 | 1700 59 | Hills 60 | 400 61 | Mercedez 62 | 1000 63 | 400 64 | Desert 65 | Desert 66 | Mercedez 67 | 68 | Output 69 | ----------- 70 | 1900 71 | Mercedez::B2 -------------------------------------------------------------------------------- /IPA14/IPA14.java: -------------------------------------------------------------------------------- 1 | package IPA14; 2 | import java.util.*; 3 | public class IPA14 { 4 | public static void main(String[] args) { 5 | Scanner sc = new Scanner(System.in); 6 | Movie[] m = new Movie[4]; 7 | for (int i = 0; i < m.length; i++) { 8 | String a = sc.nextLine(); 9 | String b = sc.nextLine(); 10 | String c = sc.nextLine(); 11 | int d = sc.nextInt();sc.nextLine(); 12 | 13 | m[i] = new Movie(a,b,c,d); 14 | } 15 | String Search = sc.nextLine(); 16 | String[] ans1 = getMovieByGenre(m, Search); 17 | for (int i = 0; i < ans1.length; i++) { 18 | System.out.println(ans1[i]); 19 | } 20 | } 21 | public static String[] getMovieByGenre(Movie[] m, String s) 22 | { 23 | String[] arr = new String[0]; 24 | for (int i = 0; i < m.length; i++) { 25 | if(m[i].getGenre().equalsIgnoreCase(s)) 26 | { 27 | if(m[i].getBudget()>80000000) 28 | { 29 | arr = Arrays.copyOf(arr,arr.length+1); 30 | arr[arr.length-1]="High Budget Movie"; 31 | } 32 | else 33 | { 34 | arr = Arrays.copyOf(arr,arr.length+1); 35 | arr[arr.length-1]="Low Budget Movie"; 36 | } 37 | } 38 | } 39 | return arr; 40 | } 41 | } 42 | 43 | class Movie 44 | { 45 | String mname, company, genre; 46 | int budget; 47 | 48 | public Movie(String mname, String company, String genre, int budget) 49 | { 50 | this.mname = mname; 51 | this.company = company; 52 | this.genre = genre; 53 | this.budget = budget; 54 | } 55 | 56 | public String getMname() { 57 | return mname; 58 | } 59 | 60 | public void setMname(String mname) { 61 | this.mname = mname; 62 | } 63 | 64 | public String getCompany() { 65 | return company; 66 | } 67 | 68 | public void setCompany(String company) { 69 | this.company = company; 70 | } 71 | 72 | public String getGenre() { 73 | return genre; 74 | } 75 | 76 | public void setGenre(String genre) { 77 | this.genre = genre; 78 | } 79 | 80 | public int getBudget() { 81 | return budget; 82 | } 83 | 84 | public void setBudget(int budget) { 85 | this.budget = budget; 86 | } 87 | 88 | 89 | } 90 | 91 | -------------------------------------------------------------------------------- /IPA14/IPA14.txt: -------------------------------------------------------------------------------- 1 | Create class Movie with below attributes: 2 | 3 | movieName - String 4 | company - String 5 | genre - String 6 | budget - int 7 | 8 | Create class Solution and implement static method "getMovieByGenre" in the Solution class. This method will 9 | take array of Movie objects and a searchGenre String as parameters. And will return another array of Movie 10 | objects where the searchGenre String matches with the original array of Movie object's genre attribute 11 | (case insensitive search). 12 | 13 | Write necessary getters and setters. 14 | 15 | Before calling "getMovieByGenre" method in the main method, read values for four Movie objects referring the 16 | attributes in above sequence along with a String searchGenre. Then call the "getMovieByGenre" method and write 17 | logic in main method to print "High Budget Movie",if the movie budget attribute is greater than 80000000 else 18 | print "Low Budget Movie". 19 | 20 | Input 21 | --------- 22 | aaa 23 | Marvel 24 | Action 25 | 250000000 26 | bbb 27 | Marvel 28 | Comedy 29 | 25000000 30 | ccc 31 | Marvel 32 | Comedy 33 | 2000000 34 | ddd 35 | Marvel 36 | Action 37 | 300000000 38 | Action 39 | 40 | Output 41 | ------------------- 42 | High Budget Movie 43 | High Budget Movie -------------------------------------------------------------------------------- /IPA15/IPA15.txt: -------------------------------------------------------------------------------- 1 | Create a class Phone with below attributes: 2 | 3 | phoneId - int 4 | os - String 5 | brand - String 6 | price - int 7 | 8 | Write getters, setters and parameterized constructor in the above mentioned attribute sequence as required. 9 | 10 | Create class Solution with main method. 11 | 12 | Implement two static methods - findPriceForGivenBrand and getPhoneIdBasedOnOs in Solution class. 13 | 14 | findPriceForGivenBrand method: 15 | ---------------------------------- 16 | This method will take two input parameters - array of Phone objects and string 17 | parameter brand. The method will return the sum of the price attribute from phone objects for the brand passed 18 | as parameter. If no phones with the given brand is present in the array of phone objects, then the method should 19 | return 0. 20 | 21 | getPhoneIdBasedOnOs method: 22 | ---------------------------------- 23 | This method will take a String parameter os, along with the array of Phone objects. 24 | The method will return the phone object, if the input String parameter matches with the os attribute of the phone 25 | object and its price attribute is greater than or equal to 50000. If any of the conditions are not met, then the 26 | method should return null. 27 | 28 | Note : No phone object would have the same value for os attribute. All phone object would have the price greater than 0. 29 | All the searches should be case insensitive. 30 | 31 | These above mentioned static methods should be called from the main method. 32 | 33 | For findPriceForGivenBrand method - The main method should print the price as it is if the returned price is greater 34 | than 0, or it should print "The given Brand is not available". 35 | 36 | For getPhoneIdBasedOnOs method - The main method should print the phoneId of the returned phone object. If the returned 37 | value is null then it should print "No phones are available with specified os and price range". 38 | 39 | Before calling these static methods in main, use Scanner object to read the values of four Phone objects referring 40 | attributes in the above mentioned attribute sequence. Next, read the value for brand and os. 41 | 42 | Input 43 | -------------- 44 | 111 45 | iOS 46 | Apple 47 | 30000 48 | 222 49 | android 50 | Samsung 51 | 50000 52 | 333 53 | Symbian 54 | HTC 55 | 12000 56 | 444 57 | Paranoid 58 | HTC 59 | 89000 60 | Blackberry 61 | aNdRoid 62 | 63 | Output 64 | ------------------ 65 | The given Brand is not available 66 | 222 -------------------------------------------------------------------------------- /IPA16/IPA16.txt: -------------------------------------------------------------------------------- 1 | Create a class NavalVessel with the below attributes: 2 | 3 | vesselld – int 4 | vesselName – String 5 | noOfVoyagesPlanned – int 6 | noOfVoyagesCompleted – int 7 | purpose – String 8 | 9 | 10 | Write getters, setters for the above attributes. Create constructor which takes parameter in the above 11 | sequence except classification. 12 | 13 | Create class Solution with main method. Implement two static methods – findAvgVoyagesByPct and findVesselByGrade 14 | in Solution class. 15 | 16 | findAvgVoyagesByPct method: 17 | 18 | This method will take two input parameters -array of NavalVessel objects and int parameter percentage. The method will 19 | return the average of the noOfVoyagesCompleted attribute from NavalVessel objects which meets the percentage requirement 20 | as mentioned below.The percentage for each navalVessel is calculated as 21 | percentage .(noOfVoyagesCompleted * 100)/noOfVoyagesPlanned. If the above calculated percentage is greater than or equal 22 | to the percentage passed as the parameter, then those objects should participate in the average calculation. If there are 23 | no objects with the mentioned criteria, then the method should return 0. 24 | 25 | findVesselByGrade method: 26 | 27 | This method will take a String parameter purpose, along with the array of NavalVessel objects. The method will return the 28 | NavalVessel object, if the input String parameter matches with the purpose attribute of the NavalVessel object. Before 29 | returning the object, the classification should be derived as mentioned below. This classification value should be assigned 30 | to the object before returning. If any of the above conditions are not met, then the method should return null. The 31 | classification attribute should be calculated based on the percentage calculation mentioned above. 32 | If the percentage = 100 then classification should be ‘Star’, if percentage is between 99 and 80 then classification should 33 | be ‘Leader, if percentage is between 79 and 55 then classification should be ‘Inspirer' otherwise the classification should 34 | be ‘Striver’ If the returned value is null then it should print “No Naval Vessel is available with the specified purpose”. 35 | 36 | Before calling these static methods in main, use Scanner object to read the values of four NavalVessel objects referring 37 | attributes in the above mentioned attribute sequence (except the classification attribute). Next, read the value for 38 | percentage and purpose. 39 | 40 | Input 41 | ------------------- 42 | 111 43 | Rojer 44 | 100 45 | 100 46 | Passenger 47 | 222 48 | Kalam 49 | 200 50 | 100 51 | Goods 52 | 333 53 | Yashwin 54 | 400 55 | 300 56 | Army 57 | 444 58 | Thanishwini 59 | 500 60 | 500 61 | Welfare 62 | 75 63 | Army 64 | 65 | Output 66 | ------------------ 67 | 300 68 | Yashwin%Inspirer -------------------------------------------------------------------------------- /IPA17/IPA17.txt: -------------------------------------------------------------------------------- 1 | Create a class Student with below attributes: 2 | 3 | rollNo - int 4 | name - String 5 | subject - String 6 | grade - char 7 | date - String [DD/MM/YYYY] 8 | 9 | 10 | 11 | The above attributes should be private.Write Getter and Setter and parametrized constructor as required. 12 | 13 | 14 | Create class Solution with main method. 15 | **************************************************************************** 16 | Implement one static method: findStudentByGradeAndMonth Solution Class. 17 | 18 | 19 | findStudentByGradeAndMonth Method: 20 | 21 | This method will take an array of Student objects, char value as grade and int value as month 22 | for input parameters.The method will find out all Students from the given grade and month. 23 | This method will return array of Student object assending based on their rollNo if found. 24 | If there is no Student that matches then the method should return null. 25 | 26 | for this method- main method should print Student name, subject and total student found [The 27 | length of the list], if the returned value is not null. If the returned value is null then 28 | main method should print "No student found". 29 | 30 | 31 | NOTE: 32 | 1. For Taking char as input use sc.nextLine().charAt(0) 33 | 2. To match/check the month You havee to convert int month in the parameter to String. 34 | 3. No need to count the Student array if return not null just print the array length. 35 | 36 | 37 | **************************************************************************** 38 | 39 | 40 | 41 | Consider the below input and output: 42 | 43 | 44 | input1: 45 | 46 | 111 47 | Arijit 48 | Math 49 | B 50 | 22/09/2023 51 | 101 52 | Priyanka 53 | English 54 | A 55 | 30/03/2022 56 | 107 57 | Shreosi 58 | History 59 | C 60 | 13/05/2022 61 | 105 62 | Tatan 63 | Physics 64 | A 65 | 27/03/2022 66 | A 67 | 3 68 | 69 | 70 | output1: 71 | 72 | Priyanka 73 | English 74 | Tatan 75 | Physics 76 | 2 77 | 78 | 79 | 80 | 81 | 82 | input2: 83 | 84 | 111 85 | Sohel 86 | Math 87 | B 88 | 22/09/2022 89 | 101 90 | Priyanka 91 | English 92 | A 93 | 30/03/2022 94 | 107 95 | Gopa 96 | History 97 | C 98 | 12/05/2022 99 | 105 100 | Kamal 101 | Physics 102 | A 103 | 27/03/2022 104 | A 105 | 7 106 | 107 | 108 | 109 | output 2: 110 | 111 | No student found 112 | 113 | -------------------------------------------------------------------------------- /IPA18/IPA18.txt: -------------------------------------------------------------------------------- 1 | create a class Antenna with below attributes. 2 | antennaid=int 3 | antennaName=String 4 | projectLead=String 5 | antennaVSWR=double 6 | 7 | the above attribute should be private ,write getter and setter and parametrized constructor as well. 8 | 9 | create class MyClass with main method. 10 | implement two static methods searchAntennaByName and sortAntennaByVSWR in MyClass class. 11 | 12 | 13 | searchAntennaByName : 14 | --------------------------------------- 15 | This method will take an array of Antenna objects and the string value as input parameter.The method will find out Antenna name(String parameterpassed). 16 | It will return Antennaid if found.if there is no Antenna that matches then the method will return zero. 17 | The main method should print the antennaid,if the returned value is not 0.if the returned value is 0 then print,"There is no antenna with the given parameter". 18 | 19 | 20 | sortAntennaByVSWR: 21 | -------------------------------------- 22 | This method will take an array of Antenna Objects and a double value as input. 23 | This method will return an array of Antenna objects sorted in ascending orderof their antennaVSWR, which is less than VSWR(double value passed). 24 | 25 | The main method should print name of the project leads from the returned array if the returned value is not null.if the returned value is null then main method 26 | should print "No Antenna found"; 27 | 28 | 29 | input1: 30 | 31 | 111 32 | Reconfigurable 33 | Hema 34 | 0.4 35 | 222 36 | Wearable 37 | Kavya 38 | 0.9 39 | 333 40 | Microstrip 41 | Teju 42 | 0.3 43 | 444 44 | Dielectric 45 | Sai 46 | 0.65 47 | Microstrip 48 | 0.5 49 | 50 | output: 51 | 333 52 | Teju 53 | Hema 54 | 55 | 56 | input 2: 57 | 111 58 | Reconfigurable 59 | Hema 60 | 0.3 61 | 222 62 | Wearable 63 | Kavya 64 | 0.9 65 | 333 66 | Microstrip 67 | Teju 68 | 0.4 69 | 444 70 | Dielectric 71 | Sai 72 | 0.65 73 | Resonator 74 | 0.25 75 | 76 | output: 77 | There is no antenna with given parameter 78 | No Antenna found 79 | -------------------------------------------------------------------------------- /IPA19/IPA19.java: -------------------------------------------------------------------------------- 1 | package IPA19; 2 | import java.util.*; 3 | public class IPA19 4 | { 5 | public static void main(String[]args) 6 | { 7 | Scanner sc = new Scanner(System.in); 8 | Flower[] fl = new Flower[4]; 9 | for(int i=0; i<4; i++) 10 | { 11 | int a = sc.nextInt();sc.nextLine(); 12 | String b = sc.nextLine(); 13 | int c = sc.nextInt();sc.nextLine(); 14 | int d = sc.nextInt();sc.nextLine(); 15 | String e = sc.nextLine(); 16 | 17 | fl[i] = new Flower(a,b,c,d,e); 18 | } 19 | String f = sc.nextLine(); 20 | int id = findMinPriceByType(fl,f); 21 | if(id!=0) 22 | { 23 | System.out.println(id); 24 | } 25 | else 26 | { 27 | System.out.println("There is no flower with given type"); 28 | } 29 | } 30 | public static int findMinPriceByType(Flower[] fl, String s) 31 | { 32 | Flower[] arr = new Flower[0]; 33 | for(int i =0; i3) 36 | { 37 | arr = Arrays.copyOf(arr,arr.length+1); 38 | arr[arr.length-1] = fl[i]; 39 | } 40 | } 41 | if(arr.length>0) 42 | { 43 | Flower mini = arr[0]; 44 | for (int j = 1; j < arr.length; j++) 45 | { 46 | if(mini.getPrice()>arr[j].getPrice()) 47 | { 48 | mini = arr[j]; 49 | } 50 | } 51 | return mini.getFlowerId(); 52 | } 53 | return 0; 54 | } 55 | } 56 | class Flower 57 | { 58 | private int flowerId; 59 | private String flowerName; 60 | private int price; 61 | private int rating; 62 | private String type; 63 | 64 | public Flower(int flowerId, String flowerName, int price, int rating, String type) 65 | { 66 | this.flowerId = flowerId; 67 | this.flowerName= flowerName; 68 | this.price = price; 69 | this.rating = rating; 70 | this.type = type; 71 | } 72 | 73 | public int getFlowerId() 74 | { 75 | return flowerId; 76 | } 77 | public void setFlowerId(int flowerId) 78 | { 79 | this.flowerId = flowerId; 80 | } 81 | public String getFlowerName() 82 | { 83 | return flowerName; 84 | } 85 | public void setFlowerName(String flowerName) 86 | { 87 | this.flowerName = flowerName; 88 | } 89 | public int getPrice() 90 | { 91 | return price; 92 | } 93 | public void setPrice(int price) 94 | { 95 | this.price = price; 96 | } 97 | public int getRating() 98 | { 99 | return rating; 100 | } 101 | public void setRating(int rating) 102 | { 103 | this.rating = rating; 104 | } 105 | public String getType() 106 | { 107 | return type; 108 | } 109 | public void setType(String type) 110 | { 111 | this.type = type; 112 | } 113 | } 114 | -------------------------------------------------------------------------------- /IPA19/IPA19.txt: -------------------------------------------------------------------------------- 1 | Create the class Flowers with below attribute: 2 | 3 | flowerId-int; 4 | flowerName-String; 5 | price-int; 6 | rating-int; 7 | type-String; 8 | 9 | The above attributes must be private,write getters and setters and parametrized constructor as well. 10 | 11 | Create class MyClass with main method. 12 | 13 | Implement one static method:findMinPriceByType in MyClass class. 14 | 15 | findMinPriceByType Method: 16 | 17 | This method will take two input parameters:Array of Flower objects and String parameter.This method will return the minimum 18 | priced flower object from array of Flower objects for the given type(String parameter),only if the rating is greater than 19 | 3. If no Flowers with the above conditions are present in the array of the flower objects,then the method will return null. 20 | 21 | For this method-The main method should print the flowerId from the returned object if the returned value is not null. 22 | else it should print "There is no flower with given type". 23 | 24 | ********************************************************************** 25 | 26 | input1: 27 | 28 | 123 29 | Yellow trout lilly 30 | 3000 31 | 5 32 | ephemerals 33 | 345 34 | snowdrop 35 | 2500 36 | 4 37 | ephemerals 38 | 321 39 | Yarrow 40 | 1000 41 | 4 42 | perennials 43 | 213 44 | red trillium 45 | 2250 46 | 4 47 | ephemerals 48 | ephemerals 49 | 50 | 51 | 52 | output: 53 | 54 | 213 55 | 56 | 57 | 58 | 59 | 60 | ********************** 61 | 62 | input2: 63 | 64 | 123 65 | 66 | Yellow trout lilly 67 | 68 | 3000 69 | 70 | 5 71 | 72 | ephemerals 73 | 74 | 345 75 | 76 | snowdrop 77 | 78 | 2500 79 | 80 | 4 81 | 82 | ephemerals 83 | 84 | 321 85 | 86 | Yarrow 87 | 88 | 1000 89 | 90 | 4 91 | 92 | perennials 93 | 94 | 213 95 | 96 | red trillium 97 | 98 | 2250 99 | 100 | 4 101 | 102 | ephemerals 103 | 104 | Biennial 105 | 106 | 107 | output2: 108 | 109 | There is no flower with given type. -------------------------------------------------------------------------------- /IPA2/footwearProgram.java: -------------------------------------------------------------------------------- 1 | package IPA2; 2 | import java.util.*; 3 | public class footwearProgram 4 | { 5 | public static void main(String[]args) 6 | { 7 | Scanner sc = new Scanner(System.in); 8 | Footwear[] ft = new Footwear[5]; 9 | for(int i=0; i<5; i++) 10 | { 11 | int a = sc.nextInt();sc.nextLine(); 12 | String b = sc.nextLine(); 13 | String c = sc.nextLine(); 14 | int d = sc.nextInt();sc.nextLine(); 15 | 16 | ft[i]=new Footwear(a,b,c,d); 17 | } 18 | 19 | String ftType = sc.nextLine(); 20 | String ftName = sc.nextLine(); 21 | int count = getCountByType(ft,ftType); 22 | if(count>0) 23 | { 24 | System.out.println(count); 25 | } 26 | else 27 | { 28 | System.out.println("Footwear not avaliable"); 29 | } 30 | 31 | Footwear obj = getSecondHighestPriceByBrand(ft, ftName); 32 | if(obj!=null) 33 | { 34 | System.out.println(obj.getId()); 35 | System.out.println(obj.getName()); 36 | System.out.println(obj.getPrice()); 37 | } 38 | else 39 | { 40 | System.out.println("Brand not available"); 41 | } 42 | 43 | } 44 | 45 | public static int getCountByType(Footwear[] ft, String t) 46 | { 47 | int count = 0; 48 | for(int i=0; i0) 56 | { 57 | return count; 58 | } 59 | else 60 | { 61 | return 0; 62 | } 63 | } 64 | 65 | public static Footwear getSecondHighestPriceByBrand(Footwear[] ft, String name) 66 | { 67 | for(int i =0; ir) 35 | { 36 | if(ft[i].getPrice()>max) 37 | { 38 | max = ft[i].getPrice(); 39 | } 40 | } 41 | } 42 | for(int i=0; i0) 37 | { 38 | return arr; 39 | } 40 | else 41 | { 42 | return null; 43 | } 44 | } 45 | } 46 | 47 | class Associate 48 | { 49 | private int id; 50 | private String name; 51 | private String tech; 52 | private int year; 53 | 54 | public Associate(int id, String name, String tech, int year) { 55 | this.id = id; 56 | this.name = name; 57 | this.tech = tech; 58 | this.year = year; 59 | } 60 | public int getId() { 61 | return id; 62 | } 63 | public void setId(int id) { 64 | this.id = id; 65 | } 66 | public String getName() { 67 | return name; 68 | } 69 | public void setName(String name) { 70 | this.name = name; 71 | } 72 | public String getTech() { 73 | return tech; 74 | } 75 | public void setTech(String tech) { 76 | this.tech = tech; 77 | } 78 | public int getYear() { 79 | return year; 80 | } 81 | public void setYear(int year) { 82 | this.year = year; 83 | } 84 | 85 | 86 | } -------------------------------------------------------------------------------- /IPA22/IPA22.txt: -------------------------------------------------------------------------------- 1 | Create class Associate with below attributes: 2 | id - int 3 | name - String 4 | technology - String 5 | experienceInYears - int 6 | 7 | Create class Solution and implement static method "associatesForGivenTechnology" in the Solution class. 8 | This method will take array of Associate objects and a searchTechnology String as parameters. 9 | And will return another array of Associate objects where the searchTechnology String matches with the original array of 10 | Associate object's technology attribute (case insensitive search) and experienceInYears attribute should be multiples of 5. 11 | 12 | Write necessary getters and setters. 13 | 14 | Before calling "associatesForGivenTechnology" method in the main method, read values for five associate objects referring 15 | the attributes in above sequence along with a String searchTechnology. 16 | Then call the "associatesForGivenTechnology" method and write the logic to print the id's in the main method. 17 | 18 | Input 19 | ----------------- 20 | 101 21 | Alex 22 | Java 23 | 15 24 | 102 25 | Albert 26 | Unix 27 | 20 28 | 103 29 | Alferd 30 | Testing 31 | 13 32 | 104 33 | Alfa 34 | Java 35 | 15 36 | 105 37 | Almas 38 | Java 39 | 29 40 | Java 41 | 42 | Output 43 | ------------------ 44 | 101 45 | 104 -------------------------------------------------------------------------------- /IPA24/IPA24.java: -------------------------------------------------------------------------------- 1 | package IPA24; 2 | import java.util.*; 3 | public class IPA24 4 | { 5 | public static void main(String[] args) { 6 | Scanner sc= new Scanner(System.in); 7 | Inventory[] in = new Inventory[4]; 8 | for (int i = 0; i < in.length; i++) { 9 | String a = sc.nextLine(); 10 | int b = sc.nextInt();sc.nextLine(); 11 | int c = sc.nextInt();sc.nextLine(); 12 | int d = sc.nextInt();sc.nextLine(); 13 | 14 | in[i] = new Inventory(a, b, c, d); 15 | } 16 | int lim = sc.nextInt(); 17 | Inventory[] ans = Replenish(in,lim); 18 | if(ans!=null) 19 | { 20 | for (int i = 0; i < ans.length; i++) { 21 | if(ans[i].getTh()>75) 22 | { 23 | System.out.println(ans[i].getId()+" Critical Falling"); 24 | } 25 | else if(ans[i].getTh()>=50 && ans[i].getTh()<=75) 26 | { 27 | System.out.println(ans[i].getId()+" Moderate Filling"); 28 | } 29 | else 30 | { 31 | System.out.println(ans[i].getId()+" Non-Critical Filling"); 32 | } 33 | } 34 | } 35 | } 36 | public static Inventory[] Replenish(Inventory[] in, int lim) 37 | { 38 | Inventory[] arr = new Inventory[0]; 39 | for (int i = 0; i < in.length; i++) { 40 | if(lim>=in[i].getTh()) 41 | { 42 | arr = Arrays.copyOf(arr,arr.length+1); 43 | arr[arr.length-1] = in[i]; 44 | } 45 | } 46 | if(arr.length>0) 47 | { 48 | return arr; 49 | } 50 | else 51 | { 52 | return null; 53 | } 54 | } 55 | } 56 | 57 | class Inventory 58 | { 59 | private String id; 60 | private int max, cur, th; 61 | public Inventory(String id, int max, int cur, int th) { 62 | this.id = id; 63 | this.max = max; 64 | this.cur = cur; 65 | this.th = th; 66 | } 67 | public String getId() { 68 | return id; 69 | } 70 | public void setId(String id) { 71 | this.id = id; 72 | } 73 | public int getMax() { 74 | return max; 75 | } 76 | public void setMax(int max) { 77 | this.max = max; 78 | } 79 | public int getCur() { 80 | return cur; 81 | } 82 | public void setCur(int cur) { 83 | this.cur = cur; 84 | } 85 | public int getTh() { 86 | return th; 87 | } 88 | public void setTh(int th) { 89 | this.th = th; 90 | } 91 | 92 | 93 | } -------------------------------------------------------------------------------- /IPA24/IPA24.txt: -------------------------------------------------------------------------------- 1 | Create class Inventory with below attributes: 2 | 3 | inventoryId - String 4 | maximumQuantity - int 5 | currentQuantity - int 6 | threshold - int 7 | 8 | Create class Solution and implement static method "Replenish" in the Solution class. 9 | This method will take array of Inventory objects and a limit int as parameters. 10 | And will return another array of Inventory objects where the limit int is greater than or equal to the original array of 11 | Inventory object's threshold attribute. 12 | 13 | Write necessary getters and setters. 14 | 15 | Before calling "Replenish" method in the main method, read values for four Inventory objects referring the attributes in above 16 | sequence along with a int limit.Then call the "Replenish" method and write logic in main method to print "Critical Filling", 17 | if the threshold attribute is greater than 75. Else if the threshold attribute is between 50 and 75 then print 18 | "Moderate Filling". Else print "Non-Critical Filling" 19 | 20 | Input 21 | --------------------------- 22 | 1 23 | 100 24 | 50 25 | 50 26 | 2 27 | 200 28 | 60 29 | 40 30 | 3 31 | 150 32 | 35 33 | 45 34 | 4 35 | 80 36 | 45 37 | 40 38 | 45 39 | 40 | Output 41 | ---------------------------- 42 | 2 Non-Critical Filling 43 | 3 Non-Critical Filling 44 | 4 Non-Critical Filling -------------------------------------------------------------------------------- /IPA25/IPA25.txt: -------------------------------------------------------------------------------- 1 | Create a class Cinema with the below attributes: 2 | 3 | movieId - int 4 | director - String 5 | rating - int 6 | budget - int 7 | 8 | Write getters, setters and parameterized constructor in the above mentioned attribute sequence as required. 9 | 10 | Create class Solution with the main method. 11 | 12 | Implement two static methods - findAvgBudgetByDirector and getMovieByRatingBudget in Solution class. 13 | 14 | findAvgBudgetByDirector method: 15 | ---------------------------------- 16 | This method will take two input parameters - array of Movie objects and string parameter director. 17 | The method will return the average of the budget attribute from Movie objects directed by the director passed as parameter. 18 | If no movie with the given director is present in the array of movie objects, then the method should return 0. 19 | 20 | getMovieByRatingBudget method: 21 | ---------------------------------- 22 | This method will take two int parameters rating and budget, along with the array of movie objects. 23 | The method will return the movie object, if the input parameters rating and budget, matches with the rating and budget 24 | attribute of the movie object respectively. 25 | 26 | Also check if rating is a factor of budget (eg: 3 is a factor of 12 because 3 divides 12 without leaving a remainder). 27 | If any of the conditions are not met, then the method should return null. 28 | 29 | Note : No two movie object would have the same value for rating and budget attributes. 30 | All the searches should be case insensitive. 31 | The budget mentioned are in crores and in INR. 32 | 33 | These above mentioned static methods should be called from the main method. 34 | 35 | For findAvgBudgetByDirector method - The main method should print the average budget as it is if the returned value is 36 | greater than 0, or it should print "Sorry - The given director has not yet directed any movie". 37 | 38 | For getMovieByRatingBudget method - The main method should print the movieId of the returned movie object. If the returned 39 | value is null then it should print "Sorry - No movie is available with the specified rating and budget requirement". 40 | 41 | Before calling these static methods in main, use Scanner object to read the values of four Movie objects referring attributes 42 | in the above mentioned attribute sequence. Next, read the value for director, rating and budget. 43 | 44 | Input 45 | ---------- 46 | 1101 47 | GVM 48 | 4 49 | 100 50 | 1201 51 | Shankar 52 | 5 53 | 500 54 | 1301 55 | Shankar 56 | 3 57 | 50 58 | 1401 59 | GVM 60 | 5 61 | 300 62 | GVM 63 | 5 64 | 300 65 | 66 | Output 67 | ---------- 68 | 200 69 | 1401 -------------------------------------------------------------------------------- /IPA26/IPA26.txt: -------------------------------------------------------------------------------- 1 | Create class Player2 with below attributes: 2 | 3 | id - int 4 | name - String 5 | iccRank - int 6 | matchesPlayed - int 7 | runsScored - int 8 | 9 | Create class Solution and implement static method "findAverageOfRuns" in the Solution class. 10 | This method will take array of Player objects and a target int as parameters. 11 | And will return another double array where the target int is lesser than or equal to the original array of Player object's 12 | matchesPlayed attribute and contains the average run scored by each player satisfying above condition. 13 | 14 | Write necessary getters and setters. 15 | 16 | Before calling "findAverageOfRuns" method in the main method, read values for four Player objects referring the attributes 17 | in above sequence along with a int target. 18 | Then call the "findAverageOfRuns" method and write logic in main method to print "Grade A",if the calculated averageRun 19 | value is 80 to 100. Else if the averageRun value is between 50 and 79 then print "Grade B". Else print "Grade C". 20 | 21 | Input 22 | ------------------ 23 | 100 24 | Sachin 25 | 5 26 | 150 27 | 13000 28 | 101 29 | Sehwag 30 | 4 31 | 120 32 | 10000 33 | 103 34 | Dhoni 35 | 7 36 | 110 37 | 7000 38 | 104 39 | Kohli 40 | 15 41 | 57 42 | 4400 43 | 100 44 | 45 | Output 46 | -------------------- 47 | Grade A 48 | Grade A 49 | Grade B -------------------------------------------------------------------------------- /IPA27/IPA27.txt: -------------------------------------------------------------------------------- 1 | Create class Sim2 with below attributes: 2 | 3 | id - int 4 | company - String 5 | balance - int 6 | ratePerSecond - double 7 | circle - String 8 | 9 | Create class Solution and implement static method "matchAndSort" in the Solution class. 10 | 11 | This method will take array of Sim objects, search_circle String and search_rate double as parameters. 12 | And will return another Sim array where the search_circle matches with the circle parameter of the original Sim array and 13 | the search_rate double is greater than the original array of Sim object's ratePerSecond attribute which is also sorted by 14 | means of balance attribute in descending order. 15 | 16 | Write necessary getters and setters. 17 | 18 | Before calling "matchAndSort" method in the main method, read values for four Sim objects referring the attributes in above 19 | sequence along with a String search_circle and a double search_rate. Then call the "matchAndSort" method and write logic in 20 | main method to print the id's of the result obtained. 21 | 22 | Input 23 | -------------------------- 24 | 1 25 | jio 26 | 430 27 | 1.32 28 | mumbai 29 | 2 30 | idea 31 | 320 32 | 2.26 33 | mumbai 34 | 3 35 | airtel 36 | 500 37 | 2.54 38 | mumbai 39 | 4 40 | vodafone 41 | 640 42 | 3.21 43 | mumbai 44 | mumbai 45 | 3.4 46 | 47 | Output 48 | -------------------------- 49 | 4 50 | 3 51 | 1 52 | 2 -------------------------------------------------------------------------------- /IPA28/IPA28.java: -------------------------------------------------------------------------------- 1 | package IPA28; 2 | import java.util.Scanner; 3 | public class IPA28 { 4 | public static void main(String[] args) { 5 | Scanner sc = new Scanner(System.in); 6 | int n = sc.nextInt();sc.nextLine(); 7 | Team[] t = new Team[n]; 8 | for (int i = 0; i < t.length; i++) { 9 | int a = sc.nextInt();sc.nextLine(); 10 | String b = sc.nextLine(); 11 | String c = sc.nextLine(); 12 | int d = sc.nextInt(); 13 | 14 | t[i] = new Team(a,b,c,d); 15 | } 16 | int r = sc.nextInt();sc.nextLine(); 17 | String con = sc.nextLine(); 18 | Team ans = findPlayer(t,r,con); 19 | if(ans!=null) 20 | { 21 | System.out.println(ans.gettId()); 22 | System.out.println(ans.gettName()); 23 | System.out.println(ans.gettCountry()); 24 | System.out.println(ans.gettRun()); 25 | } 26 | else 27 | { 28 | System.out.println("No team is found from the given country and run"); 29 | } 30 | } 31 | public static Team findPlayer(Team[] t, int r, String c) 32 | { 33 | for (int i = 0; i < t.length; i++) { 34 | if(t[i].gettCountry().equalsIgnoreCase(c) && t[i].gettRun()>r) 35 | { 36 | return t[i]; 37 | } 38 | } 39 | return null; 40 | } 41 | } 42 | class Team 43 | { 44 | private int tId; 45 | private String tName; 46 | private String tCountry; 47 | private int tRun; 48 | public Team(int tId, String tName, String tCountry, int tRun) { 49 | this.tId = tId; 50 | this.tName = tName; 51 | this.tCountry = tCountry; 52 | this.tRun = tRun; 53 | } 54 | public int gettId() { 55 | return tId; 56 | } 57 | public void settId(int tId) { 58 | this.tId = tId; 59 | } 60 | public String gettName() { 61 | return tName; 62 | } 63 | public void settName(String tName) { 64 | this.tName = tName; 65 | } 66 | public String gettCountry() { 67 | return tCountry; 68 | } 69 | public void settCountry(String tCountry) { 70 | this.tCountry = tCountry; 71 | } 72 | public int gettRun() { 73 | return tRun; 74 | } 75 | public void settRun(int tRun) { 76 | this.tRun = tRun; 77 | } 78 | 79 | } -------------------------------------------------------------------------------- /IPA28/IPA28.txt: -------------------------------------------------------------------------------- 1 | Create class Team with below attributes: 2 | 3 | tId - int 4 | tName - String 5 | tCountry - String 6 | tRun - int 7 | 8 | The above attributes should be private.Write Getter and Setter and parametrized constructor as required. 9 | 10 | Create class Solution with main method. 11 | 12 | Implement One static method- 13 | 14 | ● findPlayer 15 | 16 | findPlayer in the solution class. 17 | This method will take array of Team objects, int paramater run and String country and returns the Team object where taken 18 | country is matched with the country of team object and team run is greater than the taken run. 19 | 20 | Write code to perform following tasks: 21 | 22 | 1. In main mehod, take 1st input as integer parameter which shows the number of team object. 23 | 2. Take necessary input variable and call findPlayer. 24 | 3. All searches should be case insensitive. 25 | 26 | For this method- The main method should print the team object. As if the returned value is not null, 27 | or it should print "No team is found from the given country and run". 28 | 29 | Input 30 | ------------------ 31 | 3 32 | 1 33 | Arijit 34 | India 35 | 43 36 | 2 37 | Doremon 38 | China 39 | 40 40 | 3 41 | Donal 42 | England 43 | 32 44 | 35 45 | China 46 | 47 | 48 | 49 | Output 50 | -------------- 51 | 2 52 | Doremon 53 | China 54 | 40 -------------------------------------------------------------------------------- /IPA29/Calculate_Interest.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | public class Calculate_Interest 3 | { 4 | public static void main(String[] args) 5 | { 6 | Scanner sc = new Scanner(System.in); 7 | 8 | int a = sc.nextInt();sc.nextLine(); 9 | double b = sc.nextDouble();sc.nextLine(); 10 | double c = sc.nextDouble();sc.nextLine(); 11 | Account ac = new Account(a,b,c); 12 | 13 | int n = sc.nextInt(); 14 | 15 | double interest = calculateInterest(ac, n); 16 | 17 | System.out.format("%.3f",interest); 18 | 19 | } 20 | public static double calculateInterest(Account ac, int n) 21 | { 22 | double per = (ac.getInterestRate()/100)*n; 23 | per = ac.getInterestRate()+per; 24 | return per; 25 | } 26 | } 27 | class Account 28 | { 29 | int id; 30 | double balance; 31 | double interestRate; 32 | 33 | public Account(int id, double balance, double interestRate) 34 | { 35 | this.id = id; 36 | this.balance = balance; 37 | this.interestRate = interestRate; 38 | } 39 | 40 | public int getId() 41 | { 42 | return id; 43 | } 44 | public void setId(int id) 45 | { 46 | this.id = id; 47 | } 48 | public double getBalance() 49 | { 50 | return balance; 51 | } 52 | public void setBalance(double balance) 53 | { 54 | this.balance = balance; 55 | } 56 | public double getInterestRate() 57 | { 58 | return interestRate; 59 | } 60 | public void setInterestRate(double interestRate) 61 | { 62 | this.interestRate = interestRate; 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /IPA29/Question_Calculate_Interest.txt: -------------------------------------------------------------------------------- 1 | Find total interest of an amount. 2 | 3 | Create a class Account with following attributes : 4 | id - int 5 | balance - double 6 | interestRate - double 7 | 8 | Take another integer as number of year. 9 | After that calculate total interest using formula: 10 | 11 | Percentage = interestRate * 100 / time 12 | Total Interest = Percentage + interestRate -------------------------------------------------------------------------------- /IPA3/IPA3.txt: -------------------------------------------------------------------------------- 1 | Create a class called Student with the below attributes: 2 | 3 | rollNo - int 4 | name - String 5 | branch - String 6 | score - double 7 | dayScholar - boolean 8 | 9 | The above attributes should be private, write getters, setters and parameterized constructor as required. 10 | 11 | Create class Solution with main method. 12 | Implement two static methods -findCountOfDayscholarStudents and findStudentwithSecondHighestScore in Solution 13 | class. 14 | 15 | findCountOfDayscholarStudents: 16 | 17 | This method will take an array of Student objects as an input parameter . This method will calculate and return 18 | the count of Students whose score is greater than 80 and who are all from dayScholar. 19 | 20 | If no Student scored greater than 80 and from dayScholar are present in the array of Student objects, then the 21 | method should return 0. 22 | 23 | findStudentwithSecondHighestScore: 24 | 25 | This method will take an array of Student objects as an input parameter. This method will return the object 26 | of the second highest score student from the array of Student objects who are not from the dayScholar. 27 | 28 | If no Student is a dayScholar in the array of Student objects, then the method should return null. 29 | 30 | Note : All the searches should be case insensitive. 31 | 32 | The combination of dayScholar and score for each student is always unique. 33 | 34 | The above mentioned static methods should be called from the main method. 35 | 36 | For findCountOfDayscholarStudents method - The main method should print the returned count as it is 37 | if the returned value is greater than 0, else it should print "There are no such dayscholar students". 38 | 39 | For findStudentwithSecondHighestScore method - The main method should print the rollNo, name and score 40 | in the below format from the returned object if the retuned value is not null. 41 | 42 | rollNo#name#score 43 | 44 | If the returned value is null, then it should print ”There are no student from non day scholar” 45 | 46 | Before calling these static methods in main, use Scanner object to read the values of four Student 47 | objects referring attributes in the above mentioned attribute sequence. 48 | Consider below sample input and output: 49 | 50 | Input: 51 | 52 | 1001 53 | Ashwa 54 | IT 55 | 85 56 | true 57 | 1002 58 | Preeti 59 | IT 60 | 70 61 | false 62 | 1003 63 | Uma 64 | ECE 65 | 85 66 | false 67 | 1004 68 | Akash 69 | EEE 70 | 90 71 | true 72 | 73 | 74 | Output: 75 | 2 76 | 1002#Preeti#70.0 77 | -------------------------------------------------------------------------------- /IPA30/DocsWithOddPages.txt: -------------------------------------------------------------------------------- 1 | Create class Document with below attributes 2 | 3 | id - int 4 | title - String 5 | folderName - String 6 | pages - int 7 | 8 | Write getters, setters and parameterized constructor as required. 9 | 10 | Create class Solution with main method. 11 | 12 | Implement static method - docsWithOddPages in Solution class. 13 | 14 | This method will take array of Document objects and return another array with Document objects which has odd number of pages. 15 | 16 | This method should be called from main method and display values of returned objects as shared in the sample (in ascending 17 | order of id attribute). 18 | 19 | Before calling this method, use Scanner object to read values for four Document objects referring attributes in the above 20 | sequence. 21 | 22 | Next call the method and display the result. 23 | 24 | Consider below sample input and output: 25 | 26 | Input: 27 | 1 28 | resume 29 | personal 30 | 50 31 | 2 32 | question1 33 | exams 34 | 55 35 | 3 36 | question2 37 | exams 38 | 45 39 | 4 40 | India 41 | misc 42 | 40 43 | 44 | 45 | Output (each line has values separated by single space): 46 | 2 question1 exams 55 47 | 3 question2 exams 45 48 | 49 | 50 | 51 | Note on using Scanner object: 52 | Sometimes scanner does not read the new line character while invoking methods like nextInt(), nextDouble() etc. 53 | Usually, this is not an issue, but this may be visible while calling nextLine() immediately after those methods. 54 | 55 | Consider below input values: 56 | 22 57 | hello 58 | 59 | Referring below code: 60 | 61 | Scanner sc = new Scanner(System.in); 62 | int x = sc.nextInt(); 63 | String str = sc.nextLine(); -> here we expect str to have value hello. Instead it may be """". 64 | 65 | If above issue is observed, then it is suggested to add one more explicit call to nextLine() after reading numeric value. 66 | -------------------------------------------------------------------------------- /IPA31/Music_IPA.txt: -------------------------------------------------------------------------------- 1 | Create a class Music with below attributes: 2 | 3 | playListNo - int 4 | 5 | type -String 6 | 7 | count - int 8 | 9 | duration(minutes) -double. 10 | 11 | 12 | 13 | The above attributes should be private.Write Getter and Setter and parametrized constructor as required. 14 | 15 | Create class Solution with main method. 16 | 17 | **************************************************************************** 18 | 19 | Implement two static methods: findAvgOfCount and sortTypeByDuration in Solution Class. 20 | 21 | 22 | 23 | findAvgOfCount Method: 24 | ---------------------------------------- 25 | This method will take an array of Music objects and an int value as input parameters.The method will find out Average 26 | (as int) of count for those objects whose count is more than the given Count(int parameter passed).This method will return 27 | average if found.If there is no Type that matches then the method should return 0. 28 | 29 | for this method- main method should print average ,if the returned value is not 0.If the returned value is 0 then main method 30 | should print "No playlist found". 31 | 32 | sortTypeByDuration method: 33 | ----------------------------------------- 34 | This method will take an array of Music objects and an int value as input parameters.This method should return an array of 35 | Music objects in an ascending order of their duration which are more than the given duration (int parameter passed) value. 36 | If there are no such objects ,then the method should return null. 37 | 38 | for this method-The main method should print the type from the returned Music object array if the returned value is not null. 39 | If the returned value is null then the main method should print "No playlist found with mentioned attribute". 40 | 41 | **************************************************************************** 42 | 43 | Consider the below input and output: 44 | 45 | input1: 46 | ------------ 47 | 111 48 | WorkOut 49 | 10 50 | 15.2 51 | 321 52 | Dance Party 53 | 20 54 | 55.500 55 | 721 56 | Childhood Jams 57 | 6 58 | 50.60 59 | 521 60 | Chill 61 | 30 62 | 78.89 63 | 15 64 | 20 65 | 66 | 67 | output1: 68 | -------------------- 69 | 25 70 | Childhood Jams 71 | Dance Party 72 | Chill 73 | 74 | 75 | 76 | input2: 77 | ----------------------- 78 | 111 79 | Oldies but Goodies 80 | 17 81 | 55 82 | 321 83 | Guilty Pleasures 84 | 27 85 | 27 86 | 721 87 | night drive 88 | 21 89 | 345 90 | 521 91 | Rainy day 92 | 34 93 | 21 94 | 50 95 | 5000 96 | 97 | 98 | output 2: 99 | ----------------------- 100 | No playlist found. 101 | No playlist found with mentioned attribute. 102 | 103 | -------------------------------------------------------------------------------- /IPA32/MyClass.txt: -------------------------------------------------------------------------------- 1 | Create a class TravelAgencies with below attributes: 2 | 3 | regNo – int 4 | agencyName – String 5 | pakageType – String 6 | price – int 7 | flightFacility – boolean 8 | 9 | Write getters, setters for the above attributes . Create constructor which takes parameter in the above sequence. 10 | 11 | Create class Solution with main method. Implement two static methods – findAgencyWithHighestPackagePrice and 12 | agencyDetailsforGivenIdAndType in Solution class. 13 | 14 | findAgencyWithHighestPackagePrice method: 15 | 16 | This method will take array of TravelAgencies objects as an input parameter and return the highest package 17 | price from the given array of objects. 18 | 19 | agencyDetailsForGivenldAndType method: 20 | 21 | This method will take three input parameters -array of TravelAgencies objects, int parameter regNo and String 22 | parameter packageType. The method will return the TravelAgencies object based on below conditions. 23 | 24 | FlightFacility should be available. 25 | The input parameters(regNo and packageType) should matched with the regNo and packageType of TravelAgencies object. 26 | If any of the above conditions are not met, then the method should return null. Note : Same Travel agency can 27 | have more than one package type. Travel agency and package type combination is unique. All the searches should 28 | be case insensitive. 29 | 30 | The above mentioned static methods should be called from the main method. 31 | 32 | 33 | For findAgencyWithHighestPackagePrice method – The main method should print the highestPackagePrice as it is. 34 | For agencyDetailsForGivenldAndType method -The main method should print the AgencyName and price of the returned 35 | object.The AgencyName and price should be concatinated with : while printing. 36 | --------- 37 | Input 38 | --------- 39 | 123 40 | A2Z Agency 41 | Platinum 42 | 50000 43 | true 44 | 345 45 | SSS Agency 46 | Gold 47 | 30000 48 | false 49 | 987 50 | Cox and Kings 51 | Diamond 52 | 40000 53 | true 54 | 888 55 | Global Tours 56 | Silver 57 | 20000 58 | false 59 | 987 60 | Diamond 61 | ------------------------------- 62 | Output 63 | ------------------------------- 64 | 50000 65 | Cox and Kings:40000 -------------------------------------------------------------------------------- /IPA34/PlayerDetails.txt: -------------------------------------------------------------------------------- 1 | Create class Player3 with below attributes: 2 | 3 | id - int 4 | name - String 5 | Country - String 6 | matchesPlayed - int 7 | runsScored - int 8 | 9 | the above attribute should be private ,write getter and setter and parametrized constructor as well. 10 | 11 | Create class Solution and implement static method "findPlayerName" in the Solution class. 12 | This method will take array of Player objects and a String as country parameters and int as run parameter. 13 | And will return another array of Player object where the String is matched with country and run scored of that Player object 14 | is greater than the input int parameter. All the searches should be case insensitive. 15 | 16 | Before calling "findPlayerName" method in the main method, read values for Player objects referring the attributes 17 | in above sequence along with a int target. 18 | Then call the "findPlayerName" method and write logic in main method to print Player object. If any of the input doesn't match 19 | with the following attributes then print "No player found". 20 | 21 | Note: 22 | -------------- 23 | 1. First take input as the number of player object, then the player details 24 | 2. Show the output as the dictionary order of the players name 25 | 3. First print player id, and then use ' : ' sign and after that player name 26 | 3 : Arijit 27 | 1 : Minaz 28 | 5 : Priyanka 29 | 30 | Input : 1 31 | -------------- 32 | 5 33 | 1 34 | Arnab 35 | India 36 | 4 37 | 94 38 | 2 39 | Virat 40 | UK 41 | 5 42 | 68 43 | 3 44 | Arijit 45 | India 46 | 82 47 | 87 48 | 4 49 | Raj 50 | India 51 | 21 52 | 78 53 | 5 54 | Priyanka 55 | India 56 | 12 57 | 86 58 | India 59 | 80 60 | 61 | Output : 1 62 | ----------------- 63 | 3:Arijit 64 | 1:Arnab 65 | 5:Priyanka 66 | 67 | ___________________________________________________________ 68 | 69 | Input : 2 70 | -------------- 71 | 5 72 | 1 73 | Arnab 74 | India 75 | 4 76 | 94 77 | 2 78 | Virat 79 | UK 80 | 5 81 | 68 82 | 3 83 | Arijit 84 | India 85 | 82 86 | 87 87 | 4 88 | Raj 89 | India 90 | 21 91 | 78 92 | 5 93 | Priyanka 94 | India 95 | 12 96 | 86 97 | UK 98 | 80 99 | 100 | Output : 2 101 | -------------------- 102 | No player found -------------------------------------------------------------------------------- /IPA35/RemoveCar.java: -------------------------------------------------------------------------------- 1 | package IPA35; 2 | import java.util.*; 3 | public class RemoveCar { 4 | public static void main(String[] args) { 5 | Scanner sc = new Scanner(System.in); 6 | Car[] car = new Car[5]; 7 | for (int i = 0; i < car.length; i++) { 8 | int a = sc.nextInt();sc.nextLine(); 9 | String b = sc.nextLine(); 10 | String c = sc.nextLine(); 11 | 12 | car[i] = new Car(a,b,c); 13 | } 14 | int id = sc.nextInt(); 15 | Car[] ans = RemoveAndRearrange(car,id); 16 | if(ans!=null) 17 | { 18 | for (int i = 0; i < ans.length; i++) { 19 | System.out.println(car[i].getId()+":"+ans[i].getName()); 20 | } 21 | } 22 | else 23 | { 24 | System.out.println("There are no car with given id"); 25 | } 26 | } 27 | public static Car[] RemoveAndRearrange(Car[] c, int id) 28 | { 29 | Car[] arr = new Car[0]; 30 | for (int i = 0; i < c.length; i++) { 31 | if(c[i].getId()!=id) 32 | { 33 | arr = Arrays.copyOf(arr, arr.length+1); 34 | arr[arr.length-1] = c[i]; 35 | } 36 | } 37 | if(arr.length>0) 38 | { 39 | return arr; 40 | } 41 | else 42 | { 43 | return null; 44 | } 45 | } 46 | } 47 | class Car 48 | { 49 | private int id; 50 | private String name; 51 | private String type; 52 | public Car(int id, String name, String type) { 53 | this.id = id; 54 | this.name = name; 55 | this.type = type; 56 | } 57 | public int getId() { 58 | return id; 59 | } 60 | public void setId(int id) { 61 | this.id = id; 62 | } 63 | public String getName() { 64 | return name; 65 | } 66 | public void setName(String name) { 67 | this.name = name; 68 | } 69 | public String getType() { 70 | return type; 71 | } 72 | public void setType(String type) { 73 | this.type = type; 74 | } 75 | 76 | } -------------------------------------------------------------------------------- /IPA35/RemoveCar.txt: -------------------------------------------------------------------------------- 1 | Create a class Car with the below attributes: 2 | 3 | carId – int 4 | carName – String 5 | fuelType – String 6 | 7 | The above attributes should be private, write getters, setters and parameterized constructor as required. 8 | 9 | Create class RemoveCar with main method. 10 | 11 | Implement two static methods – RemoveAndRearrange in RemoveCar class. 12 | 13 | RemoveAndRearrange method: 14 | This method will take int input parameter. The method will return the new array of Car object and remove that car whose 15 | id is match with the input parameter. Remove the car details and return the array with continuous new ids. 16 | 17 | If no car with the given id is present in the array of Car objects, then the method should return null. 18 | 19 | Note: No two Car object would have the same engine id. 20 | 21 | The above mentioned static methods should be called from the main method. 22 | 23 | For RemoveAndRearrange method: The main method should print the id and car name as it is, if the returned 24 | value is not null, or it should print “There are no car with given id”. 25 | 26 | Before calling these static methods in main, use Scanner object to read the values of five objects referring attributes 27 | in the above mentioned attribute sequence. next, read the value of int parameters for capturing car id. 28 | 29 | Input : 30 | 31 | 1001 32 | Maruti 33 | Diesel 34 | 1002 35 | Kia 36 | Pertro 37 | 1003 38 | Hyundai 39 | Diesel 40 | 1004 41 | Taxi 42 | Petrol 43 | 1005 44 | Truck 45 | Diesel 46 | 1003 47 | 48 | Output : 49 | 50 | 1001 : Maruti 51 | 1002 : Kia 52 | 1003 : Hyundai 53 | 1004 : Taxi -------------------------------------------------------------------------------- /IPA36/Mobile.txt: -------------------------------------------------------------------------------- 1 | Create a class MobileDetails with the below attributes: 2 | 3 | MobileId – int 4 | Price - int 5 | Brand – String 6 | isFlagShip – boolean 7 | 8 | The above attributes should be private, write getters, setters and parameterized constructor as required. 9 | 10 | Create class MobileDetails with main method. 11 | 12 | Implement two static methods – getTotalPrice() and getSecondMin() in MobileDetails class. 13 | 14 | getTotalPrice method: 15 | ---------------------------------------- 16 | This method will take two int input parameters which take object array and string brand. The method will return the total 17 | price of mobiles of that brand. 18 | 19 | If no mobile with the given brand is present in the array of MobileDetails objects, then the method should return 0. 20 | 21 | getSecondMin method: 22 | ---------------------------------------- 23 | This method will take object array which will return the second minimum price from the array and name of that mobile brand. 24 | 25 | The above mentioned static methods should be called from the main method. 26 | 27 | For getTotalPrice method: The main method should print the total price as it is, if the returned 28 | value is not null, or it should print “There are no mobile with given brand”. 29 | 30 | Before calling these static methods in main, use Scanner object to read the values of five objects referring attributes 31 | in the above mentioned attribute sequence. 32 | 33 | Input : 34 | --------------------------------------- 35 | 101 36 | 25000 37 | Samsung 38 | True 39 | 102 40 | 19000 41 | Redmi 42 | False 43 | 103 44 | 28000 45 | Nokia 46 | True 47 | 104 48 | 25000 49 | Realme 50 | False 51 | 105 52 | 40000 53 | Samsung 54 | True 55 | Samsung 56 | 57 | Output : 58 | ----------------------------------------- 59 | 65000 60 | Samsung : 25000 61 | Realme : 25000 -------------------------------------------------------------------------------- /IPA39/IPA39.java: -------------------------------------------------------------------------------- 1 | package IPA39; 2 | import java.util.*; 3 | public class IPA39 { 4 | public static void main(String[] args) { 5 | Scanner sc = new Scanner(System.in); 6 | Veg[] v = new Veg[4]; 7 | for (int i = 0; i < v.length; i++) { 8 | int a = sc.nextInt();sc.nextLine(); 9 | String b = sc.nextLine(); 10 | int c = sc.nextInt();sc.nextLine(); 11 | int d = sc.nextInt();sc.nextLine(); 12 | 13 | v[i] = new Veg(a,b,c,d); 14 | } 15 | int r = sc.nextInt(); 16 | Veg ans = findMinimumPriceByRating(v,r); 17 | if(ans!=null) 18 | { 19 | System.out.println(ans.getId()); 20 | } 21 | else 22 | { 23 | System.out.println("No such Vegetables"); 24 | } 25 | } 26 | public static Veg findMinimumPriceByRating(Veg[] v, int r) 27 | { 28 | int[] arr = new int[0]; 29 | for (int i = 0; i < v.length; i++) { 30 | if(v[i].getRating()>r) 31 | { 32 | arr = Arrays.copyOf(arr, arr.length+1); 33 | arr[arr.length-1] = v[i].getPrice(); 34 | Arrays.sort(arr); 35 | } 36 | } 37 | if(arr.length>0) 38 | { 39 | for (int i = 0; i < v.length; i++) { 40 | if(v[i].getPrice()==arr[0]) 41 | { 42 | return v[i]; 43 | } 44 | } 45 | } 46 | return null; 47 | } 48 | } 49 | class Veg 50 | { 51 | private int id; 52 | private String name; 53 | private int price; 54 | private int rating; 55 | public Veg(int id, String name, int price, int rating) { 56 | this.id = id; 57 | this.name = name; 58 | this.price = price; 59 | this.rating = rating; 60 | } 61 | public int getId() { 62 | return id; 63 | } 64 | public void setId(int id) { 65 | this.id = id; 66 | } 67 | public String getName() { 68 | return name; 69 | } 70 | public void setName(String name) { 71 | this.name = name; 72 | } 73 | public int getPrice() { 74 | return price; 75 | } 76 | public void setPrice(int price) { 77 | this.price = price; 78 | } 79 | public int getRating() { 80 | return rating; 81 | } 82 | public void setRating(int rating) { 83 | this.rating = rating; 84 | } 85 | 86 | } -------------------------------------------------------------------------------- /IPA39/IPA39.txt: -------------------------------------------------------------------------------- 1 | Create a class Vegetable with below attributes: 2 | 3 | VegetableId - int 4 | VegetableName - String 5 | Price - int 6 | Rating - int 7 | 8 | The above attributes should be private, write getters, setters and parameterized constructor as required. 9 | 10 | Create class Solution with main method. 11 | Implement two static methods - findMinimumPriceByRating in Solution class. 12 | 13 | findMinimumPriceByRating method: 14 | ----------------------------------------------- 15 | The method will return minimum price object from array of vegetable objects, whichever by rating greater than given rating. 16 | If no vegetable with the above condition is present in the array of vegetable object, then the mothod return null. 17 | 18 | Note : 19 | No vegetable has the same price. 20 | All the searches should be case insensitive. 21 | 22 | The above mentioned static methods should be called from the main method. 23 | 24 | For findMinimumPriceByRating method - The main method should print the id of vegetable object or it should print 25 | "No such Vegetables". 26 | 27 | Eg: 1002 28 | where 1002 is the id whose price is lowest 29 | 30 | Before calling these static methods in main, use Scanner object to read the values of four Vegetable objects referring 31 | attributes in the above mentioned attribute sequence. 32 | Next, read the value of int parameter for rating. 33 | 34 | Consider below sample input and output: 35 | 36 | Input1 37 | --------------------------- 38 | 1001 39 | Carrot 40 | 90 41 | 5 42 | 1002 43 | Tomato 44 | 40 45 | 4 46 | 1003 47 | Bectroot 48 | 80 49 | 4 50 | 1004 51 | Onion 52 | 78 53 | 3 54 | 2 55 | 56 | Output1 57 | ------------------------------- 58 | 1002 59 | ===================================================================================== 60 | Input2 61 | --------------------------- 62 | 1001 63 | Carrot 64 | 90 65 | 5 66 | 1002 67 | Tomato 68 | 40 69 | 4 70 | 1003 71 | Bectroot 72 | 80 73 | 4 74 | 1004 75 | Onion 76 | 78 77 | 3 78 | 7 79 | 80 | Output2 81 | ---------------------------- 82 | No such Vegetables -------------------------------------------------------------------------------- /IPA40/IPA40.txt: -------------------------------------------------------------------------------- 1 | Create a class Car with the following attributes: 2 | 3 | make - String 4 | model - String 5 | year - int 6 | price - double 7 | 8 | Write getters, setters and parameterized constructor in the above mentioned attribute sequence as required. 9 | 10 | Create a class Solution with the main method. 11 | 12 | Implement two static methods - findMostExpensiveCar and getCarByMakeAndModel in Solution class. 13 | 14 | findMostExpensiveCar method: 15 | This method will take an array of Car objects as input. 16 | The method will return the Car object with the highest price. 17 | If the array is empty, the method should return null. 18 | 19 | getCarByMakeAndModel method: 20 | This method will take three input parameters - array of Car objects, make and model (both strings). 21 | The method will return the Car object that matches the make and model attributes passed as parameters. 22 | If no car with the given make and model is present in the array of car objects, then the method should return null. 23 | 24 | Note: The search should be case insensitive. 25 | 26 | These above mentioned static methods should be called from the main method. 27 | 28 | For findMostExpensiveCar method - The main method should print the make, model, year and price of the returned Car object. 29 | If the returned value is null then it should print "Sorry - No car is available". 30 | 31 | For getCarByMakeAndModel method - The main method should print the year and price of the returned Car object. If the returned 32 | value is null then it should print "Sorry - No car is available". 33 | 34 | Before calling these static methods in main, use Scanner object to read the values of four Car objects referring attributes in 35 | the above mentioned attribute sequence. Next, read the values for make and model. 36 | 37 | Input: 38 | ----------------- 39 | Mercedes 40 | S-Class 41 | 2020 42 | 1250000 43 | BMW 44 | 5-Series 45 | 2019 46 | 900000 47 | Audi 48 | A4 49 | 2022 50 | 800000 51 | Jaguar 52 | F-PACE 53 | 2021 54 | 1100000 55 | Audi 56 | A4 57 | 58 | Output: 59 | --------------------- 60 | Mercedes 61 | S-Class 62 | 1250000.0 63 | 2020 64 | 2022 65 | 800000.0 -------------------------------------------------------------------------------- /IPA41/IPA41.txt: -------------------------------------------------------------------------------- 1 | Create a class BankAccount with the following attributes: 2 | 3 | accountNumber - int 4 | accountHolderName - String 5 | balance - double 6 | 7 | Write getters, setters and parameterized constructor in the above mentioned attribute sequence as required. 8 | 9 | Create a class Solution with the main method. 10 | 11 | Implement two static methods - withdraw and deposit in Solution class. 12 | 13 | withdraw method: 14 | ------------------------------------------ 15 | This method will take two input parameters - array of BankAccount objects and the account number (int) from which withdrawal 16 | should be done. 17 | The method will check if the account number is present in the array of BankAccount objects. 18 | If present, the method will then check if the balance is sufficient to withdraw the requested amount (double). If yes, it will 19 | deduct the amount from the account balance and return the updated balance. 20 | If the account number is not present or the balance is not sufficient, the method should return -1. 21 | 22 | deposit method: 23 | -------------------------------------------- 24 | This method will take two input parameters - array of BankAccount objects and the account number (int) in which deposit should 25 | be done. 26 | The method will check if the account number is present in the array of BankAccount objects. 27 | If present, it will add the deposit amount (double) to the account balance and return the updated balance. 28 | If the account number is not present, the method should return -1. 29 | 30 | These above mentioned static methods should be called from the main method. 31 | 32 | For withdraw method - The main method should print the updated balance if the returned value is greater than or equal to 0, or 33 | it should print "Sorry - Insufficient balance" if the returned value is -1, or it should print "Sorry - Account not found" if 34 | the returned value is -2. 35 | 36 | For deposit method - The main method should print the updated balance if the returned value is greater than or equal to 0, or 37 | it should print "Sorry - Account not found" if the returned value is -1. 38 | 39 | Before calling these static methods in main, a parameterized constructor in the above mentioned attribute sequence as required. 40 | 41 | Input 42 | ------------------------ 43 | 1001 44 | Alice 45 | 5000.0 46 | 1002 47 | Bob 48 | 10000.0 49 | 1003 50 | Charlie 51 | 15000.0 52 | 1002 53 | 5000.0 54 | 1001 55 | 10000.0 56 | 57 | Output 58 | --------------------------- 59 | 5000.0 60 | 15000.0 61 | -------------------------------------------------------------------------------- /IPA42/IPA42.txt: -------------------------------------------------------------------------------- 1 | Create a class Person with the following attributes: 2 | 3 | firstName - String 4 | lastName - String 5 | age - int 6 | gender - char ('M' for male and 'F' for female) 7 | 8 | Write getters, setters and parameterized constructor in the above mentioned attribute sequence as required. 9 | 10 | Create a class Student that extends the Person class and adds the following attributes: 11 | 12 | rollNo - String 13 | course - String 14 | semester - int 15 | GPA - double 16 | 17 | Write getters, setters and parameterized constructor in the above mentioned attribute sequence as required. 18 | 19 | Create a class Faculty that extends the Person class and adds the following attributes: 20 | 21 | employeeId - String 22 | department - String 23 | designation - String 24 | salary - double 25 | 26 | Write getters, setters and parameterized constructor in the above mentioned attribute sequence as required. 27 | 28 | Create a class Solution with the main method. 29 | 30 | Implement two static methods - findHighestGPAStudent and findHighestPaidFaculty in Solution class. 31 | 32 | findHighestGPAStudent method: 33 | This method will take an array of Student objects as input. 34 | The method will return the Student object with the highest GPA. 35 | If the array is empty, the method should return null. 36 | 37 | findHighestPaidFaculty method: 38 | This method will take an array of Faculty objects as input. 39 | The method will return the Faculty object with the highest salary. 40 | If the array is empty, the method should return null. 41 | 42 | These above mentioned static methods should be called from the main method. 43 | 44 | For findHighestGPAStudent method - The main method should print the roll number, course and GPA of the returned Student object. 45 | If the returned value is null then it should print "Sorry - No student is available". 46 | 47 | For findHighestPaidFaculty method - The main method should print the employee ID, department and salary of the returned 48 | Faculty object. 49 | If the returned value is null then it should print "Sorry - No faculty is available". 50 | 51 | Before calling these static methods in main, use Scanner object to read the values of two Student objects and two Faculty 52 | objects referring attributes in the above mentioned attribute sequence. 53 | 54 | Example Input: 55 | 56 | First1 57 | Last1 58 | 20 59 | M 60 | Roll1 61 | Course1 62 | 2 63 | 3.8 64 | First2 65 | Last2 66 | 21 67 | F 68 | Roll2 69 | Course2 70 | 3 71 | 3.9 72 | Faculty1 73 | Last3 74 | 35 75 | M 76 | ID1 77 | Department1 78 | Associate Professor 79 | 90000.0 80 | Faculty2 81 | Last4 82 | 40 83 | F 84 | ID2 85 | Department2 86 | Professor 87 | 100000.0 88 | 89 | Output: 90 | 91 | Roll2 92 | Course2 93 | 3.9 94 | ID2 95 | Department2 96 | 100000.0 -------------------------------------------------------------------------------- /IPA43/IPA43.txt: -------------------------------------------------------------------------------- 1 | Create a class Student with the following attributes: 2 | 3 | name - String 4 | rollNo - String 5 | age - int 6 | gender - char ('M' for male and 'F' for female) 7 | course - String 8 | semester - int 9 | GPA - double 10 | 11 | Write getters, setters and parameterized constructor in the above mentioned attribute sequence as required. 12 | 13 | Create a class Solution with the main method. 14 | 15 | Implement two static methods - calculateAverageGPA and getStudentsByCourse in Solution class. 16 | 17 | calculateAverageGPA method: 18 | This method will take an array of Student objects as input. 19 | The method will return the average GPA of all the students in the array. 20 | If the array is empty, the method should return 0. 21 | 22 | getStudentsByCourse method: 23 | This method will take two input parameters - array of Student objects and a course (string). 24 | The method will return an array of Student objects that are enrolled in the specified course. 25 | If no student with the given course is present in the array of Student objects, then the method should return an empty array. 26 | 27 | These above mentioned static methods should be called from the main method. 28 | 29 | For calculateAverageGPA method - The main method should print the average GPA returned by the method. 30 | If the returned value is 0, then it should print "Sorry - No students are available". 31 | 32 | For getStudentsByCourse method - The main method should print the name, roll number and GPA of the returned Student objects. 33 | If the returned value is an empty array, then it should print "Sorry - No students are available for the given course". 34 | 35 | Before calling these static methods in main, use Scanner object to read the values of four Student objects referring 36 | attributes in the above mentioned attribute sequence. Next, read the value for a course. 37 | 38 | Example Input: 39 | ------------------------ 40 | John 41 | 1234 42 | 20 43 | M 44 | CSE 45 | 2 46 | 3.5 47 | Alice 48 | 5678 49 | 19 50 | F 51 | EEE 52 | 1 53 | 3.7 54 | Bob 55 | 9101 56 | 21 57 | M 58 | CSE 59 | 4 60 | 3.9 61 | Sarah 62 | 2345 63 | 20 64 | F 65 | ME 66 | 3 67 | 3.2 68 | CSE 69 | 70 | Example Output: 71 | --------------------------- 72 | 3.6 73 | John 74 | 1234 75 | 3.5 76 | Bob 77 | 9101 78 | 3.9 -------------------------------------------------------------------------------- /IPA44/IPA44.java: -------------------------------------------------------------------------------- 1 | package IPA44; 2 | import java.util.*; 3 | public class IPA44 { 4 | public static void main(String[] args) { 5 | Scanner sc= new Scanner(System.in); 6 | Rectangle[] r = new Rectangle[2]; 7 | for (int i = 0; i < r.length; i++) { 8 | double a = sc.nextDouble();sc.nextLine(); 9 | double b= sc.nextDouble();sc.nextLine(); 10 | 11 | r[i] = new Rectangle(a, b); 12 | } 13 | double[] area = calculateArea(r); 14 | double[] per = calculatePerimeter(r); 15 | if(area != null && per != null) 16 | { 17 | for (int i = 0; i < 2; i++) { 18 | System.out.println(area[i]); 19 | System.out.println(per[i]); 20 | } 21 | } 22 | else 23 | { 24 | System.out.println("Data not found"); 25 | } 26 | } 27 | public static double[] calculateArea(Rectangle[]r) 28 | { 29 | double[] arr = new double[0]; 30 | for (int i = 0; i < r.length; i++) { 31 | double area = r[i].getL() * r[i].getB(); 32 | arr = Arrays.copyOf(arr, arr.length+1); 33 | arr[arr.length-1] = area; 34 | } 35 | if(arr.length!=0) 36 | { 37 | return arr; 38 | } 39 | return null; 40 | } 41 | public static double[] calculatePerimeter(Rectangle[]r) 42 | { 43 | double[] ar = new double[0]; 44 | for (int i = 0; i < r.length; i++) { 45 | double per = 2 * (r[i].getL() + r[i].getB()); 46 | ar = Arrays.copyOf(ar, ar.length+1); 47 | ar[ar.length-1] = per; 48 | } 49 | if(ar.length>0) 50 | { 51 | return ar; 52 | } 53 | return null; 54 | } 55 | } 56 | class Rectangle 57 | { 58 | private double l; 59 | private double b; 60 | public Rectangle(double l, double b) { 61 | this.l = l; 62 | this.b = b; 63 | } 64 | public double getL() { 65 | return l; 66 | } 67 | public void setL(double l) { 68 | this.l = l; 69 | } 70 | public double getB() { 71 | return b; 72 | } 73 | public void setB(double b) { 74 | this.b = b; 75 | } 76 | } -------------------------------------------------------------------------------- /IPA44/IPA44.txt: -------------------------------------------------------------------------------- 1 | Create a class Rectangle with the following attributes: 2 | 3 | length - double 4 | breadth - double 5 | 6 | Write getters, setters and parameterized constructor in the above mentioned attribute sequence as required. 7 | 8 | Create a class Solution with the main method. 9 | 10 | Implement two static methods - calculateArea and calculatePerimeter in Solution class. 11 | 12 | calculateArea method: 13 | This method will take a Rectangle object as input. 14 | The method will calculate the area of the rectangle and return it as a double. 15 | 16 | calculatePerimeter method: 17 | This method will take a Rectangle object as input. 18 | The method will calculate the perimeter of the rectangle and return it as a double. 19 | 20 | These above mentioned static methods should be called from the main method. 21 | 22 | For calculateArea method - The main method should print the area returned by the method. 23 | 24 | For calculatePerimeter method - The main method should print the perimeter returned by the method. 25 | 26 | Before calling these static methods in main, use Scanner object to read the values of two Rectangle objects referring 27 | attributes in the above mentioned attribute sequence. 28 | 29 | Example Input: 30 | 5.5 31 | 3.2 32 | 7.0 33 | 4.5 34 | 35 | Example Output: 36 | 17.6 37 | 17.4 38 | 31.5 39 | 23.0 -------------------------------------------------------------------------------- /IPA45/Question.txt: -------------------------------------------------------------------------------- 1 | Create a class Employee with the following attributes: 2 | 3 | name (string) 4 | age (int) 5 | salary (double) 6 | Write getters, setters, and a parameterized constructor in the above-mentioned attribute sequence as required. 7 | 8 | Create a class Solution with the main method. 9 | 10 | Implement two static methods - calculateYearlySalary and calculateTax in the Solution class. 11 | 12 | calculateYearlySalary method: 13 | ----------------------------------------- 14 | This method will take an Employee object as input. 15 | The method will calculate the yearly salary of the employee (assuming that the employee works for 12 months in a year) and 16 | return it as a double. 17 | 18 | calculateTax method: 19 | ----------------------------------------- 20 | This method will take an Employee object as input. 21 | The method will calculate the tax to be paid by the employee based on the following rules: 22 | 23 | If the yearly salary is less than or equal to 50000, the tax is 10% of the yearly salary. 24 | If the yearly salary is greater than 50000 but less than or equal to 100000, the tax is 20% of the amount over 50000 plus 10% 25 | of the first 50000. 26 | If the yearly salary is greater than 100000, the tax is 30% of the amount over 100000 plus 20% of the amount between 50000 and 27 | 100000 plus 10% of the first 50000. 28 | The method will return the tax amount as a double. 29 | These above-mentioned static methods should be called from the main method. 30 | 31 | For calculateYearlySalary method - The main method should print the yearly salary returned by the method. 32 | 33 | For calculateTax method - The main method should print the tax amount returned by the method. 34 | 35 | Before calling these static methods in main, use a Scanner object to read the values of an Employee object's attributes. 36 | 37 | Example Input: 38 | ---------------- 39 | John 40 | 30 41 | 55000.0 42 | 43 | Example Output: 44 | ---------------- 45 | Yearly salary of John: 660000.0 46 | Tax to be paid by John: 183000.0 -------------------------------------------------------------------------------- /IPA45/Solution.java: -------------------------------------------------------------------------------- 1 | package IPA45; 2 | 3 | import java.util.Scanner; 4 | 5 | public class Solution { 6 | 7 | public static void main(String[] args) { 8 | 9 | Scanner sc = new Scanner(System.in); 10 | 11 | String n = sc.nextLine(); 12 | int a = sc.nextInt(); 13 | double s = sc.nextDouble(); 14 | 15 | Employee e = new Employee(n,a,s); 16 | 17 | double yearlySalary = calculateYearlySalary(e); 18 | double tax = calculateTax(e); 19 | 20 | if(yearlySalary != 0 && tax != 0) 21 | { 22 | System.out.println("Yearly salary of "+e.getName()+": "+yearlySalary); 23 | System.out.println("Tax to be paid by "+e.getName()+": "+tax); 24 | } 25 | } 26 | 27 | public static double calculateYearlySalary(Employee emp) 28 | { 29 | if (emp.getSalary() > 0) 30 | { 31 | return emp.getSalary() * 12; 32 | } 33 | return 0; 34 | } 35 | 36 | public static double calculateTax(Employee emp) 37 | { 38 | double yearlySalary = calculateYearlySalary(emp); 39 | double tax = 0; 40 | if (yearlySalary > 0) { 41 | if (yearlySalary <= 50000) 42 | { 43 | tax = yearlySalary * 0.10; 44 | } 45 | else if (yearlySalary <= 100000 && yearlySalary>50000) 46 | { 47 | tax = (50000 * 0.10) + ((yearlySalary - 50000) * 0.20); 48 | } 49 | else 50 | { 51 | tax = (50000 * 0.10) + (50000 * 0.20) + ((yearlySalary - 100000) * 0.30); 52 | } 53 | } 54 | return tax; 55 | } 56 | } 57 | 58 | class Employee { 59 | 60 | private String name; 61 | private int age; 62 | private double salary; 63 | 64 | public Employee(String name, int age, double salary) { 65 | this.name = name; 66 | this.age = age; 67 | this.salary = salary; 68 | } 69 | 70 | public String getName() { 71 | return name; 72 | } 73 | 74 | public void setName(String name) { 75 | this.name = name; 76 | } 77 | 78 | public int getAge() { 79 | return age; 80 | } 81 | 82 | public void setAge(int age) { 83 | this.age = age; 84 | } 85 | 86 | public double getSalary() { 87 | return salary; 88 | } 89 | 90 | public void setSalary(double salary) { 91 | this.salary = salary; 92 | } 93 | 94 | } 95 | -------------------------------------------------------------------------------- /IPA46/Answer.java: -------------------------------------------------------------------------------- 1 | package IPA46; 2 | import java.util.*; 3 | public class Answer 4 | { 5 | public static void main(String[] args) { 6 | Scanner sc = new Scanner(System.in); 7 | Player[] p = new Player[4]; 8 | for (int i = 0; i < p.length; i++) { 9 | int a = sc.nextInt();sc.nextLine(); 10 | String b = sc.nextLine(); 11 | String c = sc.nextLine(); 12 | double d = sc.nextDouble();sc.nextLine(); 13 | 14 | p[i] = new Player(a,b,c,d); 15 | } 16 | String s = sc.nextLine(); 17 | int[] ans = searchPlayerForMatch(p,s); 18 | if(ans!=null) 19 | { 20 | for (int i = 0; i < ans.length; i++) { 21 | System.out.println(ans[i]); 22 | } 23 | } 24 | else 25 | { 26 | System.out.println("NA"); 27 | } 28 | } 29 | public static int[] searchPlayerForMatch(Player[] p, String s) 30 | { 31 | int[] id = new int[0]; 32 | for (int i = 0; i < p.length; i++) { 33 | if(p[i].getSide().equalsIgnoreCase(s)) 34 | { 35 | id = Arrays.copyOf(id,id.length+1); 36 | id[id.length-1] = p[i].getId(); 37 | Arrays.sort(id); 38 | } 39 | } 40 | if(id.length>0) 41 | { 42 | return id; 43 | } 44 | else 45 | { 46 | return null; 47 | } 48 | } 49 | } 50 | class Player 51 | { 52 | int id; 53 | String country,side; 54 | double price; 55 | public Player(int id, String country, String side, double price) { 56 | this.id = id; 57 | this.country = country; 58 | this.side = side; 59 | this.price = price; 60 | } 61 | public int getId() { 62 | return id; 63 | } 64 | public void setId(int id) { 65 | this.id = id; 66 | } 67 | public String getCountry() { 68 | return country; 69 | } 70 | public void setCountry(String country) { 71 | this.country = country; 72 | } 73 | public String getSide() { 74 | return side; 75 | } 76 | public void setSide(String side) { 77 | this.side = side; 78 | } 79 | public double getPrice() { 80 | return price; 81 | } 82 | public void setPrice(double price) { 83 | this.price = price; 84 | } 85 | 86 | } -------------------------------------------------------------------------------- /IPA46/Question.txt: -------------------------------------------------------------------------------- 1 | Create a Class Player with below attributes: 2 | 3 | id - int 4 | country - String 5 | side - String 6 | price - double 7 | 8 | Write getters, setters and parameterized constructor as required. 9 | 10 | Create class Solution with main method. 11 | 12 | Implement static method - searchPlayerForMatch in Solution class. 13 | 14 | This method will take a String parameter along with the other parameter as array of Player objects. 15 | The method will return array of Player where the String parameter appears in the side attribute (with case insensitive search). 16 | 17 | This method should be called from main method and display the id of returned objects in ascending order. 18 | 19 | Before calling this method(searchPlayerForMatch) in the main method, use Scanner object to read values for four Player objects 20 | referring the attributes in the above sequence, then, read the value for search parameter. 21 | Next call the method searchPlayerForMatch, write the logic to sort the id in ascending order (in main method) and display the 22 | result. 23 | 24 | Consider below sample input and output: 25 | 26 | Input: 27 | ------------ 28 | 1 29 | India 30 | Batting 31 | 2500000 32 | 2 33 | Australia 34 | Batting 35 | 1000000 36 | 3 37 | Srilanka 38 | Bowling 39 | 1700000 40 | 4 41 | England 42 | Bowling 43 | 2000000 44 | Batting 45 | 46 | Output: 47 | ------------ 48 | 1 49 | 2 -------------------------------------------------------------------------------- /IPA48/IPA48.java: -------------------------------------------------------------------------------- 1 | package IPA48; 2 | import java.util.*; 3 | public class IPA48 { 4 | public static void main(String[] args) { 5 | Scanner sc = new Scanner(System.in); 6 | int n = sc.nextInt();sc.nextLine(); 7 | double[] arr = new double[n]; 8 | for (int i = 0; i < arr.length; i++) { 9 | arr[i] = sc.nextDouble(); 10 | } 11 | String ans = findValidScores(arr); 12 | if(ans!=null) 13 | { 14 | System.out.println("Valid scores are = "+ans); 15 | } 16 | else 17 | { 18 | System.out.println("No valid score found."); 19 | } 20 | } 21 | public static boolean ValidateScore(double n) 22 | { 23 | if(n>0 && n<=100 && (int)n==n) 24 | { 25 | return true; 26 | } 27 | return false; 28 | } 29 | public static String findValidScores(double[] a) 30 | { 31 | int[] ar = new int[0]; 32 | for (int i = 0; i < a.length; i++) { 33 | if(ValidateScore(a[i])==true) 34 | { 35 | ar = Arrays.copyOf(ar,ar.length+1); 36 | ar[ar.length-1] = (int)a[i]; 37 | } 38 | } 39 | if(ar.length>0) 40 | { 41 | String arr = Arrays.toString(ar); 42 | return arr; 43 | } 44 | return null; 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /IPA48/IPA48.txt: -------------------------------------------------------------------------------- 1 | Define two functions as given below. 2 | 3 | 1. validateScore: This function will validate a given number whether it is less than or equal to 100 and greater than 0. 4 | If these conditions are matched, function will return True, otherwise return False 5 | 6 | 2. findValidScores : This function will take a list of scores (numbers ) as input,and return a list of scores from the input 7 | list after validation . Use the method validateScore to validate scores in the input list. If the input list does not contain 8 | any valid score, function should return None. 9 | 10 | Define the main section for the following: 11 | 12 | 1. Create a list of positive integers by taking user inputs 13 | To create the list, do the following: 14 | a. First read the number of elements (integer) you want to store in the list as input from user 15 | b. Read a number as input and add to the list. Repeat this step for the number of elements to be stored in the list (considered 16 | in the first line of input) 17 | 18 | 2. Call the method findValidScores by passing the list created in point #1 as argument. 19 | 20 | 3. Print a message “Valid Scores =” (excluding the quotes) followed by the list returned by the method findValidScores in the 21 | same line. If the method returns None, print the message “No valid score found.” (excluding the quotes). 22 | 23 | Sample Input description: 24 | The first input is the number of elements to be added to the list. 25 | 26 | The next set of inputs are the numbers to be added to the list one after another and is repeated for the number of elements 27 | given in the first line of input. 28 | 29 | Check the sample input and output below. 30 | 31 | 32 | Sample Input 1: 33 | For example, if you want to create a list of 5 positive numbers with values 10,20 ,101,90 and 0 34 | then the input should be read/given as follows: 35 | 36 | 5 37 | 10 38 | 20 39 | 101 40 | 90 41 | 0 42 | 43 | And the output for the above set of input will be: 44 | 45 | Valid Scores = [10, 20, 90] 46 | 47 | Sample Input 2: 48 | 8 49 | -100 50 | 101 51 | 0 52 | .80 53 | 101 54 | 120 55 | -75 56 | 0.78 57 | 58 | Output: 59 | No valid score found. -------------------------------------------------------------------------------- /IPA5/IPA5.txt: -------------------------------------------------------------------------------- 1 | Create a class Motel with the below attributes: 2 | 3 | motelId - int 4 | motelName - String 5 | dateOfBooking – String (in the format dd-mon-yyyy) 6 | noOfRoomsBooked – int 7 | cabFacility – String 8 | totalBill- double 9 | 10 | Restricted for circulation outside TCS Xplore 6 11 | The above attributes should be private, write getters, setters and parameterized constructor as 12 | required. 13 | Create class Solution with main method. 14 | Implement one static method – totalNoOfRoomsBooked in Solution class. 15 | totalNoOfRoomsBooked method: 16 | This method will take two input parameter - array of Motel objects and a String parameter. 17 | The method will return the total numbers of rooms booked from array of Motel objects if the cab facility 18 | attribute matches with the given String parameter(cab facility) and the number of rooms booked is 19 | greater than 5. 20 | If no rooms are booked with the above criteria in the array of Motel objects, then the method should 21 | return 0. 22 | Note : 23 | No two Motel object would have the same motelId. 24 | dateOfBooking is stored in the format dd-mon-yyyy(eg. 01-Jan-2022) 25 | The above mentioned static method should be called from the main method. 26 | For totalNoOfRoomsBooked method - The main method should print the total number of booked rooms 27 | as it is, if the returned value is greater than 0, else it 28 | should print "No such rooms booked" 29 | Before calling these static methods in main, use Scanner object to read the values of four Motel objects 30 | referring attributes in the above mentioned attribute sequence. 31 | Next, read the value of one String parameter for capturing the cab facility 32 | 33 | Input 34 | ___________ 35 | 1001 36 | M&M 37 | 01-Dec-2022 38 | 5 39 | Yes 40 | 30000 41 | 1002 42 | BestStay 43 | 10-Jan-2022 44 | 3 45 | Yes 46 | 27000 47 | 1003 48 | Novatel 49 | 11-Jun-2022 50 | 5 51 | Yes 52 | 25000 53 | 1004 54 | Chola 55 | 01-Sep-2022 56 | 7 57 | Yes 58 | 72000 59 | Yes 60 | ___________ 61 | OutPut 62 | ___________ 63 | 7 -------------------------------------------------------------------------------- /IPA50/Question.txt: -------------------------------------------------------------------------------- 1 | Create a class called BankAccount with the following attributes: 2 | 3 | accountNumber (String) 4 | accountHolderName (String) 5 | balance (double) 6 | Write getters, setters, and a parameterized constructor for the class. 7 | 8 | Create a static method transferFunds in a separate class called BankUtils. The method should take four parameters: 9 | 10 | fromAccount (BankAccount) 11 | toAccount (BankAccount) 12 | amount (double) 13 | transactionCode (String) 14 | The method should transfer the specified amount from the fromAccount to the toAccount, 15 | and return a Transaction object containing the transactionCode, the amount 16 | transferred, and the timestamp of the transaction. If the fromAccount has insufficient 17 | balance, the method should throw an InsufficientBalanceException with an appropriate error message. 18 | 19 | Create a class called Transaction with the following attributes: 20 | 21 | transactionCode (String) 22 | amount (double) 23 | timestamp (String) 24 | Write getters and a parameterized constructor for the class. 25 | 26 | Create an InsufficientBalanceException class that extends the Exception class. 27 | The exception should have a constructor that takes a message as a parameter. 28 | 29 | In the main method, create two BankAccount objects, transfer some funds between 30 | them using the transferFunds method, and print the transaction details to the console. Handle any exceptions. 31 | 32 | Sample Input: 33 | 34 | Account 1: 35 | Account Number: 12345 36 | Account Holder Name: John 37 | Balance: 5000.0 38 | 39 | Account 2: 40 | Account Number: 67890 41 | Account Holder Name: Jane 42 | Balance: 10000.0 43 | 44 | Transfer Details: 45 | Amount: 2000.0 46 | Transaction Code: T0001 47 | 48 | Sample Output: 49 | 50 | Before Transfer: 51 | Account 1: John - 12345 - 5000.0 52 | Account 2: Jane - 67890 - 10000.0 53 | 54 | After Transfer: 55 | Account 1: John - 12345 - 3000.0 56 | Account 2: Jane - 67890 - 12000.0 57 | 58 | Transaction Details: 59 | Transaction Code: T0001 60 | Amount Transferred: 2000.0 61 | Timestamp: 2023-04-01 10:30:00 -------------------------------------------------------------------------------- /IPA51/Answer.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | public class Answer { 3 | public static void main(String[] args) { 4 | Scanner sc = new Scanner(System.in); 5 | Beach[] bc = new Beach[4]; 6 | for (int i = 0; i < bc.length; i++) { 7 | int a = sc.nextInt();sc.nextLine(); 8 | String b = sc.nextLine(); 9 | int c = sc.nextInt(); 10 | int d = sc.nextInt(); 11 | sc.nextLine(); 12 | bc[i] = new Beach(a,b,c,d); 13 | } 14 | String e = sc.nextLine(); 15 | int f = sc.nextInt(); 16 | int ans = findLeastRatingWithName(bc,e,f); 17 | if(ans!=0) 18 | { 19 | System.out.println(ans); 20 | } 21 | else 22 | { 23 | System.out.println("No beach found"); 24 | } 25 | 26 | } 27 | public static int findLeastRatingWithName(Beach[] bc, String e, int f) 28 | { 29 | int[] rate = new int[0]; 30 | for (int i = 0; i < bc.length; i++) { 31 | if(bc[i].getName().equalsIgnoreCase(e) && bc[i].getCost()>f) 32 | { 33 | rate = Arrays.copyOf(rate, rate.length+1); 34 | rate[rate.length-1] = bc[i].getRating(); 35 | Arrays.sort(rate); 36 | } 37 | } 38 | if(rate.length>0) 39 | { 40 | return rate[0]; 41 | } 42 | return 0; 43 | } 44 | } 45 | class Beach 46 | { 47 | private int id; 48 | private String name; 49 | private int rating; 50 | private int cost; 51 | public Beach(int id, String name, int rating, int cost) { 52 | this.id = id; 53 | this.name = name; 54 | this.rating = rating; 55 | this.cost = cost; 56 | } 57 | public int getId() { 58 | return id; 59 | } 60 | public void setId(int id) { 61 | this.id = id; 62 | } 63 | public String getName() { 64 | return name; 65 | } 66 | public void setName(String name) { 67 | this.name = name; 68 | } 69 | public int getRating() { 70 | return rating; 71 | } 72 | public void setRating(int rating) { 73 | this.rating = rating; 74 | } 75 | public int getCost() { 76 | return cost; 77 | } 78 | public void setCost(int cost) { 79 | this.cost = cost; 80 | } 81 | } -------------------------------------------------------------------------------- /IPA51/Question.txt: -------------------------------------------------------------------------------- 1 | Create a class Beach with the below attributes: 2 | beachId - int 3 | beachName - String 4 | beachRating - int 5 | beachCost - int 6 | Write getters, setters and parameterized constructor in the above mentioned attribute sequence as required. 7 | 8 | Create class Solution with the main method. 9 | Implement two static methods - findLeastRatingWithName in Solution class. 10 | 11 | findLeastRatingWithName method: 12 | ----------------------------------- 13 | This method will take three input parameters - array of Beach objects and string parameter and a int parameter. The method 14 | will return the minimum rating attribute from beach objects whose name is matched with string parameter and whose amount 15 | is greater than the int parameter. If no data found of beach objects, then the method should return 0. 16 | 17 | Note : All the searches should be case insensitive. 18 | 19 | These above mentioned static methods should be called from the main method. 20 | For findLeastRatingWithName method - The main method should print the least rating from the beach array. If return 0, then 21 | you should print "No beach found". 22 | 23 | Input -> 24 | 1001 25 | Puri 26 | 3 27 | 8600 28 | 1002 29 | Digha 30 | 5 31 | 6200 32 | 1003 33 | Digha 34 | 3 35 | 4000 36 | 1004 37 | Digha 38 | 4 39 | 5500 40 | digha 41 | 5000 42 | 43 | Output -> 44 | 4 -------------------------------------------------------------------------------- /IPA52/Question.txt: -------------------------------------------------------------------------------- 1 | Create a class Employee with the below attributes: 2 | EmpId - int 3 | EmpName - String 4 | Dept - String 5 | Rating - int 6 | Salary - int 7 | 8 | Write getters, setters and parameterized constructor in the above mentioned attribute sequence as required. 9 | 10 | Create class Solution with the main method. 11 | 12 | Implement two static methods - findDept and findSecondHighestSalary in Solution class. 13 | 14 | findDept method: 15 | ----------------------------------- 16 | This method will take two input parameters - array of Employee objects and int parameter. The method 17 | will return the dept array attribute from employee objects whose salary is matched with int parameter and rating greater than 18 | equal to 3. If no data found of beach objects, then the method should return null. 19 | 20 | findSecondHighestSalary method: 21 | ----------------------------------- 22 | This method will take two input parameters - array of Employee objects and string parameter. The method 23 | will return the second highest salary from employee objects whose dept is matched with string parameter. 24 | If no data found of beach objects, then the method should return 0. 25 | 26 | Note: No two employees have same rating. All the searches should be case insensitive. 27 | 28 | These above mentioned static methods should be called from the main method. 29 | For findDept method - The main method should print the dept from the Employee array. If return null, then you should print 30 | "No Department found". 31 | For findSecondHighestSalary method - The main method should print the 2nd highest salary from the Employee array with 32 | the following condition. If return 0, then you should print "No data found". 33 | 34 | 35 | Input -> 36 | 101 37 | Arijit 38 | Computer 39 | 4 40 | 35000 41 | 102 42 | Rakesh 43 | Electronics 44 | 2 45 | 18000 46 | 103 47 | Mahima 48 | Mechanical 49 | 3 50 | 35000 51 | 104 52 | Saniya 53 | Mechanical 54 | 5 55 | 68000 56 | 105 57 | Rajesh 58 | Computer 59 | 1 60 | 30000 61 | 35000 62 | Mechanical 63 | 64 | Output -> 65 | Computer, Mechanical 66 | 35000 -------------------------------------------------------------------------------- /IPA53/IPA53.txt: -------------------------------------------------------------------------------- 1 | Create a Class Course with below attributes: 2 | 3 | CourseName - String 4 | CourseNumber - int 5 | Mode - String 6 | Sharedata - boolean 7 | 8 | Write getters, setters and parameterized constructor as required. 9 | 10 | Create class Solution with main method. 11 | 12 | Implement static method - findCourseStatus in Solution class. 13 | 14 | This method will take a String parameter along with the other parameter as array of Course objects. 15 | The method will return status where the String parameter appears in the side attribute (with case insensitive search). 16 | 17 | If the number of the course greater than equal to 1000, print "High", if greater or equal to 500 but less than 1000 then print 18 | "Medium" and if less than 500 then print "Low". 19 | 20 | If the taken string not match with the Course name then print "No course found". 21 | 22 | 23 | Consider below sample input and output: 24 | 25 | Input 1: 26 | ------------ 27 | Java 28 | 1200 29 | Online 30 | False 31 | Python 32 | 600 33 | Offline 34 | False 35 | HTML 36 | 800 37 | Offline 38 | False 39 | JavaScript 40 | 300 41 | Online 42 | True 43 | Python 44 | 45 | Output 1: 46 | ------------ 47 | Medium 48 | ========================================= 49 | Input 2: 50 | ------------ 51 | Java 52 | 1200 53 | Online 54 | False 55 | Python 56 | 600 57 | Offline 58 | False 59 | HTML 60 | 800 61 | Offline 62 | False 63 | JavaScript 64 | 300 65 | Online 66 | True 67 | PHP 68 | 69 | Output 2: 70 | ------------- 71 | No course found -------------------------------------------------------------------------------- /IPA53/Solution.java: -------------------------------------------------------------------------------- 1 | package IPA53; 2 | import java.util.*; 3 | public class Solution { 4 | public static void main(String[] args) { 5 | Scanner sc = new Scanner(System.in); 6 | Course[] co = new Course[4]; 7 | for (int i = 0; i < co.length; i++) { 8 | String a = sc.nextLine(); 9 | int b = Integer.parseInt(sc.nextLine()); 10 | String c = sc.nextLine(); 11 | boolean d = sc.nextBoolean();sc.nextLine(); 12 | 13 | co[i] = new Course(a,b,c,d); 14 | } 15 | String name = sc.nextLine(); 16 | String status = findCourseStatus(co,name); 17 | if(status!=null) 18 | { 19 | System.out.println(status); 20 | } 21 | else 22 | { 23 | System.out.println("No course found"); 24 | } 25 | } 26 | public static String findCourseStatus(Course[] c, String n) 27 | { 28 | for (int i = 0; i < c.length; i++) { 29 | if(c[i].getName().equalsIgnoreCase(n)) 30 | { 31 | if(c[i].getNumber()>=1000) 32 | { 33 | return "High"; 34 | } 35 | else if(c[i].getNumber()>=500 && c[i].getNumber()<1000) 36 | { 37 | return "Medium"; 38 | } 39 | else 40 | { 41 | return "Low"; 42 | } 43 | } 44 | } 45 | return null; 46 | } 47 | } 48 | class Course 49 | { 50 | String name, mode; 51 | int number; 52 | boolean data; 53 | public Course(String name, int number,String mode, boolean data) { 54 | this.name = name; 55 | this.mode = mode; 56 | this.number = number; 57 | this.data = data; 58 | } 59 | public String getName() { 60 | return name; 61 | } 62 | public void setName(String name) { 63 | this.name = name; 64 | } 65 | public String getMode() { 66 | return mode; 67 | } 68 | public void setMode(String mode) { 69 | this.mode = mode; 70 | } 71 | public int getNumber() { 72 | return number; 73 | } 74 | public void setNumber(int number) { 75 | this.number = number; 76 | } 77 | public boolean isData() { 78 | return data; 79 | } 80 | public void setData(boolean data) { 81 | this.data = data; 82 | } 83 | 84 | } -------------------------------------------------------------------------------- /IPA54/Question.txt: -------------------------------------------------------------------------------- 1 | Create a Class Course with below attributes: 2 | 3 | CourseId - Int 4 | CourseName - String 5 | CourseRating - double 6 | Mode - String 7 | HaveCertificate - boolean 8 | 9 | Write getters, setters and parameterized constructor as required. 10 | 11 | Create class Solution with main method. 12 | 13 | Implement static method - CountCourse in Solution class. 14 | 15 | This method will take a String parameter and a double parameter along with the other parameter as array of Course objects. 16 | The method will return the total number of courses which have certificate facility and the rating of the course object is greater 17 | than or equal to the given parameter with match the mode(with case insensitive search). 18 | 19 | If no count is there then print "No course found". 20 | 21 | Consider below sample input and output: 22 | 23 | Input 1: 24 | ------------ 25 | 1001 26 | Java 27 | 5 28 | Online 29 | True 30 | 1002 31 | Python 32 | 3 33 | Offline 34 | False 35 | 1003 36 | HTML 37 | 4 38 | Offline 39 | True 40 | 1004 41 | JavaScript 42 | 2 43 | Online 44 | False 45 | 3 46 | Online 47 | 48 | 49 | Output 1: 50 | ------------ 51 | 1 52 | ========================================= 53 | Input 2: 54 | ------------ 55 | 1001 56 | Java 57 | 5 58 | Online 59 | True 60 | 1002 61 | Python 62 | 3 63 | Offline 64 | False 65 | 1003 66 | HTML 67 | 4 68 | Offline 69 | True 70 | 1004 71 | JavaScript 72 | 2 73 | Online 74 | False 75 | 5 76 | Offline 77 | 78 | Output 2: 79 | ------------- 80 | No course found -------------------------------------------------------------------------------- /IPA54/Solution.java: -------------------------------------------------------------------------------- 1 | package IPA54; 2 | import java.util.*; 3 | public class Solution 4 | { 5 | public static void main(String[] args) { 6 | Scanner sc = new Scanner(System.in); 7 | Course[] course = new Course[4]; 8 | for (int i = 0; i < course.length; i++) { 9 | int a = Integer.parseInt(sc.nextLine()); 10 | String b = sc.nextLine(); 11 | double c = sc.nextDouble();sc.nextLine(); 12 | String d = sc.nextLine(); 13 | boolean e = sc.nextBoolean();sc.nextLine(); 14 | course[i] = new Course(a, b, c, d, e); 15 | } 16 | double g = sc.nextDouble();sc.nextLine(); 17 | String f = sc.nextLine(); 18 | int ans = CountCourse(course,f,g); 19 | if(ans>0) 20 | { 21 | System.out.println(ans); 22 | } 23 | else 24 | { 25 | System.out.println("No course found"); 26 | } 27 | } 28 | public static int CountCourse(Course[] c, String f, double g) 29 | { 30 | int count=0; 31 | for (int i = 0; i < c.length; i++) { 32 | if(c[i].isCertificate()==true && c[i].getRating()>=g && c[i].getMode().equalsIgnoreCase(f)) 33 | { 34 | count++; 35 | } 36 | } 37 | return count; 38 | } 39 | } 40 | class Course 41 | { 42 | private int id; 43 | private String name; 44 | private double rating; 45 | private String mode; 46 | private boolean certificate; 47 | public Course(int id, String name, double rating, String mode, boolean certificate) { 48 | this.id = id; 49 | this.name = name; 50 | this.rating = rating; 51 | this.mode = mode; 52 | this.certificate = certificate; 53 | } 54 | public int getId() { 55 | return id; 56 | } 57 | public void setId(int id) { 58 | this.id = id; 59 | } 60 | public String getName() { 61 | return name; 62 | } 63 | public void setName(String name) { 64 | this.name = name; 65 | } 66 | public double getRating() { 67 | return rating; 68 | } 69 | public void setRating(double rating) { 70 | this.rating = rating; 71 | } 72 | public String getMode() { 73 | return mode; 74 | } 75 | public void setMode(String mode) { 76 | this.mode = mode; 77 | } 78 | public boolean isCertificate() { 79 | return certificate; 80 | } 81 | public void setCertificate(boolean certificate) { 82 | this.certificate = certificate; 83 | } 84 | 85 | } -------------------------------------------------------------------------------- /IPA55/Question.txt: -------------------------------------------------------------------------------- 1 | Create a class Resort with the below attributes: 2 | 3 | resortId - int 4 | resortName - String 5 | Category - String 6 | resortPrice - double 7 | resortRating - double 8 | 9 | Write getters, setters and parameterized constructor in the above mentioned attribute sequence as required. 10 | 11 | Create class Solution with the main method. 12 | 13 | Implement two static methods - findAvgPrice in Solution class. 14 | 15 | findAvgPrice method: 16 | ---------------------------------- 17 | This method will take two input parameters - array of Resort objects and a string parameter. 18 | The method will return the average of the prices from resort objects whose Category matched with passed as parameter and rating 19 | will greater than 4. 20 | If no resort present found, then the method should return 0. 21 | 22 | Note : All the searches should be case insensitive. 23 | 24 | These above mentioned static methods should be called from the main method. 25 | 26 | For findAvgPrice method - The main method should print the average price as it is if the returned value is 27 | greater than 0, or it should print "No such Resort found". 28 | 29 | Before calling these static methods in main, use Scanner object to read the values of four resort objects referring attributes 30 | in the above mentioned attribute sequence. Next, read the value for category. 31 | 32 | Input 33 | ---------- 34 | 1004 35 | ABC 36 | 3 star 37 | 5400.00 38 | 4.5 39 | 1001 40 | DEF 41 | 5 star 42 | 4781.45 43 | 4.0 44 | 1002 45 | GHI 46 | 3 star 47 | 6235.72 48 | 4.2 49 | 1008 50 | JKL 51 | 2 star 52 | 7454.00 53 | 4.2 54 | 3 star 55 | 56 | Output 57 | ---------- 58 | The average price of 3 star:5817 -------------------------------------------------------------------------------- /IPA55/Solution.java: -------------------------------------------------------------------------------- 1 | package IPA55; 2 | import java.util.*; 3 | public class Solution { 4 | public static void main(String[] args) { 5 | Scanner sc = new Scanner(System.in); 6 | Resort[] rs = new Resort[4]; 7 | for (int i = 0; i < rs.length; i++) { 8 | int a = Integer.parseInt(sc.nextLine()); 9 | String b = sc.nextLine(); 10 | String c = sc.nextLine(); 11 | double d = sc.nextDouble();sc.nextLine(); 12 | double e = sc.nextDouble();sc.nextLine(); 13 | 14 | rs[i] = new Resort(a,b,c,d,e); 15 | } 16 | String cat = sc.nextLine(); 17 | double ans = findAvgPrice(rs,cat); 18 | if(ans!=0) 19 | { 20 | System.out.println("The average price of "+cat+":"+(int)ans); 21 | } 22 | else 23 | { 24 | System.out.println("No resorts are available"); 25 | } 26 | } 27 | public static double findAvgPrice(Resort[] r, String s) 28 | { 29 | double sum = 0; 30 | int n = 0; 31 | for (int i = 0; i < r.length; i++) { 32 | if(r[i].getCat().equalsIgnoreCase(s) && r[i].getRate()>4) 33 | { 34 | sum += r[i].getPrice(); 35 | n++; 36 | } 37 | } 38 | if(n>0) 39 | { 40 | double avg = sum/n; 41 | return avg; 42 | } 43 | return 0; 44 | } 45 | } 46 | class Resort 47 | { 48 | private int id; 49 | private String name; 50 | private String cat; 51 | private double price; 52 | private double rate; 53 | public Resort(int id, String name, String cat, double price, double rate) { 54 | this.id = id; 55 | this.name = name; 56 | this.cat = cat; 57 | this.price = price; 58 | this.rate = rate; 59 | } 60 | public int getId() { 61 | return id; 62 | } 63 | public void setId(int id) { 64 | this.id = id; 65 | } 66 | public String getName() { 67 | return name; 68 | } 69 | public void setName(String name) { 70 | this.name = name; 71 | } 72 | public String getCat() { 73 | return cat; 74 | } 75 | public void setCat(String cat) { 76 | this.cat = cat; 77 | } 78 | public double getPrice() { 79 | return price; 80 | } 81 | public void setPrice(double price) { 82 | this.price = price; 83 | } 84 | public double getRate() { 85 | return rate; 86 | } 87 | public void setRate(double rate) { 88 | this.rate = rate; 89 | } 90 | 91 | } -------------------------------------------------------------------------------- /IPA6/IPA6.txt: -------------------------------------------------------------------------------- 1 | Create the class RRT(Rapid response team) with the below attributes: 2 | 3 | ticketNo-int 4 | 5 | raisedBy-String 6 | 7 | assignedTo-String 8 | 9 | priority-int 10 | 11 | project-String 12 | 13 | 14 | 15 | All attributes should be private,write getters and setters and 16 | 17 | parameterized constructor as required. 18 | 19 | 20 | 21 | Create class MyClass with main method. 22 | 23 | 24 | 25 | Implement a static method-getHighestPriorityTicket in MyClass class. 26 | 27 | 28 | 29 | getHighestPriorityTicket method: 30 | 31 | This method will take an array of RRT objects ,and a String value as parameters.This method will return the RRT object with highest priority 32 | ticket from the array of the RRT objects for the given project(String parameter passed).Highest priority is the one which has lesser value. 33 | 34 | for example:1 is considered as high priority and 5 is considered as low priority. 35 | 36 | If no RRT with the above condition is present in the array of the RRT objects,then the method should return null. 37 | 38 | The main method should print the ticketNo,raisedBy and assignedTo from returned object if the returned object is not null.if the returned object is null then main method should print "No such Ticket". 39 | 40 | 41 | 42 | 43 | 44 | input1: 45 | ---------------------- 46 | 123 47 | Velantish 48 | Mani 49 | 3 50 | Xperience 51 | 234 52 | Sathish 53 | Akshaya 54 | 1 55 | AIG 56 | 345 57 | John 58 | Jack 59 | 2 60 | AIG 61 | 456 62 | Bhuvi 63 | Jack 64 | 5 65 | AIG 66 | AIG 67 | 68 | 69 | output1: 70 | ------------------ 71 | 234 72 | Sathish 73 | Akshaya 74 | 75 | ************** 76 | 77 | Input2: 78 | -------------- 79 | 123 80 | Velantish 81 | Mani 82 | 3 83 | Xperience 84 | 234 85 | Sathish 86 | Akshaya 87 | 1 88 | AIG 89 | 345 90 | John 91 | Jack 92 | 2 93 | AIG 94 | 456 95 | Bhuvi 96 | Jack 97 | 5 98 | AIG 99 | Xplore 100 | 101 | 102 | output2: 103 | -------------- 104 | No such ticket. 105 | 106 | -------------------------------------------------------------------------------- /IPA7/IPA7.txt: -------------------------------------------------------------------------------- 1 | Create a class Sim with below attributes: 2 | 3 | 4 | 5 | simId - int 6 | 7 | customerName - String 8 | 9 | balance - double 10 | 11 | ratePerSecond - double 12 | 13 | circle - String 14 | 15 | 16 | 17 | Write getters, setters and parameterized constructor as required. 18 | 19 | 20 | 21 | Public class Solution is already created with main method. 22 | 23 | 24 | Code inside main method should not be altered else your solution might be 25 | 26 | 27 | scored as zero.You may copy the code from main method in eclipse to 28 | 29 | verify your implementation. 30 | 31 | 32 | 33 | 34 | 35 | Implement static method - transferCustomerCircle in Solution class. 36 | 37 | This method will take first parameter as array of Sim class objects, 38 | 39 | second parameter as circle to be transferred (which is String parameter 40 | 41 | circle1) and third parameter as new circle (which is String parameter 42 | 43 | circle2). 44 | 45 | 46 | 47 | Method will transfer the customer to new circle (circle2), where the 48 | 49 | circle attribute would match second parameter (circle1). 50 | 51 | 52 | Method will return array of Sim objects for which circle is transferred. 53 | 54 | 55 | Return array should be sorted in descending order of ratePerSecond 56 | 57 | (assuming ratePerSecond is not same for any of the Sim objects). 58 | 59 | 60 | 61 | 62 | 63 | This method should be called from main method and display the simId, 64 | 65 | customerName,circle and ratePerSecond of returned objects 66 | 67 | (as per sample output). 68 | 69 | 70 | 71 | Main method mentioned above already has Scanner code to read values, 72 | 73 | create objects and test above methods. Hence do not modify it. 74 | 75 | 76 | 77 | 78 | 79 | 80 | ************************************************************************ 81 | 82 | 83 | 84 | Consider below sample input and output: 85 | 86 | 87 | 88 | Input: 89 | 90 | 1 91 | raj 92 | 100 93 | 1.5 94 | KOL 95 | 2 96 | chetan 97 | 200 98 | 1.6 99 | AHD 100 | 3 101 | asha 102 | 150 103 | 1.7 104 | MUM 105 | 4 106 | kiran 107 | 50 108 | 2.2 109 | AHD 110 | 5 111 | vijay 112 | 130 113 | 1.8 114 | AHD 115 | AHD 116 | KOL 117 | 118 | 119 | 120 | Output: 121 | 122 | 4 kiran KOL 2.2 123 | 124 | 5 vijay KOL 1.8 125 | 126 | 2 chetan KOL 1.6 127 | 128 | -------------------------------------------------------------------------------- /IPA9/IPA9.txt: -------------------------------------------------------------------------------- 1 | Create a class Book with below attributes 2 | 3 | id - int 4 | 5 | pages - int 6 | 7 | title - String 8 | 9 | author - String 10 | 11 | price - double 12 | 13 | The above attributes should be private, write getters and setters and parameterized constructor as required. 14 | 15 | Create a class Solution with main method 16 | -------------------------------------------- 17 | Implement two static methods - findBookWithMaximumPrice and searchBookByTitle in Solution class. 18 | 19 | findBookWithMaximumPrice : 20 | ============================= 21 | Create a static method findBookWithMaximumPrice in the Solution class. This method will take array of Book objects and 22 | returns the Book object having the maximum Price if found else return null if not found. 23 | 24 | searchBookByTitle : 25 | ============================= 26 | Create a static method searchBookByTitle in the Solution class. This method will take array of Book objects and Title as 27 | input and returns the Book object having the mentioned Title if found else return null if not found. 28 | 29 | These methods should be called from the main method. 30 | 31 | write code to perform the following tasks. 32 | 33 | 1. Take necessary input variable and call findBookWithMaximumPrice. For this method - The main method should print the Book 34 | object with the maximum of mentioned attribute as it is if the returned value is not null, or it should print 35 | "No Book found with mentioned attribute." 36 | 37 | 2. Take necessary input variable and call searchBookByTitle. For this method - The main method should print the Book object 38 | details as it is, if the returned value is not null or it should print "No Book found with mentioned attribute." 39 | 40 | The above mentioned static methods should be called from the main method. Also write the code for accepting the inputs and 41 | printing the outputs. Don't use any static test or formatting for printing the result. Just invoke the method and print the 42 | result. 43 | 44 | All String comparison needs to be in case sensitive. 45 | 46 | Input: 47 | 48 | 1 49 | 845 50 | Bengali 51 | Arijit 52 | 525.50 53 | 2 54 | 456 55 | English 56 | Raju 57 | 412.30 58 | 3 59 | 1022 60 | History 61 | Kaka 62 | 525.50 63 | 4 64 | 125 65 | geography 66 | MN 67 | 524 68 | English 69 | 70 | Output: 71 | 72 | 1 Bengali 73 | 3 History 74 | 2 75 | 456 -------------------------------------------------------------------------------- /IPA_practice1.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | public class IPA_practice1 3 | { 4 | public static void main(String[] args) 5 | { 6 | Scanner sc = new Scanner(System.in); 7 | String s = sc.nextLine(); 8 | String[] word = null; 9 | word = s.split(" "); 10 | for(int i=0; i0) 10 | { 11 | int rem = n%10; 12 | sum = sum+rem; 13 | n = n/10; 14 | } 15 | if (sum%3==0) 16 | { 17 | System.out.println("True"); 18 | } 19 | else{ 20 | System.out.println("False"); 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /IndexNumber_Calculate.java: -------------------------------------------------------------------------------- 1 | /* Find the index number of a character in a String 2 | * Input1 : 3 | -------------- 4 | Carrot 5 | a 6 | 7 | * Output: 8 | --------------- 9 | 1 10 | 11 | * Input2: 12 | ---------------- 13 | Carrot 14 | z 15 | 16 | * Output: 17 | -------------- 18 | NA 19 | */ 20 | 21 | import java.util.*; 22 | public class IndexNumber_Calculate { 23 | public static void main(String[] args) { 24 | Scanner sc = new Scanner(System.in); 25 | String s = sc.nextLine(); 26 | char ch = sc.nextLine().charAt(0); 27 | int c=0; 28 | for (int i = 0; i < s.length(); i++) { 29 | if(s.charAt(i)==ch) 30 | { 31 | System.out.println(i); 32 | c++; 33 | break; 34 | } 35 | } 36 | if(c==0) 37 | { 38 | System.out.println("NA"); 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /IntersectionOfSet.java: -------------------------------------------------------------------------------- 1 | // Intersection between two given set 2 | 3 | import java.util.*; 4 | public class IntersectionOfSet { 5 | public static void main(String[] args) { 6 | Scanner sc = new Scanner(System.in); 7 | int[] set1 = new int[4]; 8 | int[] set2 = new int[5]; 9 | int[] intersection = new int[0]; 10 | System.out.println("Set 1 :"); 11 | for (int i = 0; i < set1.length; i++) { 12 | System.out.print((i+1)+" : "); 13 | set1[i] = sc.nextInt(); 14 | } 15 | System.out.println("Set 2 :"); 16 | for (int i = 0; i < set2.length; i++) { 17 | System.out.print((i+1)+" : "); 18 | set2[i] = sc.nextInt(); 19 | } 20 | for (int i = 0; i < set1.length; i++) { 21 | for (int j = 0; j < set2.length; j++) { 22 | if(set1[i]==set2[j]) 23 | { 24 | intersection = Arrays.copyOf(intersection, intersection.length+1); 25 | intersection[intersection.length-1] = set1[i]; 26 | } 27 | } 28 | } 29 | System.out.println("The intersection of the two sets : "+Arrays.toString(intersection)); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /Large_Small.java: -------------------------------------------------------------------------------- 1 | /* 2 | Write a program that reads in a list of integers and prints out the smallest and largest integer in the list. 3 | 4 | Your program should first ask the user to enter the number of integers they want to input. Then it should prompt the user to 5 | enter each integer one by one. 6 | 7 | After all the integers have been entered, the program should output the smallest and largest integer in the list. 8 | 9 | Input 10 | ------------------------- 11 | Enter the number of integers: 5 12 | Enter integer 1: 10 13 | Enter integer 2: -5 14 | Enter integer 3: 20 15 | Enter integer 4: 0 16 | Enter integer 5: 15 17 | 18 | Output 19 | ------------------------- 20 | Smallest integer: -5 21 | Largest integer: 20 22 | 23 | */ 24 | 25 | import java.util.*; 26 | public class Large_Small 27 | { 28 | public static void main(String[] args) { 29 | Scanner sc = new Scanner(System.in); 30 | System.out.print("Enter the number of integers: "); 31 | int n = sc.nextInt(); 32 | int[] arr = new int[n]; 33 | for (int i = 0; i < n; i++) 34 | { 35 | System.out.print("Enter integer "+(i+1)+": "); 36 | arr[i] = sc.nextInt();sc.nextLine(); 37 | } 38 | Arrays.sort(arr); 39 | System.out.println("Smallest integer: "+arr[0]); 40 | System.out.println("Largest integer: "+arr[n-1]); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /LargestWord.java: -------------------------------------------------------------------------------- 1 | /* Find largest word from a given sentence 2 | * 3 | Input: He is so funny boy 4 | Output: funny 5 | */ 6 | 7 | import java.util.*; 8 | public class LargestWord { 9 | public static void main(String[] args){ 10 | Scanner sc = new Scanner(System.in); 11 | String s = sc.nextLine(); 12 | String[] arr = s.split(" "); 13 | String large = ""; 14 | for (int i = 0; i < arr.length; i++) 15 | { 16 | if(arr[i].length()>large.length()) 17 | { 18 | large = arr[i]; 19 | } 20 | } 21 | System.out.println("The largest string is: "+large); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /LastChar.java: -------------------------------------------------------------------------------- 1 | /* Last Character of each word of a sentence 2 | 3 | * Input: Kalyani Government Engineering College 4 | * Output: itge 5 | */ 6 | 7 | import java.util.*; 8 | public class LastChar { 9 | public static void main(String[] args) 10 | { 11 | Scanner sc = new Scanner(System.in); 12 | String s = sc.nextLine(); 13 | String ans = ""; 14 | for (int i = 0; i < s.length(); i++) 15 | { 16 | if(s.charAt(i)==' ') 17 | { 18 | if(Character.isAlphabetic(s.charAt(i-1))) 19 | { 20 | ans = ans+s.charAt(i-1); 21 | } 22 | } 23 | else if(i==s.length()-1 && Character.isAlphabetic(s.charAt(i))) 24 | { 25 | ans = ans+s.charAt(i); 26 | } 27 | } 28 | System.out.println(ans); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /Majority.java: -------------------------------------------------------------------------------- 1 | package JAVA; 2 | 3 | // Majority of an element means if an element is present in an array for more than n/2 times, 4 | // where n is the length of the Array 5 | // Array = {3, 3, 4, 2, 4, 4, 2, 4, 4} => 4 6 | 7 | import java.util.*; 8 | public class Majority{ 9 | public static void main(String[] args) { 10 | Scanner sc = new Scanner(System.in); 11 | int n = sc.nextInt(); 12 | int[] arr = new int[n]; 13 | for (int i = 0; i < n; i++) { 14 | int l = sc.nextInt(); 15 | arr[i] = l; 16 | } 17 | int k = (n/2); 18 | int[] p = new int[0]; 19 | int m = 0; 20 | for (int i = 0; i < n; i++) { 21 | int count=1; 22 | for (int j = i+1; j < arr.length; j++) 23 | { 24 | if(arr[i]==arr[j] && !Arrays.asList(p).contains(arr[i])) 25 | { 26 | count++; 27 | } 28 | } 29 | p = Arrays.copyOf(p,p.length+1); 30 | p[p.length-1]=arr[i]; 31 | if(count>k) 32 | { 33 | System.out.println("The element : "+arr[i]); 34 | m++; 35 | } 36 | } 37 | if(m==0) 38 | { 39 | System.out.println("There are no elements"); 40 | } 41 | } 42 | } -------------------------------------------------------------------------------- /Marge.java: -------------------------------------------------------------------------------- 1 | /* Marge two strings using comma 2 | 3 | Input: 4 | Arijit,Ghosh 5 | Pop:Mom 6 | 7 | Output: 8 | Arijit, Ghosh, Pop:Mom 9 | */ 10 | 11 | import java.util.*; 12 | public class Marge_Two_String 13 | { 14 | public static void main(String[] args) 15 | { 16 | Scanner sc = new Scanner(System.in); 17 | 18 | String p1 = sc.nextLine(); 19 | String[] s1 = p1.split(","); 20 | String p2 = sc.nextLine(); 21 | String[] s2 = p2.split(","); 22 | for(int i=0 ;i-1; i++) 40 | { 41 | for(int j=0; j num2) 75 | { 76 | num2 = num; 77 | } 78 | } 79 | System.out.println("Max Prime : "+num2); 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /MaximumAscii.java: -------------------------------------------------------------------------------- 1 | /* Find the Maximum Ascii valued character in a String 2 | * Arijit = t 3 | * priyanka = y 4 | * Aa = a 5 | */ 6 | 7 | import java.util.*; 8 | public class MaximumAscii { 9 | public static void main(String[] args) { 10 | Scanner sc = new Scanner(System.in); 11 | String s = sc.nextLine(); 12 | char ch = s.charAt(0); 13 | for (int i = 0; i < s.length(); i++) { 14 | if(ch=0; j--) 34 | { 35 | if(i == (n-1-j)) 36 | { 37 | 38 | dia2[i]=arr[i][j]; 39 | } 40 | } 41 | } 42 | System.out.println(Arrays.toString(dia2)); 43 | 44 | int[] result = new int[dia1.length+dia2.length]; 45 | System.arraycopy(dia1,0,result,0,dia1.length); 46 | System.arraycopy(dia2, 0, result, dia1.length, dia2.length); 47 | System.out.println(Arrays.toString(result)); 48 | int[] prime = new int[0]; 49 | for(i=0; imax) 70 | { 71 | max = prime[i]; 72 | } 73 | } 74 | System.out.println("The maximum prime : "+max); 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /Missing.java: -------------------------------------------------------------------------------- 1 | /* 2 | *Input : 1 2 4 8 9 11 12 14 3 | *Output : 3 5 6 7 10 13 4 | */ 5 | 6 | import java.util.*; 7 | public class Missing { 8 | public static void main(String[] args) 9 | { 10 | Scanner sc = new Scanner(System.in); 11 | int[] arr = new int[8]; 12 | int j; 13 | int[] ans = new int[0]; 14 | for (int i = 0; i < arr.length; i++) { 15 | arr[i] = sc.nextInt(); 16 | } 17 | for (int i = 0; i < arr.length-1; i++) { 18 | j=i; 19 | int k = arr[j]; 20 | while(k+1!=arr[i+1]) 21 | { 22 | ans = Arrays.copyOf(ans, ans.length+1); 23 | ans[ans.length-1]=(k+1); 24 | k++; 25 | } 26 | } 27 | for (int i = 0; i < ans.length; i++) { 28 | System.out.print(ans[i]+" "); 29 | } 30 | System.out.println(); 31 | } 32 | } 33 | 34 | 35 | /* 36 | ANOTHER PROCESS 37 | --------------------- 38 | import java.util.*; 39 | public class test { 40 | public static void main(String[]args) 41 | { 42 | Scanner sc= new Scanner(System.in); 43 | int[] arr = new int[8]; 44 | for (int i = 0; i < arr.length; i++) 45 | { 46 | arr[i] = sc.nextInt(); 47 | } 48 | int num; 49 | for (int i = 0; i < arr.length-1; i++) { 50 | num = arr[i]; 51 | while(num+1 != arr[i+1]) 52 | { 53 | System.out.print(num+1+" "); 54 | num++; 55 | } 56 | } 57 | } 58 | } 59 | */ 60 | -------------------------------------------------------------------------------- /Occurance.java: -------------------------------------------------------------------------------- 1 | /* Find the occurance of each character in a string 2 | * Input: Hello world 3 | * Output: 4 | * H: 1 5 | e: 1 6 | l: 3 7 | o: 2 8 | w: 1 9 | r: 1 10 | d: 1 11 | */ 12 | 13 | import java.util.*; 14 | public class Occurance { 15 | public static void main(String[] args) { 16 | Scanner sc = new Scanner(System.in); 17 | String s = sc.nextLine().replace(" ",""); 18 | LinkedHashMap count = new LinkedHashMap<>(); 19 | for (int i = 0; i < s.length(); i++) 20 | { 21 | if(!count.containsKey(s.charAt(i))) 22 | { 23 | count.put(s.charAt(i),1); 24 | } 25 | else 26 | { 27 | count.put(s.charAt(i),count.get(s.charAt(i))+1); 28 | } 29 | } 30 | for(HashMap.Entry data : count.entrySet()) 31 | { 32 | System.out.println(data.getKey()+": "+data.getValue()); 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /Odd_Reverse.java: -------------------------------------------------------------------------------- 1 | /* Take a number. If it odd then reverse it, otherwise print "Can not reverse" 2 | * 3 | * Input : 123 4 | * Output : 321 5 | * 6 | * Input : 234 7 | * Output : Can not reverse 8 | */ 9 | 10 | import java.util.*; 11 | public class Odd_Reverse 12 | { 13 | public static void main(String[] args) { 14 | Scanner sc = new Scanner(System.in); 15 | int num = sc.nextInt(); 16 | if(num%2==0) 17 | { 18 | System.out.println("Can't reverse"); 19 | } 20 | else 21 | { 22 | int sum=0; 23 | while(num>0) 24 | { 25 | int rem = num%10; 26 | sum = sum*10 + rem; 27 | num = num/10; 28 | } 29 | System.out.println("The reverse of the number : "+sum); 30 | } 31 | } 32 | } -------------------------------------------------------------------------------- /Palindrome.java: -------------------------------------------------------------------------------- 1 | /* Check a string is palindrome or not 2 | * Input: pop 3 | * Output: Palindrome 4 | * 5 | * Input: Papa 6 | * Output: None 7 | */ 8 | 9 | import java.util.*; 10 | public class Palindrome { 11 | public static void main(String[] args) { 12 | Scanner sc = new Scanner(System.in); 13 | String s = sc.nextLine(); 14 | boolean check = true; 15 | for(int i=0; i0) 60 | { 61 | return pal; 62 | } 63 | return null; 64 | } 65 | } -------------------------------------------------------------------------------- /PerfectNumber.java: -------------------------------------------------------------------------------- 1 | /* Check a number is perfect or not 2 | 3 | * Input : 6 4 | * Output : Perfect Number 5 | * 6 | * Explaination 7 | * -------------------------- 8 | * The divisors of 6 = 1,2,3. 1+2+3 = 6 9 | * Sum of the factors is equal to the given number. So this is perfect 10 | * 11 | * Input : 8 12 | * Output : Not Perfect Number 13 | * 14 | * Explaination 15 | * ------------------------- 16 | * Factors of 8 = 1,2,4, but 1+2+4 = 7 not equal to 8. 17 | */ 18 | 19 | import java.util.*; 20 | public class PerfectNumber { 21 | public static void main(String[] args) { 22 | Scanner sc = new Scanner(System.in); 23 | int n = sc.nextInt(); 24 | boolean check = isPerfect(n); 25 | if(check == true) 26 | { 27 | System.out.println("Perfect Number"); 28 | } 29 | else 30 | { 31 | System.out.println("Not Perfect Number"); 32 | } 33 | } 34 | public static boolean isPerfect(int n) 35 | { 36 | int sum = 0; 37 | for (int i = 1; i < n; i++) 38 | { 39 | if(n % i == 0) 40 | { 41 | sum += i; 42 | } 43 | } 44 | if(sum == n) 45 | { 46 | return true; 47 | } 48 | return false; 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /PerfectSquareOrNot.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | public class PerfectSquareOrNot { 3 | public static void main(String[] args) 4 | { 5 | Scanner sc = new Scanner(System.in); 6 | int num = sc.nextInt(); 7 | double res = Math.sqrt(num); 8 | if((int)res == res) 9 | { 10 | System.out.println("Perfect Square"); 11 | } 12 | else 13 | { 14 | System.out.println("Not a perfect square"); 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Java-Solution-TCS-IPA-Questions 2 | 3 | TCS company take IPA exam for incentive. There are one 35 marks and one 15 marks question. 4 | Here I have to solve all the type of questions on Java 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Remove2ConsecutiveLetter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * You are given a string S consisting of lowercase letters. Your task is to remove all the consecutive duplicates from 3 | * the string and output the result. For example, if the input string is "abbcddeff", the output should be "abcdef". 4 | * 5 | * Input: abbcddeff 6 | * Output: abcdef 7 | */ 8 | 9 | import java.util.*; 10 | public class Remove2ConsecutiveLetter 11 | { 12 | public static void main(String[] args) { 13 | Scanner sc = new Scanner(System.in); 14 | String s = sc.next(); 15 | String result = removeConsecutiveDuplicates(s); 16 | System.out.println(result); 17 | } 18 | 19 | private static String removeConsecutiveDuplicates(String s) { 20 | String str = ""; 21 | char ch = '\0'; 22 | for (int i = 0; i < s.length(); i++) { 23 | if(s.charAt(i)!=ch) 24 | { 25 | ch = s.charAt(i); 26 | str += ch; 27 | } 28 | } 29 | return str; 30 | } 31 | } 32 | 33 | -------------------------------------------------------------------------------- /RemoveLetter.java: -------------------------------------------------------------------------------- 1 | /* Remove a character from a string 2 | * Input 3 | * -------------- 4 | * Arijit 5 | * i 6 | * Output 7 | * --------------- 8 | * Arjt 9 | */ 10 | 11 | import java.util.*; 12 | public class RemoveLetter 13 | { 14 | public static void main(String[] args) { 15 | Scanner sc = new Scanner(System.in); 16 | String str = sc.nextLine(); 17 | String ch = sc.nextLine(); 18 | String s = str.replace(ch,""); 19 | System.out.println(s); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /Remove_Duplicate.java: -------------------------------------------------------------------------------- 1 | /* Remove duplicate characters in a string 2 | * 3 | * Input : Arijit Ghosh 4 | * Output : Arijt Ghos 5 | */ 6 | 7 | import java.util.*; 8 | public class Remove_Duplicate { 9 | public static void main(String[] args) { 10 | Scanner sc = new Scanner(System.in); 11 | String str = sc.nextLine(); 12 | String ch = ""; 13 | int i,j; 14 | for (i = 0; i < str.length(); i++) { 15 | for (j = 0; j < i; j++) 16 | { 17 | if(str.charAt(i)==str.charAt(j)) 18 | { 19 | break; 20 | } 21 | } 22 | if(i==j) 23 | { 24 | ch = ch+str.charAt(i); 25 | } 26 | } 27 | System.out.println("New string removing Duplicates : "+ch); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /Remove_Vowel.java: -------------------------------------------------------------------------------- 1 | /* Remove Vowel From A String 2 | 3 | * Input : Arijit Ghosh 4 | * Output : rjt Ghsh 5 | */ 6 | 7 | import java.util.*; 8 | public class Remove_Vowel { 9 | public static void main(String[] args) { 10 | Scanner sc = new Scanner(System.in); 11 | String str = sc.nextLine(); 12 | String s=""; 13 | char[] dic = {'A','a','E','e','I','i','O','o','U','u'}; 14 | for (int i = 0; i < str.length(); i++) { 15 | int c = 0; 16 | for (int j = 0; j < dic.length; j++) { 17 | if(str.charAt(i)==dic[j]) 18 | { 19 | c++; 20 | } 21 | } 22 | if(c==0) 23 | { 24 | s = s + str.charAt(i); 25 | } 26 | } 27 | System.out.println(s); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /RepeatedNumber.java: -------------------------------------------------------------------------------- 1 | //a2b3c1 = aabbbc 2 | 3 | import java.util.*; 4 | public class RepeatedNumber { 5 | public static void main(String[] args) { 6 | Scanner sc = new Scanner(System.in); 7 | String s = sc.nextLine(); 8 | for (int i = 0; i < s.length(); i++) 9 | { 10 | if(Character.isAlphabetic(s.charAt(i))) 11 | { 12 | System.out.print(s.charAt(i)); 13 | } 14 | else if(Character.isDigit(s.charAt(i))){ 15 | int x = Integer.parseInt(String.valueOf(s.charAt(i))); 16 | for (int j = 1; j < x; j++) { 17 | System.out.print(s.charAt(i-1)); 18 | } 19 | } 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /RepeatedSum_Digit.java: -------------------------------------------------------------------------------- 1 | /* Calculate the sum of all digits of a numbers. If the sum is greater than 9 then again sum the digits. The sum is 2 | continuing until the sum becomes one digit. 3 | 4 | Input : 195 5 | Output : 6 6 | 7 | Explanation: 1+9+5 =15>9, so 1+5=6 */ 8 | 9 | import java.util.*; 10 | public class RepeatedSum_Digit 11 | { 12 | public static void main(String[] args) { 13 | Scanner sc = new Scanner(System.in); 14 | int num = sc.nextInt(); 15 | if(num<=9) 16 | { 17 | System.out.println(num); 18 | } 19 | else 20 | { 21 | int sum = Sum(num); 22 | System.out.println(sum); 23 | } 24 | } 25 | public static int Sum(int num) 26 | { 27 | int div = num; 28 | int sum = 0; 29 | while(div>0) 30 | { 31 | int rem = div % 10; 32 | sum += rem; 33 | div = div/10; 34 | } 35 | if(sum>9) 36 | { 37 | return Sum(sum); 38 | } 39 | return sum; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /ReverseString.java: -------------------------------------------------------------------------------- 1 | /* Reverse of a string 2 | * Arijit = tijirA 3 | */ 4 | import java.util.*; 5 | public class ReverseString { 6 | public static void main(String[] args) { 7 | Scanner sc = new Scanner(System.in); 8 | String s = sc.nextLine(); 9 | 10 | /* One method 11 | -------------------------------------- 12 | for (int i = s.length()-1; i>=0; i--) { 13 | System.out.print(s.charAt(i)+""); 14 | } 15 | */ 16 | // Another method 17 | //----------------------------------- 18 | String n = ""; 19 | for (int i = 0; i < s.length(); i++) { 20 | n = s.charAt(i)+n; 21 | } 22 | System.out.println(n); 23 | } 24 | } -------------------------------------------------------------------------------- /Same_1st_2nd_Letter.java: -------------------------------------------------------------------------------- 1 | /*Count the number of words in a sentence that start and end with the same letter. 2 | 3 | Input: Anna asked about the Ginseng recipe 4 | Output: 2 5 | 6 | Explanation: There are two words in the sentence that start and end with the same letter - "Anna" and "Ginseng". */ 7 | 8 | import java.util.*; 9 | public class Same_1st_2nd_Letter { 10 | public static void main(String[] args) { 11 | Scanner sc = new Scanner(System.in); 12 | String s = sc.nextLine().toLowerCase(); 13 | String[] str = s.split(" "); 14 | int count=0; 15 | for (int i = 0; i < str.length; i++) { 16 | if(str[i].charAt(0)==str[i].charAt(str[i].length()-1)) 17 | { 18 | count++; 19 | } 20 | } 21 | if(count>0) 22 | { 23 | System.out.println(count); 24 | } 25 | else 26 | { 27 | System.out.println("No word found"); 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /Set_Employees_By_Location.java: -------------------------------------------------------------------------------- 1 | /* Group the employees by city 2 | 3 | * Input: 4 | * ---------------- 5 | * Employee | City 6 | * --------------------- 7 | * Arijit Kolkata 8 | * Minaz Mumbai 9 | * Rahul Chennai 10 | * Rajesh Kolkata 11 | * Sekhar Chennai 12 | * Kasim Chennai 13 | 14 | * Output: 15 | * ---------------- 16 | * Kolkata: Arijit,Rajesh 17 | * Mumbai: Minaz 18 | * Chennai: Rahul,Sekhar,Kasim 19 | */ 20 | 21 | import java.util.*; 22 | public class Set_Employees_By_Location { 23 | public static void main(String[] args) { 24 | Scanner sc = new Scanner(System.in); 25 | LinkedHashMap emp = new LinkedHashMap<>(); 26 | System.out.print("Number of Employee: "); 27 | int n = sc.nextInt();sc.nextLine(); 28 | for (int i = 0; i < n; i++) { 29 | System.out.print((i+1)+"> Enter name: "); 30 | String name = sc.nextLine(); 31 | System.out.print("Enter city: "); 32 | String city = sc.nextLine(); 33 | emp.put(name,city); 34 | } 35 | System.out.println(); 36 | // Show my data set 37 | for(HashMap.Entry data : emp.entrySet()) 38 | { 39 | System.out.println(data.getKey()+": "+data.getValue()); 40 | } 41 | System.out.println(); 42 | 43 | LinkedHashMap update = new LinkedHashMap<>(); 44 | for(HashMap.Entry data : emp.entrySet()) 45 | { 46 | if(!update.containsKey(data.getValue())) 47 | { 48 | update.put(data.getValue(),data.getKey()); 49 | } 50 | else 51 | { 52 | update.put(data.getValue(),update.get(data.getValue())+","+data.getKey()); 53 | } 54 | } 55 | // List data 56 | for(HashMap.Entry ans : update.entrySet()) 57 | { 58 | System.out.println(ans.getKey()+": "+ans.getValue()); 59 | } 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /Smallest_Character.java: -------------------------------------------------------------------------------- 1 | /* Minimum Ascii valued character in a String */ 2 | 3 | import java.util.*; 4 | public class Smallest_Character { 5 | public static void main(String[] args) { 6 | Scanner sc = new Scanner(System.in); 7 | String s =sc.nextLine(); 8 | char c=s.charAt(0); 9 | for (int i = 0; i < s.length(); i++) 10 | { 11 | for (int j = 0; j <= i; j++) { 12 | if(Character.compare(c,s.charAt(j))>0) // arijit = a 13 | { 14 | c = s.charAt(j); 15 | } 16 | } 17 | } 18 | System.out.println(c); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /SortBookByPrice.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | import java.util.*; 3 | import java.text.*; 4 | import java.math.*; 5 | import java.util.regex.*; 6 | 7 | public class SortBookByPrice { 8 | public static void main(String args[] ) throws Exception { 9 | /* Enter your code here. Read input from STDIN. Print output to STDOUT */ 10 | Scanner sc=new Scanner(System.in); 11 | Book[] bk = new Book[4]; 12 | for(int i=0; i<4; i++) 13 | { 14 | int a = sc.nextInt();sc.nextLine(); 15 | String b = sc.nextLine(); 16 | String c = sc.nextLine(); 17 | double d = sc.nextDouble(); 18 | 19 | bk[i]=new Book(a,b,c,d); 20 | } 21 | Book[] k = sortBookByPrice(bk); 22 | if(k!=null) 23 | { 24 | for(int i =0; ib[j].getPrice()) 39 | { 40 | k = b[i]; 41 | b[i]=b[j]; 42 | b[j]=k; 43 | } 44 | } 45 | } 46 | return b; 47 | } 48 | } 49 | class Book 50 | { 51 | int id; 52 | String title, author; 53 | double price; 54 | 55 | public Book(int id, String title, String author, double price) 56 | { 57 | this.id = id; 58 | this.title= title; 59 | this.author = author; 60 | this.price = price; 61 | } 62 | 63 | public int getId() 64 | { 65 | return id; 66 | } 67 | public void setId(int id) 68 | { 69 | this.id = id; 70 | } 71 | public String getTitle() 72 | { 73 | return title; 74 | } 75 | public void setTitle(String title) 76 | { 77 | this.title = title; 78 | } 79 | public String getAuthor() 80 | { 81 | return author; 82 | } 83 | public void setAuthor(String author) 84 | { 85 | this.author = author; 86 | } 87 | public double getPrice() 88 | { 89 | return price; 90 | } 91 | public void setPrice(double price) 92 | { 93 | this.price = price; 94 | } 95 | } -------------------------------------------------------------------------------- /SortingName.java: -------------------------------------------------------------------------------- 1 | /* Sort name by dictionary order 2 | Input 3 | ----------------- 4 | Arijit 5 | Minaz 6 | Arnab 7 | 8 | Output 9 | ------------------- 10 | Arijit 11 | Arnab 12 | Minaz 13 | */ 14 | 15 | import java.util.*; 16 | public class SortingName { 17 | public static void main(String[] args) { 18 | Scanner sc = new Scanner(System.in); 19 | String[] str = new String[3]; 20 | String name = ""; 21 | for (int i = 0; i < str.length; i++) { 22 | str[i] = sc.nextLine(); 23 | } 24 | for (int i = 0; i < str.length; i++) { 25 | for (int j = i+1; j < str.length; j++) { 26 | if(str[i].compareTo(str[j])>0) 27 | { 28 | name = str[i]; 29 | str[i]=str[j]; 30 | str[j]=name; 31 | } 32 | } 33 | } 34 | for (int i = 0; i < str.length; i++) { 35 | System.out.println(str[i]); 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /Space_Count.java: -------------------------------------------------------------------------------- 1 | /* Count number of spaces and characters in a string 2 | * Input 3 | * --------- 4 | * Arijit is bad boy 5 | * 6 | * Output 7 | * ------------------ 8 | * Number of space : 3 9 | Number of character : 14 10 | */ 11 | 12 | import java.util.*; 13 | public class Space_Count { 14 | public static void main(String[] args) { 15 | Scanner sc = new Scanner(System.in); 16 | String s = sc.nextLine(); 17 | int count = 0; 18 | for (int i = 0; i < s.length(); i++) { 19 | if(s.charAt(i)==' ') 20 | { 21 | count++; 22 | } 23 | } 24 | System.out.println("Number of space : "+count); 25 | System.out.println("Number of character : "+(s.length()-count)); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Split.java: -------------------------------------------------------------------------------- 1 | /*Books are identified by International Standard Book Number(ISBN). ISBNs contain 2 | 13 digits, arranged in five groups such as 978-0-13-110362-8. The first group 3 | (GSI prefix) is currently either 978 or 979. The group identifier specifies the 4 | language or country of origin (for example 0 and 1 are used for English speaking 5 | countries). The publisher code identifies the publisher (13 is the code for 6 | Prentice Hall, New Jersey). The item number is assigned by the publisher to 7 | identify a specific book (110362 is the code for the book "The C Programming 8 | Language" by Kernighan and Ritchie) and ISBN ends with a check digit that's used 9 | to verify the accuracy of preceding digits. Write a program that breaks down the 10 | ISBN entered by the user.: 11 | 12 | Sample Input: 13 | ----------------------- 14 | Enter ISBN: 978-0-13-110362-8 15 | 16 | Sample Output: 17 | ----------------------- 18 | GSI Prefix: 978 19 | Group Identifier: 0 20 | Publisher Code: 13 21 | Item Number: 110362 22 | Check Digit: 8 23 | 24 | Note: The number of digits in each group may vary. You can't assume that the 25 | groups have the length shown in the sample output. You can test your program 26 | with actual ISBN values (usually found on the back cover of a book and on the 27 | copyright page */ 28 | 29 | import java.util.*; 30 | public class Split { 31 | public static void main(String[] args) { 32 | Scanner sc = new Scanner(System.in); 33 | System.out.println("Enter ISBN: "); 34 | String n = sc.nextLine(); 35 | String[] data = ExtractElement(n); 36 | if(data!=null) 37 | { 38 | int i=0; 39 | System.out.println("GSI Prefix: "+data[i++]); 40 | System.out.println("Group Identifier: "+data[i++]); 41 | System.out.println("Publisher Code: "+data[i++]); 42 | System.out.println("Item Number: "+data[i++]); 43 | System.out.println("Check Digit: "+data[i++]); 44 | } 45 | } 46 | public static String[] ExtractElement(String data) 47 | { 48 | String[] num = data.split("-"); 49 | if(num.length==5) 50 | { 51 | return num; 52 | } 53 | return null; 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /StringToArray.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | public class StringToArray { 3 | public static void main(String[] args) 4 | { 5 | Scanner sc = new Scanner(System.in); 6 | String str = sc.nextLine(); 7 | char[] arr = new char[str.length()]; 8 | for(int i=0; i0) 9 | { 10 | int rem = num%10; 11 | if(rem%2==0) 12 | { 13 | sum+=rem; 14 | } 15 | num = num/10; 16 | }*/ 17 | // Another solution 18 | String str = sc.nextLine(); 19 | for (int i = 0; i < str.length(); i++) 20 | { 21 | int k = Integer.parseInt(String.valueOf(str.charAt(i))); 22 | if(k%2==0) 23 | { 24 | sum+=k; 25 | } 26 | } 27 | System.out.println("The sum of even digit : "+sum); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /SumOfNum.java: -------------------------------------------------------------------------------- 1 | /* Input : 123Arijit1998Arijit10 2 | 3 | * Process : 4 | * ----------- 5 | * Array : [123, Arijit, 1998, Arijit, 10] 6 | * Now you should sum up the position of that array where numbers are stored. 7 | * 123 + 1998 = 2121 8 | * 9 | * Output : 10 | * -------------- 11 | * 2131 12 | */ 13 | 14 | import java.util.*; 15 | public class SumOfNum 16 | { 17 | public static void main(String[] args) 18 | { 19 | int sum=0,num=0; 20 | String str = "123Arijit1998Arijit10"; 21 | for (int i = 0; i < str.length(); i++) { 22 | if(Character.isDigit(str.charAt(i))) 23 | { 24 | num=(num*10)+Integer.parseInt(String.valueOf(str.charAt(i))); 25 | } 26 | else if(num!=0) 27 | { 28 | sum = sum+num; 29 | num=0; 30 | } 31 | } 32 | if(num>0) 33 | { 34 | sum = sum+num; 35 | } 36 | System.out.println(sum); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /Sum_EvenInteger.java: -------------------------------------------------------------------------------- 1 | /* Write a function that takes a list of numbers as input and returns the sum of all the even numbers in the list. 2 | 3 | For example: 4 | 5 | Enter size of Array: 4 6 | Create an array: 7 | 10 15 20 25 8 | The array is: [10, 15, 20, 25] 9 | Sum of even numbers in the array: 30 10 | 11 | */ 12 | import java.util.*; 13 | public class Sum_EvenInteger 14 | { 15 | public static void main(String[] args) { 16 | Scanner sc = new Scanner(System.in); 17 | System.out.print("Enter size of Array: "); 18 | int n = sc.nextInt(); 19 | int[] num = new int[n]; 20 | System.out.println("Create an array:"); 21 | for (int i = 0; i < num.length; i++) { 22 | num[i] = sc.nextInt(); 23 | } 24 | String array = Arrays.toString(num); 25 | System.out.println("The array is: "+array); 26 | int sum = SumOfEven(num); 27 | System.out.println("Sum of even numbers in the array: "+sum); 28 | } 29 | public static int SumOfEven(int[] arr) 30 | { 31 | int sum = 0; 32 | for (int i = 0; i < arr.length; i++) { 33 | if(arr[i] % 2 == 0) 34 | { 35 | sum += arr[i]; 36 | } 37 | } 38 | return sum; 39 | } 40 | } -------------------------------------------------------------------------------- /Sum_Prime_Digits.java: -------------------------------------------------------------------------------- 1 | /* Count the sum of prime digits in a given number 2 | * 3 | * Input: 2345678910 4 | * Output: 17 5 | * 6 | * Explaination: 2+3+5+7 = 17 7 | */ 8 | 9 | import java.util.*; 10 | public class Sum_Prime_Digits { 11 | public static void main(String[] args) 12 | { 13 | Scanner sc = new Scanner(System.in); 14 | String k = sc.nextLine(); 15 | int sum = 0; 16 | for (int i = 0; i < k.length(); i++) { 17 | if(isPrime(k.charAt(i))) 18 | { 19 | sum+= Integer.parseInt(String.valueOf(k.charAt(i))); 20 | } 21 | } 22 | if(sum>0) 23 | { 24 | System.out.println("Sum of the prime digits: "+sum); 25 | } 26 | else 27 | { 28 | System.out.println("No prime digits found"); 29 | } 30 | } 31 | public static boolean isPrime(char k) 32 | { 33 | int n = Integer.parseInt(String.valueOf(k)); 34 | if(n<2) 35 | { 36 | return false; 37 | } 38 | for (int i = 2; i < n; i++) 39 | { 40 | if(n % i == 0) 41 | { 42 | return false; 43 | } 44 | } 45 | return true; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /Sum_Upto_n.java: -------------------------------------------------------------------------------- 1 | /* 2 | Write a Java program that takes a user input integer n and calculates the sum of the first n natural numbers. 3 | 4 | The program should use a for loop to calculate the sum. 5 | 6 | Sample Input: 7 | --------------------- 8 | 5 9 | 10 | Sample Output: 11 | --------------------- 12 | The sum of first 5 natural numbers is 15. 13 | 14 | Explanation: 15 | --------------------- 16 | The first 5 natural numbers are: 1, 2, 3, 4, 5 17 | Their sum is: 1 + 2 + 3 + 4 + 5 = 15 18 | 19 | */ 20 | import java.util.*; 21 | public class Sum_Upto_n { 22 | public static void main(String[] args) { 23 | Scanner sc = new Scanner(System.in); 24 | int k = sc.nextInt(); 25 | int sum=0; 26 | for (int i = 1; i <= k; i++) { 27 | sum+=i; 28 | } 29 | System.out.println(sum); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /Text To Voice/Text_To_Speech.py: -------------------------------------------------------------------------------- 1 | from gtts import gTTS 2 | from playsound import playsound 3 | 4 | mytext = 'Welcome to the future' 5 | 6 | print(mytext) 7 | 8 | # Change voice into woman 9 | myobj = gTTS(text=mytext, lang='en', slow=False) 10 | 11 | # Save it using name welcome 12 | myobj.save("welcome.mp3") 13 | 14 | # Play the sound 15 | playsound("welcome.mp3") 16 | -------------------------------------------------------------------------------- /UniqueCharacters.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | 3 | public class UniqueCharacters { 4 | public static void main(String[] args){ 5 | Scanner sc = new Scanner(System.in); 6 | String input = sc.nextLine(); 7 | input = input.toLowerCase(); 8 | String temp = ""; 9 | for(int i =0;i 27 | xperience 28 | 29 | o/p -> 30 | xperinc 31 | */ -------------------------------------------------------------------------------- /avg.java: -------------------------------------------------------------------------------- 1 | /* Find average of a number array between two limit numbers (except the two numbers) 2 | * Input 3 | * --------------- 4 | * 5 5 | 1 6 | 2 7 | 3 8 | 4 9 | 5 10 | * 1 11 | * 4 12 | * 13 | * Output 14 | * --------------- 15 | * 2 16 | */ 17 | import java.util.*; 18 | public class avg 19 | { 20 | public static void main(String[] args) { 21 | Scanner sc = new Scanner(System.in); 22 | int n = sc.nextInt(); 23 | int[] arr = new int[n]; 24 | for(int i=0; i0 && lowerIndex+10) 25 | { 26 | System.out.println(count); 27 | } 28 | else{ 29 | System.out.println("NA"); 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /evencheck.java: -------------------------------------------------------------------------------- 1 | /* Count number of even digit in a number 2 | * If the count greater than or equal to 3, then print "True" otherwise "False" 3 | */ 4 | import java.util.*; 5 | public class evencheck 6 | { 7 | public static void main(String[] args) 8 | { 9 | int n; 10 | Scanner sc = new Scanner(System.in); 11 | int count = 0; 12 | /* 13 | n = sc.nextInt(); 14 | while(n>0) 15 | { 16 | int rem = n%10; 17 | if(rem%2==0){ 18 | count++; 19 | } 20 | n = n/10; 21 | } 22 | */ 23 | String num = sc.nextLine(); 24 | for (int i = 0; i < num.length(); i++) 25 | { 26 | if(Integer.parseInt(String.valueOf(num.charAt(i)))%2==0) 27 | { 28 | count++; 29 | } 30 | } 31 | if(count>=3) 32 | { 33 | System.out.print("True"); 34 | } 35 | else{ 36 | System.out.print("False"); 37 | } 38 | } 39 | } -------------------------------------------------------------------------------- /practice1.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | public class practice1 3 | { 4 | public static void main(String[]args) 5 | { 6 | Scanner sc = new Scanner(System.in); 7 | System.out.print("Value of V :"); 8 | int v = sc.nextInt(); 9 | System.out.print("Value of W :"); 10 | int w = sc.nextInt(); 11 | if (w>=2 && w%2==0 && v