The screenshots below show the jpanel after the user

This preview shows page 10 - 14 out of 26 pages.

The screenshots below show the JPanel after the user has entered values in the top two JTextField s and pressed the "CALCULATE PAY" button.
Image of page 10

Subscribe to view the full document.

- 11 - COMPSCI 101 Question/Answer Sheet ID: ..................................................................... CONTINUED import java.awt.*; import java.awt.event.*; import javax.swing.*; public class PayJPanel extends JPanel implements ActionListener { private JTextField weekdayHrsT, weekendHrsT, payT; private JLabel weekdayHrsL, weekendHrsL, payL; private JButton calculatePayB; public PayJPanel() { weekdayHrsT = new JTextField(5); weekendHrsT = new JTextField(5); payT = new JTextField(10); calculatePayB = new JButton("CALCULATE PAY"); calculatePayB.addActionListener(this); weekdayHrsL = new JLabel("Weekday Hours"); weekendHrsL = new JLabel("Weekend Hours"); payL = new JLabel("Pay"); weekdayHrsT.setText("10"); weekendHrsT.setText("2"); payT.setText("$200"); add(weekdayHrsL); add(weekdayHrsT); add(weekendHrsL); add(weekendHrsT); add(payL); add(payT); add(calculatePayB); } public void actionPerformed ( ActionEvent e ) { final int WEEKDAY_PER_HOUR = 15; final int WEEKEND_PER_HOUR = 25; String hrsWeekDay, hrsWeekEnd; int numWeekDay, numWeekEnd, pay; hrsWeekDay = weekdayHrsT.getText(); hrsWeekDay = hrsWeekDay.trim(); numWeekDay = Integer.parseInt(hrsWeekDay); hrsWeekEnd = weekendHrsT.getText(); hrsWeekEnd = hrsWeekEnd.trim(); numWeekEnd = Integer.parseInt(hrsWeekEnd); pay = WEEKDAY_PER_HOUR*numWeekDay + WEEKEND_PER_HOUR*numWeekEnd; payT.setText("$" +pay); (12 marks) } }
Image of page 11
- 12 - COMPSCI 101 Question/Answer Sheet ID: ..................................................................... CONTINUED Question 7 (10 marks) For this question, you need to complete a method called process2D() . This method accepts a two-dimensional int array as a parameter and returns a new two-dimensional int array. The array which is returned by the method contains the same number of elements as the parameter array but each integer element is one greater than or one smaller than the corresponding element in the parameter array. The return array element is one less than the corresponding parameter array element if the parameter array element is zero or greater. The return array element is one greater than the corresponding parameter array element if the parameter array element is less than zero. For example, when the start() method below is executed with the completed process2D() method, the output would be: 2 2 -3 4 4 -5 -2 -1 -5 2 3 -3 1 1 -2 3 3 -4 -1 0 -4 1 2 -2 The start() method that produces the above output is shown below: public void start() { int[][] nums1 = { { 2, 2, -3, 4}, { 4, -5, -2, -1}, {-5, 2, 3, -3} }; int[][] nums2 = process2D( nums1 ); print2D(nums1); print2D(nums2); } The print2D() method called in the above example simply prints all the elements of a 2- dimensional array, one row at a time. The source code for this method is not given.
Image of page 12

Subscribe to view the full document.

- 13 - COMPSCI 101 Question/Answer Sheet ID: ..................................................................... CONTINUED Complete the process2D() method in the space provided below: private int[][] process2D(int[][] nums) { int rows = nums.length; int cols = nums[0].length; int[][] newNums = new int[rows][cols]; for(int i=0; i<rows; i++) { for(int j=0; j<cols; j++) { if (nums[i][j] >= 0) { newNums[i][j] = nums[i][j]-1; } else { newNums[i][j] = nums[i][j]+1; } } } return newNums; (10 marks) } private void print2D(int[][] nums) { /* This method displays the elements of the 2D array row by row.
Image of page 13
Image of page 14
You've reached the end of this preview.
  • Summer '12
  • AdrianaFerraro
  • Computer Science, English-language films, Following, Subroutine, ........., The Return

{[ 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