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

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
what does nano mean?
Anassong Reply
nano basically means 10^(-9). nanometer is a unit to measure length.
Bharti
do you think it's worthwhile in the long term to study the effects and possibilities of nanotechnology on viral treatment?
Damian Reply
absolutely yes
Daniel
how to know photocatalytic properties of tio2 nanoparticles...what to do now
Akash Reply
it is a goid question and i want to know the answer as well
Maciej
characteristics of micro business
Abigail
for teaching engĺish at school how nano technology help us
Anassong
Do somebody tell me a best nano engineering book for beginners?
s. Reply
there is no specific books for beginners but there is book called principle of nanotechnology
NANO
what is fullerene does it is used to make bukky balls
Devang Reply
are you nano engineer ?
s.
fullerene is a bucky ball aka Carbon 60 molecule. It was name by the architect Fuller. He design the geodesic dome. it resembles a soccer ball.
Tarell
what is the actual application of fullerenes nowadays?
Damian
That is a great question Damian. best way to answer that question is to Google it. there are hundreds of applications for buck minister fullerenes, from medical to aerospace. you can also find plenty of research papers that will give you great detail on the potential applications of fullerenes.
Tarell
what is the Synthesis, properties,and applications of carbon nano chemistry
Abhijith Reply
Mostly, they use nano carbon for electronics and for materials to be strengthened.
Virgil
is Bucky paper clear?
CYNTHIA
carbon nanotubes has various application in fuel cells membrane, current research on cancer drug,and in electronics MEMS and NEMS etc
NANO
so some one know about replacing silicon atom with phosphorous in semiconductors device?
s. Reply
Yeah, it is a pain to say the least. You basically have to heat the substarte up to around 1000 degrees celcius then pass phosphene gas over top of it, which is explosive and toxic by the way, under very low pressure.
Harper
Do you know which machine is used to that process?
s.
how to fabricate graphene ink ?
SUYASH Reply
for screen printed electrodes ?
SUYASH
What is lattice structure?
s. Reply
of graphene you mean?
Ebrahim
or in general
Ebrahim
in general
s.
Graphene has a hexagonal structure
tahir
On having this app for quite a bit time, Haven't realised there's a chat room in it.
Cied
what is biological synthesis of nanoparticles
Sanket Reply
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