If a number is entered into the bottom textfield and

This preview shows page 16 - 24 out of 39 pages.

? If a number is entered into the bottom TextField and the return key is pressed, then a number twice as big will be placed in the top TextField . A skeleton of the Applet is provided below. You must complete all the methods given. Add any instance variables you will need . You may find the following extract from the Java API useful: public final class String { // Public Instance Methods public String toUpperCase (); } Complete the following applet: public class Q6 extends Applet implements ActionListener{ //Instance variables Initial Applet Any number entered in the lower TextField will be doubled and the result placed in the upper TextField Any text entered in the upper TextField will be converted to capital letters (upper case) and the result placed in the lower TextField
Image of page 16

Subscribe to view the full document.

Question/Answer Sheet - 17 - 415.101ST Surname: ................................ Forenames: ................................ CONTINUED
Image of page 17
Question/Answer Sheet - 18 - 415.101ST Surname: ................................ Forenames: ................................ CONTINUED public void init(){ } public void actionPerformed(ActionEvent e){ } public void copyText(TextField t1, TextField t2){ } public String doubleString(String s){
Image of page 18

Subscribe to view the full document.

Question/Answer Sheet - 19 - 415.101ST Surname: ................................ Forenames: ................................ CONTINUED } } (10 Marks)
Image of page 19
Question/Answer Sheet - 20 - 415.101ST Surname: ................................ Forenames: ................................ CONTINUED Question 7 (10 marks) Complete the following method, which is passed an array of String s as a parameter, and reverses all the elements in the array. In other words, the String in the first position of the array should be swapped with the String in the last position of the array, the String in the second position of the array should be swapped with the String in the second to last position of the array, and so on. Notice that this method is void, so it does not return anything - it must modify the array which is passed to it as a parameter. public void reverse(String[] s) { .... } For example, the following code segment: String[] advice = {"fail", "to", "plan"}; for (int i = 0; i < advice.length; i++) System.out.println(advice[i]); reverse(advice); for (int i = 0; i < advice.length; i++) System.out.println(advice[i]); should produce this output: fail to plan plan to fail Write your code here: public void reverse(String[] s) {
Image of page 20

Subscribe to view the full document.

Question/Answer Sheet - 21 - 415.101ST Surname: ................................ Forenames: ................................ CONTINUED } (10 marks)
Image of page 21
Question/Answer Sheet - 22 - 415.101ST Surname: ................................ Forenames: ................................ CONTINUED Question 8 (12 marks) In the following applet the user is able to create new Shapes objects by pressing the 'ADD SHAPE' button; the new Shapes object is constructed at random to be either a filled circle, a filled square, an unfilled circle or an unfilled square in a random position in the applet area. You must use an array of Shape s objects in your solution. The size of the array is specified by the constant MAX_NO_OF_SHAPES which has already been declared in the applet.
Image of page 22

Subscribe to view the full document.

Question/Answer Sheet - 23 - 415.101ST Surname: ................................ Forenames: ................................ CONTINUED The class definition for the Shapes class is shown below (the code for this class should not be changed at all): import java.awt.*; public class Shapes { private static final int CIRCLE = 0; private static final int SQUARE = 1; private static final int SIZE = 40; private int shapeType; /** 0 for circle shape, 1 for a square */ private boolean filledShape;/** true if circle/square is filled */ private Point centrePt;
Image of page 23
Image of page 24
You've reached the end of this preview.
  • Summer '12
  • AdrianaFerraro
  • Computer Science, Subroutine, ........., Eye class

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    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.

    Student Picture

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

  • Left Quote Icon

    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.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    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.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern