<< Chapter < Page Chapter >> Page >

A penguin in the snow in front of some houses.

Figure 2 - The modified image.

The penguin image but with color modification. Colors tend to be yellow on the left and purple on the right.

Figure 3 . Text output on the command-line screen.
java version "1.6.0_14" Java(TM) SE Runtime Environment (build 1.6.0_14-b08)Java HotSpot(TM) Client VM (build 14.0-b16, mixed mode, sharing)javac 1.6.0_14 Dick BaldwinPicture, filename Prob03.jpg height 274 width 365

The required output on the command-line screen is shown by the last two lines of text in Figure 3 . The remaining text in Figure 3 was produced by the system during the compilation and execution process.

Discussion and sample code

Will explain in fragments

I will explain this program in fragments. A complete listing is provided in Listing 8 near the end of the module.

I will begin with the driver class named Prob03 , which is shown in its entirety in Listing 1 .

Listing 1 . The driver class named Prob03.
public class Prob03{ public static void main(String[]args){ Prob03Runner obj = new Prob03Runner();obj.run(); System.out.println(obj.getPicture());}//end main }//end class Prob03

There is nothing in Listing 1 that I haven't explained in earlier modules. Therefore, no explanation of the code in Listing 1 should be required.

Beginning of the class named Prob03Runner

The class definition for the class named Prob03Runner begins in Listing 2 .

Listing 2 . Beginning of the class named Prob03Runner.
class Prob03Runner{ //Instantiate the Picture object.private Picture pic = new Picture("Prob03.jpg"); public Prob03Runner(){//constructorSystem.out.println("Dick Baldwin"); }//end constructor//----------------------------------------------------// //Accessor methodpublic Picture getPicture(){return pic;}

Once again, there is nothing in Listing 2 that I haven't explained before. I included it here simply for the sake of continuity.

The beginning of the run method

The run method begins in Listing 3 . The run method is where most of the interesting action takes place.

Listing 3 . The beginning of the run method.
public void run(){ pic.addMessage("Dick Baldwin",10,20);//Display a PictureExplorer object. pic.explore();//Get an array of Pixel objects. Pixel[]pixels = pic.getPixels(); //Declare working variablesPixel pixel = null; int green = 0;int blue = 0; int width = pic.getWidth();double greenScale = 0; double blueScale = 0;

Much of what you see in Listing 3 has been explained in earlier modules. However, Listing 3 does deserve a few comments.

Display the raw image

The call to the explore method produces the output shown in Figure 1 .

Get an array of Pixel data

The call to the getPixels method in Listing 3 returns a reference to a one-dimensional array object. The elements in the arrayare references to Pixel objects, where each Pixel object represents a single pixel in the image. I will explain the organization of the pixel data later .

Get the width of the image

The call to the getWidth method in Listing 3 returns an int value that specifies the width of the image in pixels. This value will be usedlater to compute the column to which each pixel belongs.

Local variables

Listing 3 declares six local variables. The purpose of these variables should become clear during the explanation of the code thatimplements the algorithm.

Questions & Answers

Application of nanotechnology in medicine
what is variations in raman spectra for nanomaterials
Jyoti Reply
I only see partial conversation and what's the question here!
Crow Reply
what about nanotechnology for water purification
RAW Reply
please someone correct me if I'm wrong but I think one can use nanoparticles, specially silver nanoparticles for water treatment.
Damian
yes that's correct
Professor
I think
Professor
what is the stm
Brian Reply
is there industrial application of fullrenes. What is the method to prepare fullrene on large scale.?
Rafiq
industrial application...? mmm I think on the medical side as drug carrier, but you should go deeper on your research, I may be wrong
Damian
How we are making nano material?
LITNING Reply
what is a peer
LITNING Reply
What is meant by 'nano scale'?
LITNING Reply
What is STMs full form?
LITNING
scanning tunneling microscope
Sahil
how nano science is used for hydrophobicity
Santosh
Do u think that Graphene and Fullrene fiber can be used to make Air Plane body structure the lightest and strongest. Rafiq
Rafiq
what is differents between GO and RGO?
Mahi
what is simplest way to understand the applications of nano robots used to detect the cancer affected cell of human body.? How this robot is carried to required site of body cell.? what will be the carrier material and how can be detected that correct delivery of drug is done Rafiq
Rafiq
if virus is killing to make ARTIFICIAL DNA OF GRAPHENE FOR KILLED THE VIRUS .THIS IS OUR ASSUMPTION
Anam
analytical skills graphene is prepared to kill any type viruses .
Anam
what is Nano technology ?
Bob Reply
write examples of Nano molecule?
Bob
The nanotechnology is as new science, to scale nanometric
brayan
nanotechnology is the study, desing, synthesis, manipulation and application of materials and functional systems through control of matter at nanoscale
Damian
Is there any normative that regulates the use of silver nanoparticles?
Damian Reply
what king of growth are you checking .?
Renato
What fields keep nano created devices from performing or assimulating ? Magnetic fields ? Are do they assimilate ?
Stoney Reply
why we need to study biomolecules, molecular biology in nanotechnology?
Adin Reply
?
Kyle
yes I'm doing my masters in nanotechnology, we are being studying all these domains as well..
Adin
why?
Adin
what school?
Kyle
biomolecules are e building blocks of every organics and inorganic materials.
Joe
anyone know any internet site where one can find nanotechnology papers?
Damian Reply
research.net
kanaga
sciencedirect big data base
Ernesto
Introduction about quantum dots in nanotechnology
Praveena Reply
hi
Loga
what does nano mean?
Anassong Reply
nano basically means 10^(-9). nanometer is a unit to measure length.
Bharti
how did you get the value of 2000N.What calculations are needed to arrive at it
Smarajit Reply
Privacy Information Security Software Version 1.1a
Good
Got questions? Join the online conversation and get instant answers!
Jobilize.com Reply

Get the best Algebra and trigonometry course in your pocket!





Source:  OpenStax, Object-oriented programming (oop) with java. OpenStax CNX. Jun 29, 2016 Download for free at https://legacy.cnx.org/content/col11441/1.201
Google Play and the Google Play logo are trademarks of Google Inc.

Notification Switch

Would you like to follow the 'Object-oriented programming (oop) with java' conversation and receive update notifications?

Ask