th<\/sup> position.<\/td>\n(ii) This technique divides the array in two halves, and the desired data item is searched in the halves.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n Question 3. \n(a) Write a Java expression for the following : [2] \n|x2<\/sup>+2xy| \n(b) Write the return data type of the following functions : [2] \n(i) startsWith( ) \n(ii) random( ) \n(r) If the value of basic=1500, what will be the value of tax after the following statement is executed? [2] \ntax = basic > 1200 ? 200 : 100; \nid) Give the output of following code and mention how many times the loop will execute ? [2] \nint i; \nfor(i=5; i> =l;i~) \n{ \nif(i%2 ==1) \ncontinue; \nSystem.out.print(i+ ” \n} \n(e) State a difference between call by value and call by reference. [2] \n(f) Give the output of the following: [2] \nMath.sqrt(Math.max(9, 16)) \n(g) Write the output for the following: [2] \nString s1 = “phoenix”; String s2 =”island”; \nSystem.out.prindn (s1.substring(0).concat (s2.substring(2))); \nSystem.out.println(s2.toUpperCase( )); \n(h) Evaluate the following expression if the value ofx=2,y=3 and z=1. [2] \nv=x+–z+y+ + +y \n(i) String x[ ] = {“Artificial intelligence”, “IOT”, “Machine learning”, “Big data”}; [2] \nGive the output of the following statements: \n(i) System.out.prindn(x[3]); \n(ii) System.out.prindn(x.length); \n(j) What is meant by a package? Give an example. [2] \nSolution. \n(a) Math.abs((x * x) + (2 * x * y); \n(b) (i) boolean \n(ii) double \n(c) 200 \n(d) 4 2 \nLoop will execute 5 times.<\/p>\n(e)<\/p>\n \n\n\nCall by Value<\/strong><\/td>\nCall by Reference<\/strong><\/td>\n<\/tr>\n\n(i) In call by value the method creates its new set of variables (formal parameters) to copy the value of actual parameters and works with them.<\/td>\n | (i) In call by reference, reference of the actual parameters is passed on to the method. No new set of variables is created.<\/td>\n<\/tr>\n | \n(ii) Any change made in the formal parameter is not reflected in the actual parameter.<\/td>\n | (ii) Any change made in the formal parameter is always reflected in the actual parameters.<\/td>\n<\/tr>\n | \n(iii) Primitive data types are passed by call by value.<\/td>\n | (iii) Reference types like (objects, array etc.) are passed by call by reference.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n (f) 4.0 \n(g) phoenix land \nISLAND<\/p>\n (h) = 2 + 0 + 3 + 4 \n(i) (i) Big data \n(ii) 4 \n(j)\u00a0A package is an organized collection of classes which is included in the program as per the\u00a0requirement of the program. For example java.io package is included for input and output\u00a0operations in a program.<\/p>\n Section -B [60 Marks]<\/strong> \nAttempt any four questions from this Section \nThe answers in this Section should consist of the Programs in either Blue J environment or any \nprogram environment with Java as the base. \nEach program should be written using Variable descriptions\/Mnemonic Codes so that the logic of \nthe program is clearly depicted. \nFlow-Charts and Algorithms are not required.<\/p>\nQuestion 4. \nDesign a class name ShowRoom with the following description : \nInstance variables\/ Data members : \nString name – To store the name of the customer \nlong mobno – To store the mobile number of the customer \ndouble cost – To store the cost of the items purchased \ndouble dis – To store the discount amount \ndouble amount – To store the amount to be paid after discount \nMember methods: – \nShowRoom() – default constructor to initialize data members \nvoid input() – To input customer name, mobile number, cost \nvoid calculate() – To calculate discount on the cost of purchased items, based on following criteria<\/p>\n \n\n\nCost<\/strong><\/td>\nDiscount (in percentage)<\/strong><\/td>\n<\/tr>\n\nLess than or equal to \u20b9 10000<\/td>\n | 5%<\/td>\n<\/tr>\n | \nMore than \u20b9 10000 and less than or equal to \u20b9 20000<\/td>\n | 10%<\/td>\n<\/tr>\n | \nMore than \u20b9 20000 and less than or equal to \u20b9 35000<\/td>\n | 15%<\/td>\n<\/tr>\n | \nMore than \u20b9 35000<\/td>\n | 20%<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n void display() – To display customer name, mobile number, amount to be paid after discount \nWrite a main method to create an object of the class and call the above member methods. \nSolution. \nimport java.io.*; \nimport java.util.*; \nclass ShowRoom { \nString name; \nlong mobno; \ndouble cost; \ndouble dis; \ndouble amount; \nShowRoom( ) { \nname = ” “; \nmobno =0; \ncost = 0; \ndis = 0; \namount = 0; \n} \nvoid input( ) { \nScanner sc = new Scanner(System.in); \nSystem.out.println(“EnterName:”); \nname = sc.nextLine( ); \nSystem.out.println(“Enter Mobile number:”); \nmobno = sc.nextLong( ); \nSystem.out.println(“Enter cost:”); \ncost = sc.nextDouble( ); \n} \nvoid calculate( ) { \nif (cost <= 10000){ \ndis cost*5\/100; \namount = cost – dis; \n} \nelse \nif (cost > 10000 && cost < = 20000){ \ndis = cost* 10\/100; \namount cost – dis; \n} \nelse \nif (cost > 20000 && cost < = 35000){ \ndis = cost* 15\/100; \namount = cost – dis; \n} \nelse \nif (cost > 35000){ \ndis = cost*20\/100; \namount = cost – dis; \n} \n} \nvoid display( ) { \nSystem.out.println(“Name::” +name); \nSystem.out.println(“Mobile No.::” +mobno); \nSystem.out.println(“Amount::” +amount); \n} \npublic static void main(String args( )) { \nShowRoom ob = new ShowRoom( ); \nob.input( ); \nob.calculate( ); \nob.display( ); \n} \n}<\/p>\n Question 5. \nUsing the switch-case statement, write a menu driven program to do the following : [15] \n(a) To generate and print Letters from A to Z and their Unicode Letters Unicode \n<\/p>\n (b) Display the following pattern using iteration (looping) statement: 1 \n \nSolution. \nimport java.io.*; \nimport java.util.*; \nclass SwitchCase { \npublic static void main(String args[ ]) { \nScanner sc = new Scanner (System.in); \nSystem.out.println(” 1. Enter 1 for Unicode:”); \nSystem.out.prindn(” 2. Enter 2 for Pattern:”); \nSystem.out.println(“Enter your choice:”); \nint choice sc.nextlntO; \nswitch(choice){ \ncase 1: \nchar ch; \nSystem.out.println( “Letters \\t Unicode”); \nfor (ch = ‘A’; ch < = ‘Z’; ch+ +) { \nSystem.out.println(ch +”\\t” + (int)ch); \n} \nbreak; \ncase 2: \nint i, j; \nfor (i = 1; i < = 5; i+ +) { \nfor (j = 1; j < = i; j + +) \n{ \nSystem.out.print(j + “”);. \n} \nSystem.out.printlnO; \n} \nbreak; \ndefault: \nSystem.out.println(“Wrong choice entered:”); \n} \n} \n}<\/p>\n Question 6. \nWrite a program to input 15 integer elements in an array and sort them in ascending order using the bubble sort technique. [15] \nSolution. \nimport java.io.*; \nimport java.util\u2019*; \nclass AscendingOrder { \npublic static void main(String args[]) { \nint i, j, temp; \nScanner sc = new Scanner(System.in); \nint arr[] = new int[15]; \nSystem.out.println(“Enter 15 integers:”); \nfor (i = 0; i < = 15; i+ +) { \narr[i] = sc.nextlntO; \nfor(i = 0; i < 14; i++){ \nfor(j = 0; j < 14 -i; j + +){ \nif(arr[j] > arr[j + 1]){ \ntemp = arr[j]; \narr[j] = arr [j + 1]; \narr[j + 1] = temp; \n} \n} \n} \nSystem.out.println(“Elements in ascending order are::”); \nfor (i = 0; i < 15; i+ +) { \nSystem.out.println(arr[i]); \n} \n} \n} \n}<\/p>\n Question 7. \nDesign a class to overload a function series() as follows: [15] \n(a) void series (int x, int n) – To display the sum of the series given below: \nx1<\/sup> + x2<\/sup> + x3<\/sup> + ……………. xn<\/sup> terms \n(b) void series (int p) – To display the following series: \n0, 7, 26, 63 p terms. \n(c) void series () – To display the sum of the series given below: \n \nSolution. \nimport java.io.*; \nimport java.util.*; \nclass OverloadSeries { \nvoid series( int x, int n) { \nint i; . \ndouble a; \ndouble sum = 0; \nfor (i = 1; i < = n; i++) { \na = Math.pow(x, i); \nsum = sum + a; \n} \nSystem.out.prindn(“Sum::” +sum)r \n} \nvoid series(int p) { \nint i; \nfor (i = 1; i < = p; i++) { \nSystem.out.prindn((i * i * i) – 1 + ” “); \n} \n} \nvoid series() { \ndouble i; \ndouble s = 0; \nfor (i =-2; i < = 10; i+ +) { \ns = s + 1\/i; \n} \nSystem.out.println(“Sum:\u201d +s); \n} \n}<\/p>\nQuestion 8. \nWrite a program to input a sentence and convert it into uppercase and count and display the total number of words starting with a letter ‘A’. [15] \nExample: \nSample Input: ADVANCEMENT AND APPLICATION OF INFORMATION TECHNOLOGY ARE EVER CHANGING. \nSample Output : Total number of words starting with letter A’ = 4. \nSolution. \nimport java.io.*; \nimport java.util.*; \nclass UpperCount { \npublic static void main(String args[ ]) { \nint i, a; \nScanner sc = new Scanner(System.in); \nString str, str1, str2; \nSystem.out.prindn(“Enter sentence::”); \nstr = sc.nextLine(); \nstrl = str.toUpperCaseO; ‘ \nstr2 = “” + strl; \na = 0; , \nfor (i = 0; i < = str2.1ength(); i+ +) { \nif(str2.charAt(i) == ‘ ‘) \nif(str2.charAt(i + 1) == ‘A’); \na+ +; \n} \nSystem.out.println(“Total number of words starting with letter ‘A’::” +a); \n} \n}<\/p>\n Question 9. \nA tech number has even number of digits. If the number is split in two equal halves, then the square of sum of these halves is equal to the number itself. Write a program to generate and print all four digit tech numbers. [15] \nExample : \nConsider the number 3025 \nSquare of sum of the halves of 3025 = (30+25)2<\/sup> \n= (55)2<\/sup> \n= 3025 is a tech number. \nSolution. \nimport java.io.*; \nimport java.util.*; \nclass TechNumber { \npublic static void main(String args[ ]) { \nint i, a, b, sum; \nString n; \nSystem.out.println(“Four Digits Tech Numbers are::”); \nfor(i = 1000; i < 1000; i+ +) { \nn = i +””; \na = lnteger,parselnt(n.substring(0, 2)); \nb = Integer.parselnt(n.substring(2)); \nsum = (int)Math.pow((a + b), 2); \nif (sum == i) \nSystem.out.println(i); \n} \n} \n}<\/p>\n | | | | | | |