[Solved] OOP Lab 4

$25

File Name: OOP_Lab_4.zip
File Size: 84.78 KB

SKU: [Solved] OOP Lab 4 Category: Tag:
5/5 - (1 vote)
  1. Exercises

You are required to implement the following design as well as a main() method in another class to test your implementation:

  1. Using JOptionPane dialog called input dialogto ask users to input the users name and responds with a message dialog containing a greeting and the name that the user entered. (Refer to Chapter 3, section 3.6)

Fig. 1 | Obtaining user input from a dialog.

  1. Using class Graphics (from package awt), which provides various methods for drawing text and shapes onto the screen, and class JPanel (from package javax.swing), which provides an area on which we can draw, to create a simple application that draws four lines as shown in Figure 2. (Refer to Chapter 4, section 4.15)

Fig. 2 | Creating JFrame to display DrawPanel.

  1. Using loops and control statements to draw lines can lead to many interesting designs.
  2. Create the design in the left screen capture of Fig. 3. This design draws lines from the top-left corner, fanning them out until they cover the upper-left half of the panel. One approach is to divide the width and height into an equal number of steps (we found 15 steps worked well). The first endpoint of a line will always be in the top-left corner (0,

0). The second endpoint can be found by starting at the bottom-left corner and moving up one vertical step and right one horizontal step. Draw a line between the two endpoints. Continue moving up and to the right one step to find each successive endpoint. The figure should scale accordingly as you resize the window.

Fig. 3 | Lines fanning from a corner.

  1. Modify part (a) to have lines fan out from all four corners, as shown in the right screen capture of Fig. 3. Lines from opposite corners should intersect along the middle.
  2. Figure 4 displays two additional designs created using while loops and drawLine.
    1. Create the design in the left screen capture of Fig. 4. Begin by dividing each edge into an equal number of increments (we chose 15 again). The first line starts in the top-left corner and ends one step right on the bottom edge. For each successive line, move down one increment on the left edge and right one increment on the bottom edge. Continue drawing lines until you reach the bottom-right corner. The figure should scale as you resize the window so that the endpoints always touch the edges.
    2. Modify your answer in part (a) to mirror the design in all four corners, as shown in the right screen capture of Fig. 4.

Fig. 4 | Line art with loops and drawLine.

  1. (Drawing Spirals) In this exercise, you will draw spirals with methods drawLine and drawArc.
    1. Draw a square-shaped spiral (as in the left screen capture of Fig. 5), centered on the panel, using method drawLine. One technique is to use a loop that increases the line length after drawing every second line. The direction in which to draw the next line should follow a distinct pattern, such as down, left, up, right.
    2. Draw a circular spiral (as in the right screen capture of Fig. 5), using method drawArc to draw one semicircle at a time. Each successive semicircle should have a larger radius (as specified by the bounding rectangles width) and should continue drawing where the previous semicircle finished.

Fig. 5 | Drawing a spiral using drawLine (left) and drawArc (right).

  1. (Bar Chart Printing Program) Write an application that reads five integer numbers using dialogs. For each number that is read, your program should display the bar chart using rectangles of varying lengths. Display the rectangles after you read all five numbers.

Fig. 6 | Obtaining user input and creating a JFrame to display Bar Chart.

Reviews

There are no reviews yet.

Only logged in customers who have purchased this product may leave a review.

Shopping Cart
[Solved] OOP Lab 4
$25