Skip to content Skip to navigation Skip to collection information

Connexions

You are here: Home » Content » Object-Oriented Programming (OOP) with Java » Java OOP: ITSE 2317 Practice Test 2

Navigation

Table of Contents

Recently Viewed

This feature requires Javascript to be enabled.
 

Java OOP: ITSE 2317 Practice Test 2

Module by: Richard Baldwin. E-mail the author

Summary: A practice test with solutions for ITSE 2317

ITSE2317 - Java Programming (Intermediate) - Practice Test 2

Java and Media Library Version Requirements

Your programs must be compatible with Sun's Standard Edition JDK Version 1.7 or later.

Some of the programs on this test require you to use the Guzdial-Ericson multimedia class library. You will find download, installation, and usage instructions for the library at Java OOP: The Guzdial-Ericson Multimedia Class Library .

Input Image Files

Links are provided within the individual program specifications for downloading zip files that contain any image files that may be required to write, compile, and test your programs.

Solution source code files

The downloadable zip files mentioned above also contains source code files for the programming solutions. You can compile and execute those programs using procedures described in Java OOP: The Guzdial-Ericson Multimedia Class Library .

Output Images

Your output image(s) must match my output image(s) in every respect including color, size, position, etc. Don't forget to display your name in the output image(s) as shown.

New Classes

You may define new classes and add import directives as needed to cause your programs to behave as required, but you may not modify the class definitions for the given classes named ProbXX when such class definitions are provided.

Hints

For some of the programs, you may first need to deduce the algorithm used to transform the input image into the output image, and then write a working program that implements that algorithm. In some cases, you may need to compare numeric color values for corresponding pixels in the input and output images in order to deduce the algorithm.

You can obtain those color values using the following procedure:

  1. Click the download link for the zip files that contain input image files and solution source code files. Use the capabilities of your browser to download and save the contents of those zip files.
  2. If necessary, replace calls to the show method in my source code with calls to the explore method to force the program to display the output images in a PictureExplorer window.
  3. Compile and run the source code.
  4. Write, compile, and run a simple Java program that will display each input image file in a PictureExplorer window.
  5. Use the input and output PictureExplorer windows to compare the input and output color values on a pixel by pixel basis.

You may find other useful hints in my online tutorials and slides for this course.

Testing Your Programs

You can compile and execute your program by following the instructions given at Java OOP: The Guzdial-Ericson Multimedia Class Library .

Program Specifications

Program 1

Listing 1: Write the Java application described below.

/*File Prob01 Copyright 2012 R.G.Baldwin

Write a program named Prob01 that uses the class definition shown below and Ericson's media library along with the image files named Prob01a.jpg and Prob01b.jpg to produce the graphic output images shown in Figure 1 , Figure 2 , and Figure 3 below.

Click here to download a zip file containing the required image files along with the source code for a solution.

Just in case you haven't noticed it, the image in Figure 3 contains a partially transparent image of a butterfly superimposed and centered on the beach image.

In order to write this program, you must modify the class from Ericson's media library named SimplePicture. Your modifications must make it possible for you to display a partially transparent image on top of another image with the background image showing through. The degree of transparency can range from being completely transparent at one extreme to being totally opaque at the other extreme. In this case, the butterfly image is about 37-percent opaque. Don't forget to compile the SimplePicture class after you modify it.

You will probably need to do some outside research in order to write this program. For example, you will need to learn about the following topics and probably some other topics as well:

  • Alpha transparency
  • BufferedImage objects of TYPE_INT_ARGB
  • The representation of a pixel as type int.
  • Bit manipulation of pixels.
  • The drawImage method of the Graphics class.

In addition to the output images described above, your program must produce the following output on the command-line screen, and must substitute your name for mine wherever my name appears both in the images and on the command-line screen:

Dick Baldwin.
Dick Baldwin
Picture, filename Prob01a.jpg height 118 width 100
Picture, filename Prob01b.jpg height 240 width 320
Picture, filename None height 101 width 77
*********************************************************/
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Image;

public class Prob01{
  //DO NOT MODIFY THE CODE IN THIS CLASS DEFINITION.
  public static void main(String[] args){
    Picture[] pictures = new Prob01Runner().run();
    System.out.println(pictures[0]);
    System.out.println(pictures[1]);
    System.out.println(pictures[2]);
  }//end main method
}//end class Prob01
//End program specifications.
Figure 1: The first of three required output images for Prob01.
The first of three required output images for Prob01.
Missing image
Figure 2: The second of three required output images for Prob01.
The second of three required output images for Prob01.
Missing image
Figure 3: The third of three required output images for Prob01.
The third of three required output images for Prob01.
Missing image

Program 2

Listing 2: Write the Java application described below.

/*File Prob02 Copyright 2012 R.G.Baldwin

Write a program named Prob02 that uses Ericson's media library along with the image files named Prob02a.jpg and Prob02b.jpg to produce the graphic output images shown in Figure 4 below.

Click here to download a zip file containing the required image files along with the source code for a solution.

The top image shown in Figure 4 is a beach scene with a partially opaque butterfly superimposed on the beach scene. The bottom image is a slider that is used to control the percent opacity of the butterfly image.

At startup, the slider is positioned at the 50-percent mark and the opacity of the butterfly is 50 percent.

As you move the slider to the right, the butterfly becomes more opaque, becoming totally opaque when the slider is positioned at 100 percent. As you move the slider to the left, the butterfly becomes less opaque, becoming totally transparent when the slider is positioned at 0 percent.

In order to write this program, you must modify the class from Ericson's media library named SimplePicture. Your modifications must make it possible for you to display a partially transparent image on top of another image with the background image showing through.

Your modification must also make it possible to display your name in the dark blue banner at the top of the image of the beach scene.

The program must terminate and return control to the operating system when you click the large X in the upper- right corner of the GUI containing the slider.

In order to improve the responsiveness and memory utilization of the program, you should instantiate all of the Picture objects that the program needs at startup, and should not instantiate additional Picture objects when handling events fired by the slider.

Figure 4: Required output images for Prob02.
Required output images for Prob02.
Missing image

Program 3

Listing 3: Write the Java application described below.

/*File Prob03 Copyright 2012 R.G.Baldwin

Write a program named Prob03 that uses Ericson's media library along with the image file named Prob3.jpg to produce the graphic output images shown in Figure 5 below.

Click here to download a zip file containing the required image file along with the source code for a solution.

The top image shown in Figure 5 is an image of a butterfly to which an edge detection algorithm has been applied. The bottom image is a slider that is used to control the edge-detection threshold.

The edge-detection algorithm performs edge detection on a Picture object by rows and also by columns. All edges that are detected by processing adjacent pixels on a row are marked in red. All edges that are detected by processing adjacent pixels on a column are marked in black. If a pixel is determined to be on an edge using both approaches, it ends up being black. If an edge is not detected, the corresponding pixel is marked in white.

At startup, the slider is positioned at the 50-percent mark and the image has been edge-detected using a threshold value of 50. As you move the slider to the right, the threshold increases up to a value of 100, which in turn causes the amount of white area in the image to increase. As you move the slider to the left, the threshold decreases down to a value of zero, which in turn causes the amount of white area in the image to decrease.

The program must terminate and return control to the operating system when you click the large X in the upper- right corner of the GUI containing the slider.

Figure 5: Required output images for Prob03.
Required output images for Prob03.
Missing image

Program 4

Listing 4: Write the Java application described below.

/*File Prob04 Copyright 2012 R.G.Baldwin

Write a program named Prob04 that uses Ericson's media library along with the image files named Prob04a.jpg and Prob04b.jpg to produce the graphic output images shown in Figure 6 and Figure 7 below.

Click here to download a zip file containing the required image files along with the source code for a solution.

The top image shown in Figure 6 is a butterfly image. The image immediately below that one is a slider that is used to control a scale factor that is applied to an image of a beach.

At startup, the slider is positioned at the zero-percent mark (at the far left) and the beach image is too small to be seen in the upper-left corner of the butterfly image.

As you move the slider to the right, an image of a beach emerges from the upper-left corner covering the image of the butterfly.

Figure 7 shows the result of moving the slider to the 50-percent mark.

The size of the beach image increases and decreases smoothly as you move the slider back and forth. The upper- left corner of the beach image is always in the upper- left corner of the butterfly image. The butterfly becomes completely covered by the beach image when the slider is positioned at 100 percent (the far right) .

The program must terminate and return control to the operating system when you click the large X in the upper- right corner of the GUI containing the slider.

Figure 6: Required output images for Prob04.
Required output images for Prob04.
Missing image
Figure 7: Required output image for Prob04.
Required output image for Prob04.
Missing image

Program 5

Listing 5: Write the Java application described below.

/*File Prob05 Copyright 2012 R.G.Baldwin

Write a program named Prob05 that uses Ericson's media library along with the image file named Prob05.jpg to produce the graphic output images shown in Figure 8 and Figure 9 below.

Click here to download a zip file containing the required image file along with the source code for a solution.

The top image in Figure 8 is a butterfly image. The image of the butterfly can be rotated in its picture by any angle ranging from -360 degrees to +360 degrees.

The image immediately below that one is a slider that is used to control the rotation angle that is applied to the butterfly image.

At startup, the slider is positioned at the zero-degrees mark (in the center) and the butterfly image is displayed with no rotation. As you move the slider to the right, the butterfly image rotates clockwise around its center through an angle that can be as large as 360 degrees.

Figure 9 shows the result of moving the slider to the +120-degree mark.

As you move the slider to the left, the butterfly image rotates counter-clockwise around its center through an angle that can be as large as -360 degrees.

The butterfly image rotates smoothly around its center as you move the slider back and forth.

The program must terminate and return control to the operating system when you click the large X in the upper- right corner of the GUI containing the slider.

Figure 8: Required output image for Prob05.
Required output image for Prob05.
Missing image
Figure 9: Required output image for Prob05.
Required output image for Prob05.
Missing image

Miscellaneous Information

This section contains a variety of miscellaneous information.

Note:

Housekeeping material
  • Module name: Java OOP: ITSE 2317 Practice Test 2
  • File: PracticeTest02.htm
  • Published: August 10, 2012
  • Revised: --

Note:

Disclaimers:

Financial : Although the Connexions site makes it possible for you to download a PDF file for this module at no charge, and also makes it possible for you to purchase a pre-printed version of the PDF file, you should be aware that some of the HTML elements in this module may not translate well into PDF.

I also want you to know that, I receive no financial compensation from the Connexions website even if you purchase the PDF version of the module.

In the past, unknown individuals have copied my modules from cnx.org, converted them to Kindle books, and placed them for sale on Amazon.com showing me as the author. I neither receive compensation for those sales nor do I know who does receive compensation. If you purchase such a book, please be aware that it is a copy of a module that is freely available on cnx.org and that it was made and published without my prior knowledge.

Affiliation : I am a professor of Computer Information Technology at Austin Community College in Austin, TX.

-end-

Collection Navigation

Content actions

Download:

Collection as:

PDF | EPUB (?)

What is an EPUB file?

EPUB is an electronic book format that can be read on a variety of mobile devices.

Downloading to a reading device

For detailed instructions on how to download this content's EPUB to your specific device, click the "(?)" link.

| More downloads ...

Module as:

PDF | EPUB (?)

What is an EPUB file?

EPUB is an electronic book format that can be read on a variety of mobile devices.

Downloading to a reading device

For detailed instructions on how to download this content's EPUB to your specific device, click the "(?)" link.

| More downloads ...

Add:

Collection to:

My Favorites (?)

'My Favorites' is a special kind of lens which you can use to bookmark modules and collections. 'My Favorites' can only be seen by you, and collections saved in 'My Favorites' can remember the last module you were on. You need an account to use 'My Favorites'.

| A lens I own (?)

Definition of a lens

Lenses

A lens is a custom view of the content in the repository. You can think of it as a fancy kind of list that will let you see content through the eyes of organizations and people you trust.

What is in a lens?

Lens makers point to materials (modules and collections), creating a guide that includes their own comments and descriptive tags about the content.

Who can create a lens?

Any individual member, a community, or a respected organization.

What are tags? tag icon

Tags are descriptors added by lens makers to help label content, attaching a vocabulary that is meaningful in the context of the lens.

| External bookmarks

Module to:

My Favorites (?)

'My Favorites' is a special kind of lens which you can use to bookmark modules and collections. 'My Favorites' can only be seen by you, and collections saved in 'My Favorites' can remember the last module you were on. You need an account to use 'My Favorites'.

| A lens I own (?)

Definition of a lens

Lenses

A lens is a custom view of the content in the repository. You can think of it as a fancy kind of list that will let you see content through the eyes of organizations and people you trust.

What is in a lens?

Lens makers point to materials (modules and collections), creating a guide that includes their own comments and descriptive tags about the content.

Who can create a lens?

Any individual member, a community, or a respected organization.

What are tags? tag icon

Tags are descriptors added by lens makers to help label content, attaching a vocabulary that is meaningful in the context of the lens.

| External bookmarks