Skip to content Skip to navigation Skip to collection information

OpenStax-CNX

You are here: Home » Content » Object-Oriented Programming (OOP) with Java » Java OOP: ITSE 2321 Practice Group 1

Navigation

Table of Contents

Recently Viewed

This feature requires Javascript to be enabled.
 

Java OOP: ITSE 2321 Practice Group 1

Module by: R.G. (Dick) Baldwin. E-mail the author

Summary: Practice programs with solutions for ITSE 2321

ITSE 2321 Object-Oriented Programming - Practice Group 1

Java and Media Library Version Requirements

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

Some of the programs in this group 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 any image files that may be required to write, compile, and test your programs.

Solution source code files

Links are provided within the individual program specifications for downloading source code files that contain 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.

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 on the input image file link(s) and use the capabilities of your browser to download and save the image file(s).
  2. Click on the Java solution source code link(s) and use the capabilities of your browser to download and save the source code file(s).
  3. 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.
  4. Write, compile, and execute 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.

In addition to the hints listed above, I will precede the detailed specifications for each program with a discussion that contains hints about the concepts and skills that you will probably need to successfully write the program.

In order to write this or any other Java program of substance, you will need to know how to use the Java Platform, Standard Edition API Specification as well as the documentation for the Guzdial-Ericson Multimedia Class Library .

You may find other useful hints in my online tutorials and slides for this course as well as in the YouTube video lectures 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

Discussion

The following is a non-exhaustive list of concepts that you need to understand along with knowledge and skills that you need to possess in order to successfully write this program and/or understand the given solution in Prob01.java . Some of these items are general in nature and some are specific to the use of Ericson's multimedia library.

Listing 1:

/*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 file named Prob01.jpg to produce the graphic output image shown in Figure 1 below.

Click Prob01.java to download a Java source file containing the solution to this program.

In addition to the output image, your program must display your name and the other three lines of text shown below on the command-line screen:

Display your name here.
A 300 by 274 world with 2 turtles in it.
joe turtle at 256, 131 heading 45.0.
sue turtle at 50, 37 heading 0.0.
*********************************************************/
public class Prob01{
  //DO NOT MODIFY THE CODE IN THIS CLASS DEFINITION.
  public static void main(String[] args){
    Prob01Runner obj = new Prob01Runner();
    obj.run();

    System.out.println(obj.getMars());
    System.out.println(obj.getJoe());
    System.out.println(obj.getSue());
  }//end main
}//end class Prob01nd program specifications.
Figure 1: Required output image for Prob01.
Required output image for Prob01.
Missing image

Program 2

Discussion

The following is a non-exhaustive list of concepts that you need to understand along with knowledge and skills that you need to possess in order to successfully write this program and/or understand the given solution in Prob02.java . Some of these items are general in nature and some are specific to the use of Ericson's multimedia library. I won't repeat the items listed under Program 1 above. Instead, I will concentrate on new concepts, knowledge, and skills not included in the above list.

  • How to design and implement an algorithm that will transform Prob02.jpg into the image shown in Figure 2 .
  • How to declare and initialize instance variables in a single statement.
  • How to instantiate a new object of Ericson's Picture class encapsulating the contents of a local image file.
  • How to call methods on the new Picture object for a variety of purposes.
  • How to declare a reference variable capable of storing a reference to a one-dimensional array object.
  • How to populate a one-dimensional array object of type Pixel[] with references to all of the Pixel objects encapsulated in a Picture object.
  • How to use a l oop structure to individually access the reference to each Pixel object in the array object.
  • How to use a reference to a Pixel object to modify the red, green, and blue color values belonging to the pixel that is represented by the Pixel object.
  • How use a pair of PictureExplorer objects to design and implement an algorithm that will transform the original image into the required output image shown in Figure 2 .
  • How to display your modified Picture object in an object of Ericson's PictureExplorer class.
  • How to confirm the validity of your algorithm by numerically comparing the color values in your output with the color values produced by compiling and running the program solution given below.
Listing 2: Write the Java application described below.

/*File Prob02 Copyright 2012 R.G.Baldwin

Write a program named Prob02 that uses the class definition shown below and Ericson's media library along with the image file named Prob02.jpg to produce the graphic output image shown in Figure 2 below.

Click Prob02.java to download a Java source file containing the solution to this program.

In addition to the output image, your program must display your name and the other text shown below on the command-line screen:


Display your name here.
Picture, filename Prob02.jpg height 274 width 365
*********************************************************/
public class Prob02{
  //DO NOT MODIFY THE CODE IN THIS CLASS DEFINITION.
  public static void main(String[] args){
    Prob02Runner obj = new Prob02Runner();
    obj.run();
    System.out.println(obj.getPicture());
  }//end main
}//end class Prob02
//End program specifications.
Figure 2: Required output image for Prob02.
Required output image for Prob02.
Missing image

Program 3

Discussion

The following is a non-exhaustive list of concepts that you need to understand along with knowledge and skills that you need to possess in order to successfully write this programand/or understand the given solution in Prob03.java . Some of these items are general in nature and some are specific to the use of Ericson's multimedia library. I won't repeat the items listed above. Instead, I will concentrate on new concepts, knowledge, and skills not included in the above lists.

There are at least two alternative ways to write a program that will satisfy these requirements.

Both alternatives

  • How to design and implement an algorithm that will transform Prob03.jpg into the required output image shown in Figure 3 .

Alternative 1

Alternative 2

Listing 3: Write the Java application described below.

/*File Prob03 Copyright 2012 R.G.Baldwin

Write a program named Prob03 that uses the class definition shown below and Ericson's media library along with the image file named Prob03.jpg to produce the graphic output image shown in Figure 3 below.

Click Prob03.java to download a Java source file containing the solution to this program.

In addition to the output, your program must display your name and the other text shown below on the command-line screen:


Display your name here.
Picture, filename Prob03.jpg height 274 width 365

*********************************************************/
public class Prob03{
  //DO NOT MODIFY THE CODE IN THIS CLASS DEFINITION.
  public static void main(String[] args){
    Prob03Runner obj = new Prob03Runner();
    obj.run();
    System.out.println(obj.getPicture());
  }//end main
}//end class Prob03
//End program specifications.
Figure 3: Required output image for Prob03.
Required output image for Prob03.
Missing image

Program 4

Discussion

The following is a non-exhaustive list of concepts that you need to understand along with knowledge and skills that you need to possess in order to successfully write this programand/or understand the given solution in Prob04.java . Some of these items are general in nature and some are specific to the use of Ericson's multimedia library. I won't repeat the items listed above. Instead, I will concentrate on new concepts, knowledge, and skills not included in the above lists.

  • How to design and implement an algorithm that will transform Prob04.jpg into the image shown in Figure 4 .
  • Similarities and differences between classes and interfaces .
  • The different types under which you can store an object's reference when the class from which the object was instantiated extends a class and implements one or more interfaces.
  • The kinds of new relationships that are created when a class implements one or more interfaces.
  • The implications of inheriting one or more abstract methods.
  • The significance of all interface methods being implicitly abstract.
  • That DigitalPicture is an interface and is not a class in Ericson's library.
  • The relationship that exists between the DigitalPicture interface and the Picture class.
  • The circumstances under which an accessor method can return a reference to an object as type DigitalPicture .
  • The difference between displaying a Picture object with the show and explore methods.
Listing 4: Write the Java application described below.

/*File Prob04 Copyright 2012 R.G.Baldwin

Write a program named Prob04 that uses the class definition shown below and Ericson's media library along with the image file named Prob04.jpg to produce the graphic output image shown in Figure 4 below.

Click Prob04.java to download a Java source file containing the solution to this program.

In addition to the output image, your program must display your name and the other text shown below on the command-line screen:


Display your name here.
Picture, filename Prob04.jpg height 274 width 365
*********************************************************/
public class Prob04{
  //DO NOT MODIFY THE CODE IN THIS CLASS DEFINITION.
  public static void main(String[] args){
    Prob04Runner obj = new Prob04Runner();
    DigitalPicture digitalPicture = 
                                  obj.getDigitalPicture();
    System.out.println(digitalPicture);
    digitalPicture.show();
  }//end main
}//end class Prob04
//End program specifications.
Figure 4: Required output image for Prob04.
Required output image for Prob04.
Missing image

Program 5

Discussion

The following is a non-exhaustive list of concepts that you need to understand along with knowledge and skills that you need to possess in order to successfully write this program and/or understand the given solution in Prob05.java . Some of these items are general in nature and some are specific to the use of Ericson's multimedia library. I won't repeat the items listed above. Instead, I will concentrate on new concepts, knowledge, and skills not included in the above lists.

  • How to design and implement an algorithm that will transform Prob05a.jpg and Prob05b.jpg into the images shown in Figure 5 and Figure 6 .
  • What it means for the method named getDigitalPictures to return a reference to an object as type DigitalPicture[] .
  • What you can do with a reference of type DigitalPicture[] .
  • The implications of the fact that calling the show method each of the elements of the array of type DigitalPicture[] produces a different output image.
Listing 5: Write the Java application described below.

/*File Prob05 Copyright 2012 R.G.Baldwin

Write a program named Prob05 that uses the class definition shown below and Ericson's media library along with the image files named Prob05a.jpg and Prob05b.jpg to produce the pair of graphic output images shown in Figure 5 and Figure 6 below.

Note that unless you know how to position the output images on the screen, they will both end up in the upper-left corner of the screen with one image partially or completely covering the other image. Use your mouse to drag and separate the images.

Click Prob05.java to download a Java source file containing the solution to this program.

In addition to the output images mentioned above, your program must display your name and the other text shown below on the command-line screen:


Display your name here.
Picture, filename Prob05b.jpg height 309 width 412
Picture, filename Prob05a.jpg height 274 width 365	 
*********************************************************/
public class Prob05{
  //DO NOT MODIFY THE CODE IN THIS CLASS DEFINITION.
  public static void main(String[] args){
    Prob05Runner obj = new Prob05Runner();
    DigitalPicture[] digitalPictures = 
                                 obj.getDigitalPictures();

    System.out.println(digitalPictures[0]);
    digitalPictures[0].show();

    System.out.println(digitalPictures[1]);
    digitalPictures[1].show();
  }//end main
}//end class Prob05
//End program specifications.
Figure 5: First required output image for Prob05.
First required output image for Prob05.
Missing image
Figure 6: Second required output image for Prob05.
Second 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 2321 Practice Group 1
  • File: PracticeGroup01.htm
  • Published: 08/03/12
  • Revised: 02/10/13

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:

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