Practice

__Questions__ 1. What are the vertices of the rectangle created by: new FramedRect (80, 40, 20, 30, canvas) 2. What is the command that creates an arc of ninety degrees contained within the square with vertices (0,5) (10,0) (5,5) (10,5)? (two possible answers, find both) 3. Write a command that can be used to output "hi there", quotes included. 4. Given x=10 and y=5, what is the output of System.out.println(""+x+y);? 5. Given System.out.print("number" + 6 + 4 * 5);, what is the output? 6. What will z equal if the following assignment statement is executed? double z = 5/10 7. What is the order in which the operators will be applied in the following statement? a = (b+c) * d / e - f 8. True or false? A double is wider than an int. 9. True or false? A variable of type boolean will store either a 0 or 1. 10. True or false? The mod operator, %, can only be performed on int values and its result is a double. 11. True or false? Because double to an int is lowering precision, there is no way to convert a double to an int. 12. Write code to prompt the user for an int value and input it using the Scanner class into the variable x and prompt the user for a double value and input it into the variable y. 13. Write code which will prompt the user to input 3 int values, compute the average, and output the result as a double. 14. Write code to correctly exchange values of x and y given that they are 6 and 10 respectively. 15. Write code that creates an array called box which holds 20 framed rectangles. Afterwards, make variables height and width and set them to 50. Make variables x and y, setting them to 1. 16. Building off of question 15, make a for loop that creates the 20 rectangles, 5 per row in four rows. Make the first rectangle have vertices (50,50) (100,50) (50,100) (100,100). The second rectangle should have vertices (125,50) (125,100) (175,50) (175,100). The sixth rectangle should have vertices (50,125) (50,175) (100,125) (100, 175). 17. What is the correct way to have a long string be in two different lines of code? 18. What is the output of the following lines of code? int x = 5; int y = 10; sumXY = x + y; System.out.println("The sum of x + y equals: sumXY); 19. What is the value of the variable result? int n = 4; result = (n+2) / 3 + n / 2; 20. String pokemon = "Charizard"; pokemon.compareTo(Charmander); 21. pokemon.length/2; (see 20) 22. pokemon.substring(3, 9); (see 20) 23. What is the value of the variable result? int n = 6; result = (6%5) + 3 * 4 -2; 24. How do you get the row number of something in gridworld? 25. How do you get the column number of something in gridworld? 26. If 5 = x, x = y, and x is set to temp, what is temp * (x + temp) + y;? 27. How many times is hello printed? for(int i = 0; i <= 5; i++) { System.out.println("Hello"); } 28. What is the value of the variable result? result = (double) (7/3); 29. True or false? For loop is the most useful loop in programming. 30. String pokemon = "Geodude"; pokemon.indexOf("dud"); 31. pokemon.equals("geodude "); (refer to #30) 32. pokemon.substring("geo"); 33. pokemon.substring(3); 34. String pokemon = "Articuno"; pokemon.length; 35. System.out.println("pokemon.substring(6) + " " + pokemon.substring(0, 3)"); What are three benefits of an array list? (in any order) 36. 37. 38.

__Answers__ 1. (80,40) (100, 40) (80, 70) (100, 70) 2. new FIlledArc(0, 0, 10, 10, 0, 90, canvas); or new FilledArc(5, 0, 10, 10, 90, 90, canvas);. 3. System.out.println("\"hi there\""); 4. 105 5. number620 6. 0.0 7. +, *, /, - 8. true 9. false 10. false 11. false 12. Scanner scan = new Scanner(System.in); System.out.println("Enter an integer value"); x = scan.nextInt; System.out.println("Enter a double value"); y = scan.nextDouble; 13. double average; Scanner scan = new Scanner(System.in); System.out.println("Enter integer values one after another 3 times"); x = scan.nextInt; y = scan.nextInt; z = scan.nextInt; average = (x+y+z)/ 3.0; System.out.println("The result of my calculation is" + average); 14. int temp = x; x = y; y = temp; 15. FramedRect[ ] box = new FramedRect[20]; int height = 50, width = 50; int x = 1, y = 1; 16. ***note - make x and y doubles or this code will not work for (int i = 0; i<20; i++) { box[i] = new FramedRect(x * width, y * height, width, height, canvas); x = x + 1.5; if (x == 8.5) //makes it so there are 5 boxes in each row { y = y + 1.5; x = 1; } } 17. concatenation 18. The answer is that there is no output. A quote mark is missing 19. 4 20. -1 21. 4 22. error 23. 11 24. getNumRows; 25. getNumCols; 26. 55 27. 6 28. 2.0 29. false. the while loop is. 30. 3 31. false 32. error. An index is needed, but a string. 33. dude 34. 8 35. no Art 36. slots can be changed 37. slots can be added 38. can hold more than one object