JAVA PROBLEMS SOLVED

Redo Exercise 9 using do. . .while loops. 9. Write a program that uses while loops to perform the following steps: a. Prompt the user to input two integers: firstNum and secondNum. (firstNum must be less than secondNum.) b. Output all the odd numbers between firstNum and secondNum inclusive. c. Output the sum of all the even numbers between firstNum and secondNum inclusive. d. Output all the numbers and their squares between 1 and 10. e. Output the sum of the squares of all the odd numbers between firstNum and secondNum inclusive. f. Output all the uppercase letters. Step-by-step solution Comment Use of do…while loops Program Plan: Use nextInt method of the Scanner class to read two integers from the keyboard. Use do…while loop to iterate as many times as the difference between the numbers entered by the user to print odd numbers. If a number is divisible by 2, it is even, otherwise it is odd. Display the output. Comment Program: a. Use Scanner class methods to get input from keyboard. /********************************************************** * The program demonstrates using of a while loop, to * * print numbers, their squares and also uppercase letters* *********************************************************/ import java.util.Scanner; //Class definition Step 1 of 8 Step 2 of 8 Step 3 of 8 My Textbook Solutions Java Programming 5th Edition Meriam Engineering… 7th Edition Engineering Economy 7th Edition View all solutions Post a question Answers from our experts for your tough homework questions Enter question Continue to post 20 questions remaining Snap a photo from your phone to post a question We’ll send you a one-time download link 888-888-8888 Text me By providing your phone number, you agree to rec a one-time automated text message with a link to g the app. Standard messaging rates may apply. Stay ahead in class with practice exams Find solutions for your homework Chapter 5, Problem 11PE Bookmark Search Show all steps: ON Textbook Solutions Expert Q&A Study Pack Practice  public class DoWhileLoop { //Create a scanner static Scanner console = new Scanner(System.in); //Main function public static void main(String args[]) { // declare variables and get two numbers as input System.out.print(“Input two positive integers: “); //Read the input values int firstNum = console.nextInt(); int secondNum = console.nextInt(); System.out.println(); Comment b. If a number is not divisible by 2, then it is odd, otherwise it is even. //Declare variable i which is equal to firstNum, //evenSum to track the sum of even numbers int i = firstNum,evenSum = 0; System.out.print(“Odd numbers between “+firstNum+ ” and “+secondNum+” are: “); do { //if i is not divisible by 2, then it is odd if( i%2 != 0) System.out.print(i+” “) ; else // if i is divisible by 2, then it is even, add it to // evenSum evenSum = evenSum + i; i++; } //if i is less than secondNum continue the iteration while( i <= secondNum) System.out.println(); Comment c. Print sum of even numbers as calculated above. System.out.println(“sum of even numbers: “+evenSum) ; d.To output numbers and their sqaures between from 1 to 10 declare a variable ‘number’ initialised to 1, run the loop 10 times each time printing the number and its square. //Declare variable ‘squareSum’ to track sum of squares int number = 1,squareSum = 0; do Step 4 of 8 Step 5 of 8 Stay ahead in class with practice exams Chapter 5, Problem 11PE Bookmark Show all steps: ON Textbook Solutions Expert Q&A Study Pack Practice  { //print number and its square System.out.println(number+ “‘s square is:”+(number*number)) ; Comment e. update the variable squareSum tracking the sums of the squares of odd numbers. if(number %2!=0) //Track sum of squares of odd numbers squareSum = squareSum + (number*number); number++; // increment the variable } //if value in number is less than or equal to 10, // go to the next interation while(number <= 10); // print sum of squares of odd numbers System.out.println(“Sum of squares of odd numbers is: “+squareSum); Comment f. To output all upper case letters initialize variable a to 0 and run the loop as many times as the number of letters. int a = 0; // loop 26 times do { // ASCII value of A is 65, each time add 65 to a // type cast it into char and print it. System.out.print((char)(a+65)+” “); a++; } } while(a <= 25); // loop 26 times } Comment Sample Output: Input two positive integers: 1 10 Odd numbers between 1 and 10 are: 1 3 5 7 9 sum of even numbers: 30 1’s square is: 1 2’s square is: 4

Rewrite the following as a for loop: What is the output of this loop? Step-by-step solution Modified for loop Initialize the variable value and control variable i to zero, give the conditional expression that i is less than or equal to 20 and give the update statement, i should be incremented after every iteration. //for loop defintion for(i=0, value = 0; i <= 20; i++) { //Check the values if (i % 2 == 0 && i <= 10) //Compute value value = value + i * i; else if (i % 2 == 0 && i > 10) //Compute value value = value + i; else //Compute value value = value – i; } //Display output System.out.println(“value = ” + value); Step 1 of 2 My Textbook Solutions Java Programming 5th Edition Meriam Engineering… 7th Edition Engineering Economy 7th Edition View all solutions Post a question Answers from our experts for your tough homework questions Enter question Continue to post 20 questions remaining Snap a photo from your phone to post a question We’ll send you a one-time download link 888-888-8888 Text me By providing your phone number, you agree to rec a one-time automated text message with a link to g the app. Standard messaging rates may apply. Stay ahead in class with practice exams Find solutions for your homework Chapter 5, Problem 34E 1 Bookmark Search Show all steps: ON Textbook Solutions Expert Q&A Study Pack Practice  Recommended solutions for you in Chapter 5 Was this solution helpful? Output: value = 200 Comment The loop runs iterates for 21 times as the control variable increments its value by 1 each time from 0 to 20. According to the given if statement, for i with values 0, 2 , 4 , 6 , 8, 10. value = value + i * i; for i with values 12, 14 , 16 , 18, 20 value = value + i; for all other values of i value = value – i; For each value of i, the variable value changes as follows: i = 0 value = 0 i = 1 value = -1 i = 2 value = 3 i = 3 value = 0 i = 4 value = 16 i = 5 value = 11 i = 6 value = 47 i = 7 value = 40 i = 8 value = 104 i = 9 value = 95 i = 10 value = 195 i = 11 value = 184 i = 12 value = 196 i = 13 value = 183 i = 14 value = 197 i = 15 value = 182 i = 16 value = 198 i = 17 value = 181 i = 18 value = 199 i = 19 value = 180 i = 20 value = 200

Correct the following code so that it finds the sum of 10 numbers: sum = 0; Step-by-step solution Code Correction to Intended Output Declare the necessary variables to track sum of the variables, to count the number integers, to store numbers received as input. int sum = 0, count = 0, num; Enclose the loop statements in a block using braces while(count < 10) { num = console.nextInt(); sum = sum + num; count++; } Write the print statement to display the sum of 10 integers. System.out.println(“Sum = ” + sum); Sample Run: 1 2 3 4 5 6 7 8 9 10 Sum = 55

Example 5-6 implements the Guessing the Number game program. If the guessed number is not correct, the program outputs a message indicating whether the guess is low or high. Modify the program as follows: Suppose that the variables num and guess are as declared in Example 5-6 and diff is an int variable. Let diff = the absolute value of (num – guess). If diff is 0, then guess is correct and the program outputs a message indicating that the user guessed the correct number. Suppose diff is not 0. Then, the program outputs the message as follows: a. If diff is greater than or equal to 50, the program outputs the message indicating that the guess is very high (if guess is greater than num) or very low (if guess is less than num). b. If diff is greater than or equal to 30 and less than 50, the program outputs the message indicating that the guess is high (if guess is greater than num) or low (if guess is less than num). c. If diff is greater than or equal to 15 and less than 30, the program outputs the message indicating that the guess is moderately high (if guess is greater than num) or moderately low (if guess is less than num). d. If diff is greater than 0 and less than 15, the program outputs the message indicating that the guess is somewhat high (if guess is greater than num) or somewhat low (if guess is less than num). As in Programming Exercise 16, give the user, at most, five tries to guess the number. (To find the absolute value of num – guess, use the expression Math.abs(num – guess).) My Textbook Solutions Java Programming 5th Edition Meriam Engineering… 7th Edition Engineering Economy 7th Edition View all solutions Post a question Answers from our experts for your tough homework questions Enter question Continue to post 20 questions remaining Snap a photo from your phone to post a question We’ll send you a one-time download link 888-888-8888 Text me By providing your phone number, you agree to rec a one-time automated text message with a link to g the app. Standard messaging rates may apply. Stay ahead in class with practice exams Find solutions for your homework Search Textbook Solutions Expert Q&A Study Pack Practice  Stay ahead in class with practice exams Textbook Solutions Expert Q&A Study Pack Practice  Step-by-step solution Program Plan: • Create a class named GuessNumber. • Use random method of the Math class to generate a random number and store it in a variable. • Use nextInt method of the Scanner class to get a number from the keyboard. • Use a while loop, which iterates to prompt the user to guess the randomly generated number. • Find difference between the random number and guess number entered by the user. Based on the difference and using if statements display an appropriate message to the user to re-enter the number if the user did not guess the number correctly in the previous attempt. • Use a counter variable which tracks the number of times the user guesses the number. If number of tries reaches 5, break from the loop and display message that the user lost the game. Comment Program: /********************************************************** *The program generates a random number and prompts a user* *to guess the number. It displays an appropriate message * *based on the number entered in the previous attempt, * *which may help the user to guess correctly, in the next * *attempt. * *********************************************************/ //Import java file import java.util.*; //Class definition Step 1 of 4 Step 2 of 4 Stay ahead in class with practice exams Textbook Solutions Expert Q&A Study Pack Practice  public class GuessNumber { //Create a scanner static Scanner console = new Scanner(System.in); //Main function public static void main(String args[]) { //Variable to store random number int random; //Variable to store the number guessed by the user int guessNumber; //Boolean variable to control the loop boolean done; Generate a random number and store it in a variable random = (int)(Math.random() * 100); done = false; Declare variable to track the number of tries int count = 5; Loop iterates, prompting the user to guess the number. If user guesses correctly, the loop condition fails and there are no further iterations. while(!done) { System.out.println(“Enter an integer greater than or equal to 0 and less than 100:”+ ” \n You have “+count+” chances.”); guessNumber = console.nextInt(); System.out.println(); Declare variable to contain the difference between number guessed by user and random number. int diff = Math.abs(guessNumber – random); // if difference is equal to zero,the guess number is correct if ( diff == 0 ) { System.out.println(“You guessed the correct number. \n YOU WIN !!!”); done = true; } Comment a) Check if difference is greater than or equal to 50 else if ( diff >= 50 ) { if(guessNumber > random) System.out.println(“Your guess is very high.”); else System.out.println(“Your guess is very low.”); } b) Check if difference is greater than or equal to 30, and less than 50 Step 3 of 4 Stay ahead in class with practice exams Textbook Solutions Expert Q&A Study Pack Practice  else if (( diff >= 30 )&&( diff < 50 )) { if(guessNumber > random) System.out.println(“Your guess is high.”); else System.out.println(“Your guess is low.”); } C) Check if difference is greater than or equal to 15, and less than 30 else if (( diff >= 15 )&&( diff < 30 )) { if(guessNumber > random) System.out.println(“Your guess is moderately high.”); else System.out.println(“Your guess is moderately low.”); } d) Check if difference is greater than 0, and less than 15 else if (( diff > 0 )&&( diff < 15 )) { if(guessNumber > random) System.out.println(“Your guess is somewhat high.”); else System.out.println(“Your guess is somewhat low.”); } Update the counter after each guess by the user, if the user exceeds the number of chances, stop the iterations and print an appropriate message // decrement the counter after each guess count–; // check if the counter is equal to 0 if(count <= 0 ) { // print a message System.out.println(“You exceeded the number of tries, You lose the game!”); break; // exit from the loop } } // end while } } Comment Sample Output: Enter an integer greater than or equal to 0 and less than 100: You have 5 chances. 50 Your guess is moderately low. Enter an integer greater than or equal to 0 and less than 100: Step 4 of 4 Stay ahead in class with practice exams Textbook Solutions Expert Q&A Study Pack Practice  COMPANY LEGAL & POLICIES CHEGG PRODUCTS AND SERVICES CHEGG NETWORK CUSTOMER SERVICE Recommended solutions for you in Chapter 5 See more problems in subjects you study Was this solution helpful? You have 4 chances. 60 Your guess is moderately low. Enter an integer greater than or equal to 0 and less than 100: You have 3 chances. 76 Your guess is somewhat low. Enter an integer greater than or equal to 0 and less than 100: You have 2 chances. 85 Your guess is somewhat high. Enter an integer greater than or equal to 0 and less than 100: You have 1 chances. 80 Your guess is somewhat high. You exceeded the number of tries, You lose the game!

To further learn how nested for loops work, do a walk-through of the following program segments and, in each case, determine the exact output. My Textbook Solutions Java Programming 5th Edition Meriam Engineering… 7th Edition Engineering Economy 7th Edition View all solutions Post a question Answers from our experts for your tough homework questions Enter question Continue to post 20 questions remaining Snap a photo from your phone to post a question We’ll send you a one-time download link 888-888-8888 Text me By providing your phone number, you agree to rec a one-time automated text message with a link to g the app. Standard messaging rates may apply. Stay ahead in class with practice exams Find solutions for your homework Search Textbook Solutions Expert Q&A Study Pack Practice  Step-by-step solution a. // declare the control variables int i,j; // outer loop will execute 5 times for(i=1; i<=5; i++) { /* Inner loop will execute 5 times for each iteration of outer loop print value of i in 3 spaces*/ for(j=1; j<=5; j++) System.out.printf(“%3d”, i); // print a newline for every iteration of outer loop System.out.println(); } For the outer loop, i is the control variable. The conditional statement and update statement sees that the loop runs for 5 times. For the inner loop, j is the control variable. The conditional statement and update statement sees that the inner loop also runs for 5 times for every iteration of the outer loop. The print statement prints the value of i in 3 spaces. For each iteration of the outer loop, the inner loop runs for 5 times. As the outer loop runs for 5 times, the inner loop runs for a total of 5 * 5 that is 25 times, each time printing the value of i. For i = 1, the inner loop prints 5 times the value of i. The output after first iteration of outer loop is: 1 1 1 1 1 For i = 2, the inner loop prints 5 times the value of i. The output after second iteration of outer loop is: 1 1 1 1 1 2 2 2 2 2 For i = 3, the inner loop prints 5 times the value of i. The output after third iteration of outer loop is: 1 1 1 1 1 2 2 2 2 2 3 3 3 3 3 For i = 4, the inner loop prints 5 times the value of i. The output after fourth iteration of outer loop is: 1 1 1 1 1 2 2 2 2 2 3 3 3 3 3 4 4 4 4 4 For i = 5, the inner loop prints 5 times the value of i. The output after fifth iteration of outer loop is: 1 1 1 1 1 2 2 2 2 2 3 3 3 3 3 4 4 4 4 4 5 5 5 5 5 Comment Step 1 of 6 Stay ahead in class with practice exams Textbook Solutions Expert Q&A Study Pack Practice  b. // declare the control variables int i,j; // outer loop will execute 5 times for(i=1; i<=5; i++) { /* Number of times inner loop will execute depends on the value of i. */ for(j = 1; j <= i; j++) // print value of j in 3 spaces System.out.printf(“%3d”, j); // print a newline for every iteration of outer loop System.out.println(); } For the outer loop, i is the control variable. The conditional statement and update statement sees that the loop runs for 5 times. For the inner loop, j is the control variable. The conditional statement and update statement see that the number of times inner loop will execute depends on the value of i. The print statement prints the value of j in 3 spaces. For i = 1, the inner loop runs 1 time. The output after first iteration of outer loop is: 1 For i = 2, the inner loop runs 2 times printing the value of j in each iteration. The output after second iteration of outer loop is: 1 1 2 For i = 3, the inner loop runs 3 times printing the value of j in each iteration. The output after third iteration of outer loop is: 1 1 2 1 2 3 For i = 4, the inner loop runs 4 times printing the value of j in each iteration. The output after fourth iteration of outer loop is: 1 1 2 1 2 3 1 2 3 4 For i = 5, the inner loop runs 5 times printing the value of j in each iteration. The output after fifth iteration of outer loop is: 1 1 2 1 2 3 1 2 3 4 1 2 3 4 5 Comment c. // declare the control variables Step 2 of 6 Step 3 of 6 Stay ahead in class with practice exams Textbook Solutions Expert Q&A Study Pack Practice  int i,j; // outer loop will execute 5 times for(i=1; i<=5; i++) { /*Number of times inner loop will execute depends on the value of i. */ for(j = (i + 1); j <= i; j++) // print value of j in 5 spaces System.out.printf(“%5d”, j); // print a newline for every iteration of outer loop System.out.println(); } For the outer loop, i is the control variable. The conditional statement and update statement sees that the loop runs for 5 times. For the inner loop, j is the control variable. However, the initial value of j and value of conditional expression depends on the value of i. In the first iteration of the outer loop, the inner loop will have j = i + 1 = 1 + 1 = 2 But the given condition, j<=1 evaluates to false. So the inner loop is never executed. For the second iteration of outer loop, the inner loop will have j = i + 1 = 2 + 1 = 3 But the given condition, j<=2 evaluates to false. The inner loop is again not executed. The process repeats for all the iterations of the outer loop, and the inner loop is never executed to run the print statement that should print the value of j. However, for each iteration of the outer loop, a newline is printed because of the println statement. Comment d. final int m = 10; final int n = 10; // declare the control variables int i,j; // as m = 10, outer loop will execute 10 times for(i = 1 ;i <= m; i++) { // as n = 10, inner loop will execute 10 times for(j = 1; j <= n; j++) System.out.printf(“%4d”, (m * (i-1) + j)); System.out.println(); } For the outer loop, i is the control variable. The conditional statement and update statement sees that the loop runs for 10 times. For the inner loop, j is the control variable. The conditional statement and update statement sees that the inner loop also runs for 10 times for every iteration of the outer loop. The print statement evaluates the expression, m * (i-1) + j) When i = 1, inner loop runs 10 times, value of j changes from 1 to 10. Print statement evaluates the expression each time and prints each value in 4 spaces. 1 2 3 4 5 6 7 8 9 10 When i = 2, again the loop runs for 10 times and output after second iteration. 1 2 3 4 5 6 7 8 9 10 Step 4 of 6 Stay ahead in class with practice exams Textbook Solutions Expert Q&A Study Pack Practice  Comment 11 12 13 14 15 16 17 18 19 20 The process repeats for each value of i. The output after the tenth iteration is, 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 Comment e. int i,j; // outer loop runs 9 times, once for each value of i for(i = 1 ;i <= 9; i++) { // loop to print spaces for(j = 1; j <= (9 – i); j++) System.out.print(” “); // loop to print value of j from 1 to i for(j = 1; j <= i; j++) System.out.print(j); // loop to print value of j from (i-1) to 1 for(j = (i-1); j >= 1; j–) System.out.print(j); System.out.println(); } The outer loop runs 9 times, once for each value of i changing from 1 to 9. For every iteration of the outer loop, 3 inner loops will run. For i = 1, The first inner loop will run 9-i that is 8 times and print 8 spaces. The second inner loop will run 1 time and print the value of j that is 1. The third inner loop will run i-1=0 times. Output after first iteration of outer loop: 1 For i = 2, The first inner loop will run 9-i that is 7 times and print 7 spaces. The second inner loop will run 2 times and print the values of j that is 12 . The third inner loop will run i-1=1 time and print the value of j that is 1. Output after second iteration of outer loop: Step 5 of 6 Step 6 of 6 Stay ahead in class with practice exams Textbook Solutions Expert Q&A Study Pack Practice  COMPANY LEGAL & POLICIES CHEGG PRODUCTS AND SERVICES Recommended solutions for you in Chapter 5 See more problems in subjects you study Was this solution helpful? 1 121 For i = 3, The first inner loop will run 9-i that is 6 times and print 6 spaces. The second inner loop will run 3 times and print the values of j that is 123 . The third inner loop will run i-1=2 times and print the values of j that is 21. Output after third iteration of outer loop: 1 121 12321 The process continues for each value of i. Output after ninth iteration of outer loop: 1 121 12321 1234321 123454321 12345654321 1234567654321 123456787654321 12345678987654321

Given the following program segment: Step-by-step solution Definition of while loop: First, initialize the variable number with 1. The conditional statement to check the value of number is less than or equal to 10. Give a print statement in the body to print the value in number and post increment it, so that number be update with the next integer. //Variable declaration int number = 1; //Repate the loop until number is less than or equal to 10 while(number <=10) //Display output System.out.print(number++ + ” “); System.out.println(); Comment Definition of DO-While loop: First, initialize the variable number with 1. Give a print statement in the body to print the value in number and post increment it. The conditional statement to check the value of number is less than or equal to 10. //Variable declaration int number = 1; do //Display output System.out.print(number++ + ” “); //Repate the loop until number is less than or equal to 10 while(number <=10); System.out.println(); Step 1 of 2 Step 2 of 2 My Textbook Solutions Java Programming 5th Edition Meriam Engineering… 7th Edition Engineering Economy 7th Edition View all solutions Post a question Answers from our experts for your tough homework questions Enter question Continue to post 20 questions remaining Snap a photo from your phone to post a question We’ll send you a one-time download link 888-888-8888 Text me By providing your phone number, you agree to rec a one-time automated text message with a link to g the app. Standard messaging rates may apply. Stay ahead in class with practice exa

Correct the following code so that it finds the sum of 10 numbers: sum = 0; Step-by-step solution Code Correction to Intended Output Declare the necessary variables to track sum of the variables, to count the number integers, to store numbers received as input. int sum = 0, count = 0, num; Enclose the loop statements in a block using braces while(count < 10) { num = console.nextInt(); sum = sum + num; count++; } Write the print statement to display the sum of 10 integers. System.out.println(“Sum = ” + sum); Sample Run: 1 2 3 4 5 6 7 8 9 10 Sum = 55

What is the difference between a pretest loop and a posttest loop? Step-by-step solution Difference between Pretest Loop and Posttest Loop A pretest loop tests the loop condition before executing the loop’s body. The body is executed only when the logical expression given as a condition evaluates to true. The loop continues to iterate as long as this condition is true. The loop terminates as soon as the condition becomes false, and the control goes to the statement after the loop’s body. Both while and for loops are examples of pretest loops. Comment Comment Comment Comment Step 1 of 18 Step 2 of 18 Step 3 of 18 Step 4 of 18 Step 5 of 18 My Textbook Solutions Java Programming 5th Edition Meriam Engineering… 7th Edition Engineering Economy 7th Edition View all solutions Post a question Answers from our experts for your tough homework questions Enter question Continue to post 20 questions remaining Snap a photo from your phone to post a question We’ll send you a one-time download link 888-888-8888 Text me By providing your phone number, you agree to rec a one-time automated text message with a link to g the app. Standard messaging rates may apply. Stay ahead in class with practice exams Find solutions for your homework Search Textbook Solutions Expert Q&A Study Pack Practice  Comment true false Comment A posttest loop tests the loop condition after executing the loop’s body. The body is executed prior to evaluating the logical expression. Next the condition is tested, if evaluated to true, the loop continues with the next iteration. The do-while loop is an example of posttest loop.

What does a break statement do in a loop? Step-by-step solution Break statement in Loop In a loop, the break statement helps you to immediately exit from the loop. After the break statement executes, the program continues to execute starting at the first statement after the loop structure. int num = 1; while( num <= 100 ) { if(num % 50 == 0 ) { break; } System.out.print(num + ” “); num++; } In the above lines of code, the while loop is supposed to execute for 100 times each time testing the if condition and printing the value of num. However, the condition in the if statement becomes true when num is equal to 50, inside which there is a break statement. When break is executed, the loop terminates and the remaining iterations of the loop are skipped, so the loop gets executed only 49 times instead of 100 times.

Mark the following statements as true or false. a. Every window has a width and height. b. In Java, JFrame is a class. c. To display the window, you need not invoke a method such as setVisible. d. In Java, the reserved word extends allows you to create a new class from an existing one. e. The window you see displayed on your screen is a class. f. Labels are used to display the output of a program. g. Every GUI component you need has to be created and added to a container. h. In Java, implements is a keyword. i. Clicking a button is an example of an action event. j. In a problem statement, every verb is a possible class. k. In a problem statement, every noun is a possible method. l. To use an object, you must know how it is implemented. Step-by-step solution a) In GUI applications the main component is window, everything is displayed inside the window. Windows are measured in pixels of height and width. So every window has some height and width. Hence the statement “Every window has a width and height” is True. Comment b) JFrame is a Pre-defined class presented in javax.swing package .This class main purpose is to create a Frame .Whenever we need a Frame ,we can create Frame by extending the JFrame class into our class. Comment Hence the statement “In java, JFrame is a class” statement is True. Comment Step 1 of 13 Step 2 of 13 Step 3 of 13 My Textbook Solutions Java Programming 5th Edition Meriam Engineering… 7th Edition Engineering Economy 7th Edition View all solutions Post a question Answers from our experts for your tough homework questions Enter question Continue to post 20 questions remaining Snap a photo from your phone to post a question We’ll send you a one-time download link 888-888-8888 Text me By providing your phone number, you agree to rec a one-time automated text message with a link to g the app. Standard messaging rates may apply. Stay ahead in class with practice exams Find solutions for your homework Search Textbook Solutions Expert Q&A Study Pack Practice  c) To display the window ,you need not invoke a method such as setVisible() method.setVisible () is a pre-defined method and by default it is set to false,so explicitly should invoke this method by passing the true value as parameter.Otherwise window is not visible. Hence the statement “To display the window , you need not invoke a method such as setVisible ” statement is False. Comment d) In java, the reserved word extends allows you to create a new class from the existing one. “extends” is a reserved word in java, which is used to extend the properties and behaviors of existing class into new class. extends is a keyword which is used in inheritance . Hence the statement “In java, the reserved word extends allows you to create a new class from an existing one ”is True. Comment e) In java,Every GUI program requires a window.A window represents the rectangular area on the screen without any border or title bar.window is a one of the main GUI component.window is a component not a class. Hence the statement “The window you see displayed on your screen is a class” is False. Comment f) Labels are used for display some information to user, then user can do accordingly. The main purpose is to display some information. Hence the statement “Labels are used to display the output of a program” is False. Comment g) Every GUI component is need to be created explicitly by the user. There are many number of classes which are available, by creating the object to those classes we can make use of componenets.We should add all the components to the container. If component is not added to container, it is not visible in the window. Hence the statement “Every GUI component you need has to be created and added to a container” is True. Comment h) “implements” is a reserved word in java .It is used in Interfaces, whenever we want to implement an interface into our class we use this keyword. It is used in two cases, they are • Between a class and interface Step 4 of 13 Step 5 of 13 Step 6 of 13 Step 7 of 13 Step 8 of 13 Step 9 of 13 Stay ahead in class with practice exams Textbook Solutions Expert Q&A Study Pack Practice  Recommended solutions for you in Chapter 6 Was this solution helpful? • Between two interfaces. Hence the statement “In java, implements is a keyword” is True. Comment i) Button is a pre-defined class, we can use this component by creating a object to it. When user clicks the button appropriate action will be raised. It invokes the actionPerformed (), which is available in Action Listener interface. Hence the statement “Clicking a button is an example of an action event” is True. Comment j) According to the problem we should define class. We can’t say every verb in a problem is a class, sometimes it may be and sometimes it may not be. Hence the statement “In a problem statement, every verb is a possible class” is False. Comment k) Method is a group of statements that perform a particular task repeatedly, we can’t say every noun in problem is a method, according to the requirement for solution we will define methods. Hence the statement “In a problem statement, every noun is a possible class” is False. Comment l) To use an object, no need to know how the object methods are implemented. It is necessary to know only what the arguments to pass to the object are. Without knowing internal implementations of the object, we can use object. Hence the statement “To use an object, you must know how it is implemented” is False

Leave a Reply