2000ACTestQuestions

# 101ac test page 6 question 5 8 marks write a method

• Notes
• UltraLightningCobra8457
• 18

This preview shows page 6 - 11 out of 18 pages.

415.101AC Test January 31 2000 page 6 Question 5 (8 marks) Write a method called shortThenLong which takes two Strings as parameters and returns the String which is formed by joining the longer of the two Strings to the end of the shorter of the two Strings. If the Strings are both the same length, then the order in which one String is joined to the other does not matter. If the following statements were executed: System.out.println(shortThenLong(" Anniversary ", " Happy ")); System.out.println(shortThenLong(" to ", " you ")); the output should be: Happy Anniversary to you

Subscribe to view the full document.

415.101AC Test January 31 2000 page 7 Question 6 (4 marks) Do the following boolean expressions evaluate to true or false? int a = 34; int b = 56; int c = 62; (a < b) && !(b < c) (a < b && a >= c) || (c < b)
415.101AC Test January 31 2000 page 8 Question 7 (12 marks) Complete the following Applet so that it executes as follows: the user types in an x, y value into two TextFields and then presses either the “From Left” or the “From Right” button. If the user presses the “From Left” button a blue circle (size 30 pixels) is drawn in position x , y of the Applet. If the user presses the “From Right” button a red circle (size 30 pixels) is drawn x pixels in from the right of the Applet and y pixels down from the top of the Applet. The top left corner of the red circle has to be (x + the size of the circle) pixels in from the right of the Applet (see the example screen shots below). The Applet is 300 pixels in width. Complete the Applet below:. import java.awt.*; import java.applet.*; import java.awt.event.*; public class Q7 extends Applet implements ActionListener { /** width and height of oval */ static final int SIZE = 30; /** applet width */ static final int APP_WIDTH = 300; /** TextFields to hold x,y position of circle */ private TextField xPosT, yPosT; /** Buttons for drawing circle from Applet left or right */ private Button fromLeftB, fromRightB; /** true if circle is drawn from left of applet */ private boolean fromLeft; /** x,y position of the circle*/ private int xPos, yPos;

Subscribe to view the full document.

415.101AC Test January 31 2000 page 9 public void init() { xPosT = new TextField(5); //set up TextFields and Buttons add(xPosT); yPosT = new TextField(5); add(yPosT); fromLeftB = new Button("From Left"); fromLeftB.addActionListener(this); add(fromLeftB); fromRightB = new Button("From Right"); fromRightB.addActionListener(this); add(fromRightB); xPos = 100; yPos = 100; fromLeft = false; } //end of init() method public void actionPerformed(ActionEvent e){ }//end of actionPerformed() method public void paint(Graphics g){ }//end of paint() method }//end of Applet
415.101AC Test January 31 2000 page 10 Question 8 (7 marks) An application program executes as follows: first the user is asked to enter: The number of items required, The cost of each item, The amount inserted by the user.

Subscribe to view the full document.

You've reached the end of this preview.
• Summer '12
• English-language films, Following, Denys Cowan

{[ snackBarMessage ]}

### What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern