Archive for January, 2008

Chapter 6: Controlling Program Flow with Loops 141 (Web hosting domains)

Saturday, January 19th, 2008

Chapter 6: Controlling Program Flow with Loops 141 You can apply values()to the name of any enumtype. In fact, to create a n enhanced forloop with an enumtype, you have to use something like values(). The expression Suspect.values()stands for all the items you list in the declaration of the Suspectenumtype. So, in the loop of Listing 6-5, mySuspectbecomes mustard, then plum, then green, and so on. When you apply values()to the name of an enumtype, you get an array of items belonging to that enumtype. To read all about arrays, see Chapter 11.
We provide special commissions and earns up to $125 us per referral for all website hosting directories. With such big commissions you should immediately sign up for our affiliate program for website hosting directory sites.

Web hosting servers - 140 Part II: Writing Your Own Java Programs

Friday, January 18th, 2008

140 Part II: Writing Your Own Java Programs In both kinds of loops, you define a variable. The loop in Listing 6-2 defines a variable named count. The loop in Listing 6-5 defines a variable named mySuspect. In both listings, the statements inside the loop refer to the newly defined variable. The loop in Listing 6-2 has the statement out.print(count); and the loop in Listing 6-5 has the statement out.print(mySuspect); During successive iterations, the printin Listing 6-2 stands for out.print(1), out.print(2), and so on. During successive iterations, the printin Listing 6-5 stands for out.print(mustard), out.print(plum), and so on. In both kinds of loops, you declare the type of value that the variable can have. In Listing 6-2, the variable countmust store an intvalue ( 7, 0, 5, 15, and so on). In Listing 6-5, the variable mySuspectmust refer to a Suspectvalue (mustard, plum, white, and so on). In fact, this declaring the type of value rule applies everywhere in Java not only in forloops. Every Java variable belongs to one type or another. In Listing 6-1, the line int numGuesses = 0; declares that numGuessesmust store an intvalue. The line goes on to say that, among all possible intvalues, the starting value for numGuessesis 0. Again in Listing 6-1, the line Scanner myScanner = new Scanner(System.in); declares that myScannermust refer to a Scannerobject. Among all such objects, the starting value for myScanneris an object that gets keystrokes from the keyboard (from System.in). In both kinds of loops, you specify a range of values. You specify the range of values that the variable takes on during the execution of the loop. In Listing 6-2, you narrow the countvariable s values to the numbers from 1 to 10. In Listing 6-5, you throw caution to the wind, and say that mySuspectgets to be every one of the items in Suspect.values().
CGI is used because it is far better and more physical than other ways , such as constructing miniatures for effects shots or hiring a cheap deal of extras for crowd scenes, and because it allows the creation of images that would not be feasible using any other technology.Check fore more details under our cgi web hosting section.

Web site translator - Chapter 6: Controlling Program Flow with Loops 139

Thursday, January 17th, 2008

Chapter 6: Controlling Program Flow with Loops 139 You can create variables to refer to those values. After the forloop in Listing 6-5, I declare a variable named killer. Just as int numGuessesdeclares a numGuessesvariable is of type int, and just as String myTitledeclares variable myTitleto be of type String, so Suspect killerdeclares variable killerto be of type Suspect. I declare int numGuessesin Listing 6-1, and I declare String myTitlein Listing 4-6. Being of type Suspectmeans that you can have values mustard, plum, green, and so on. So in Listing 6-5, I give the killervariable the value peacock. (At this point in the code, if I don t type the longer dotted name Suspect.peacock, the Java compiler gets confused.) In a similar way, I create variables sceneOfTheCrimeand murderWeapon toward the end of Listing 6-5. Both these variables have enumtypes, and both are given appropriate values (values like Room.studyand Weapon. leadPipe). In Listing 6-5, all the enumtype declarations are outside the mainmethod. (For example, the line that begins with enum Suspectis before the start of the mainmethod.) Java doesn t allow you to put an enumtype declaration inside a method. That s because an enumtype declaration is really a Java class in disguise. For more insight on enumtypes, see Chapter 9. Anatomy of an enhanced for loop The enhanced and un-enhanced forloops have a lot in common. Figure 6-8 illustrates the point. Listing 6-2: for (int count = 1; count <= 10; count++) The type of The range of values The name of value that a that variable takes the variable variable can on during execution have of the loop Figure 6-8: Comparing Listing 6-5: for (Suspect mySuspect : Suspect.values()) for loops.
Our Colorado hosting facilities are located in Little Rock, Colorado. Colorado web hosting datacenter which we have is linked on five major US backbones which gives you assurance that your site will be online 24/7 a day. More details you can find out in Web Hosting Colorado part.

138 Part II: Writing Your (How to cite a web site) Own Java Programs

Wednesday, January 16th, 2008

138 Part II: Writing Your Own Java Programs Figure 6-7: The code in Listing 6-5 starts running. Listing 6-5 has a loop within a loop within a loop. The Roomloop is inside of the Suspectloop. Not only do you loop through all the rooms, but you loop through all the rooms six times once for each of the six suspects. If I count them up, that makes 54 visits to various rooms. The Weaponloop is inside of the Roomloop. So every time you visit a room (and you visit a room 54 times), you go through all six of the hideous weapons. Like the code in Listing 6-3, this section s Clueprogram nests statements within other statements. In Listing 6-3, I nested switchstatements inside a big forstatement. But in the Clueprogram, I nest forstatements inside other forstatements. It may look at bit tangled at first, but when you get used to it, nesting loop within loop is a really useful technique. Grouping things together Java provides lots of ways for you to group things together. In Chapter 11, you can group things into an array or a collection. In this chapter, you group things into an enumtype. (Of course, you can t group anything unless you can pronounce enum. The word enum is pronounced ee-noom, like the first two syllables of the word enumeration.) Creating a complicated enumtype isn t easy, but to create a simple enum type, just write a bunch of words inside a pair of curly braces. Listing 6-5 has three enumtypes. The names of the enumtypes are Suspect, Room, and Weapon. When you define an enumtype, two important things happen: You create values. Just as 13and 151are intvalues, mustardand plumare Suspect values.
Have all the commercials and ads about web hosting companies given you headache? Relax now.Our recommendation is web hosting comparisons.

Chapter 6: Controlling Program Flow with Loops 137 (Web server address)

Wednesday, January 16th, 2008

Chapter 6: Controlling Program Flow with Loops 137 Listing 6-5: I Accuse . . . import static java.lang.System.out; class Clue { enum Suspect {mustard, plum, green, peacock, scarlet, white}; enum Room {ballroom, kitchen, diningRoom, lounge, hall, study, library, billiardRoom, conservatory}; enum Weapon {knife, candlestick, revolver, rope, leadPipe, wrench}; public static void main(String args[]) { for (Suspect mySuspect : Suspect.values()) { for (Room myRoom : Room.values()) { for (Weapon myWeapon : Weapon.values()) { out.print(mySuspect); out.print( in the ); out.print(myRoom); out.print( with a ); out.println(myWeapon); } } } Suspect killer = Suspect.peacock; Room sceneOfTheCrime = Room.study; Weapon murderWeapon = Weapon.leadPipe; out.println(); out.print( I accuse ); out.print(killer); out.print( in the ); out.print(sceneOfTheCrime); out.print( with a ); out.print(murderWeapon); out.println( . ); } } The output of the code in Listing 6-5 has 324 lines, so I can t show it all to you. But the first several lines appear in Figure 6-7. First, you see Colonel Mustard s ballroom antics. Then you get Mustard s kitchen tricks. Later in the run, when all Mustard s frolics are finished, you see the same possibilities for Professor Plum.
We are the the largest streaming host company, and we provide professional audio & video web hosting streaming using Real Networks, QuickTime, Flash and Windows Media.We strongly recommend you to visit and check web hosting streaming services.

136 Part II: Writing Your Own Java Programs (Web hosting servers)

Tuesday, January 15th, 2008

136 Part II: Writing Your Own Java Programs So in Listing 6-4, your hands are tied. The program s first real use of the replyvariable is inside the loop. But, to make that variable available after the loop, you have to declare replybefore the loop. In this situation, you re best off declaring the replyvariable without initializing the variable. Very interesting! To read more about variable initializations, see Chapter 4. To read more about blocks, see Chapter 5. Loops Made Painless I ll never forget the first time I played Clue. We bought the board game during a family vacation in Niagara Falls. (Niagara Falls?) Cousin Alan and I sat in the hotel room playing the game for hours on end. I scribbled complicated assertions in my little detective s notebook. At one point, I bluffed by suggesting three cards that I had in my hand. Alan took the bait and made an accusation that was wrong on all three counts. Because he d lost the game, and because I was being so smug about it, he beat the living daylights out of me. It was heaven. If I had the chance, I d do it all over again. The material in this section applies to Java 5, Java 6, or whatever higher version number comes along in the next few years. But this section s material doesn t work with older versions of Java versions such as 1.3, 1.4, and so on. For a bit more about Java s version numbers, see Chapter 2. Don t need no stinking counters The forloop in Listing 6-2 counts from 1 to 10. And its friend (the forloop in Listing 6-3) counts 1, 2, 3. This counting is very nice, but sometimes it s not the most natural way to think about a problem. Take, for instance, the listing of all possible accusations in the board game Clue. The suspects aren t numbered from 1 to 6, and neither are the rooms or weapons. You can number all these things, but why bother with numbering when the programming language provides a simpler solution? Java s enhanced for loop lets you cycle through groups of things without creating a counting variable. All you have to do is define the group. Listing 6-5 shows you what to do.
Do you want truly affordable web hosting? With us, what you see is what you get, just click on affordable web hosting services.

Chapter 6: Controlling Program Flow with Loops 135 (Web space)

Monday, January 14th, 2008

Chapter 6: Controlling Program Flow with Loops 135 File handling in Java In Listing 6-4, the actual file-handling statements deserve some attention. These statements involve the use of classes, objects, and methods. Many of the meaty details about these things are in other chapters, like Chapters 7 and 9. Even so, I can t do any harm by touching on some highlights right here. So, you can find a class in the Java language API named java.io.File. The statement File evidence = new File( c:\cookedBooks.txt ); creates a new object in the computer s memory. This object, formed from the java.io.Fileclass, describes everything that the program needs to know about the disk file c:cookedBooks.txt. (In Java, when you want to indicate a backslash inside a double-quoted Stringliteral, you use a double backslash instead.) From this point on in Listing 6-4, the variable evidence refers to the disk file c:cookedBooks.txt. After you ve got all this java.io.Filestuff in your head, the only thing left to know is that the evidenceobject, being an instance of the java.io.File class, has a deletemethod. (What can I say? It s in the API documentation.) When you call evidence.delete, the computer gets rid of the file for you. Variable declarations and blocks A bunch of statements surrounded by curly braces form a block. If you declare a variable inside a block, you generally can t use that variable outside the block. For instance, in Listing 6-4, you get an error message if you make the following change: do { out.print( Delete evidence? (y/n) ); char reply = myScanner.findWithinHorizon( . , 0).charAt(0); } while (reply != y && reply != n ); if (reply == y ) With the declaration char replyinside the loop s curly braces, no use of the name replymakes sense anywhere outside the braces. When you try to compile this code, you get three error messages two for the replywords in while (reply != y && reply != n ), and a third for the if statement s reply.
Are you a Mac user in a search of Mac web hosting provider? We are. once upon a time, we were just like you, trying to find somebody who knows. Unfortunately, we had no luck, so we decided to help many others like you, and us. our team developed Mac friendly web hosting plans, feature packed, constantly monitored, and more than affordable. With us, you are home. Sign up.

134 Part (Web design software) II: Writing Your Own Java Programs

Sunday, January 13th, 2008

134 Part II: Writing Your Own Java Programs Figure 6-6 shows the flow of control in the loop of Listing 6-4. With a doloop, the situation in the twoPlusTwoprogram (shown earlier) can never happen. Because the doloop carries out its first action without testing a condition, every doloop is guaranteed to perform at least one iteration. Delete evidence? Was the replyeither yor n? no yes Figure 6-6: Here we go Delete the file, or don’t loop, do delete the file (depending on the reply) loop. Reading a single character In Listing 5-3, the user types a word on the keyboard. The myScanner.next method grabs the word and places the word into a Stringvariable named password. Everything works nicely because a Stringvariable can store many characters at once and the nextmethod can read many characters at once. But in Listing 6-4, you re not interested in reading several characters. You expect the user to type one letter either y or n. So you don t create a Stringvariable to store the user s response. Instead, you create a char variable a variable that stores just one symbol at a time. The Java API doesn t have a nextCharmethod. So to read something suitable for storage in a charvariable, you have to improvise. In Listing 6-4, the improvisation looks like this: myScanner.findWithinHorizon( . , 0).charAt(0) You can use this code exactly as it appears in Listing 6-4 whenever you want to read a single character. A Stringvariable can contain many characters or just one character. But a Stringvariable that contains only one character isn t the same as a char variable. No matter what you put in a Stringvariable, Stringvariables and charvariables have to be treated differently.
With our Unix hosting accounts you have total control of your Web site content from anywhere in the world.For more information please follow link Unix Web Hosting.

Chapter 6: Controlling Program Flow with Loops 133 (Java hosting)

Saturday, January 12th, 2008

Chapter 6: Controlling Program Flow with Loops 133 the user gives the first response, the loop has nothing to check. The loop doesn t start with as long as such-and-such is true, then get a response from the user. Instead, the loop just leaps ahead, gets a response from the user, and then checks the response to see if it makes sense. That s why the program in Listing 6-4 has a do loop (also known as a do . . . while loop). With a doloop, the program jumps right in, takes action, and then checks a condition to see whether the result of the action makes sense. If the result makes sense, execution of the loop is done. If not, the program goes back to the top of the loop for another go-around. Listing 6-4: To Delete or Not to Delete import java.io.File; import static java.lang.System.out; import java.util.Scanner; class DeleteEvidence { public static void main(String args[]) { File evidence = new File( c:\cookedBooks.txt ); Scanner myScanner = new Scanner(System.in); char reply; do { out.print( Delete evidence? (y/n) ); reply = myScanner.findWithinHorizon( . ,0).charAt(0); } while (reply != y && reply != n ); if (reply == y ) { out.println( Okay, here goes… ); evidence.delete(); } else { out.println( Sorry, buddy. Just asking. ); } } } Figure 6-5 shows two runs of the code in Listing 6-4. The program accepts lowercase letters y and n, but not the uppercase letters Y and N. To make the program accept uppercase letters, change the conditions in the code as follows: do { out.print( Delete evidence? (y/n) ); reply = myScanner.findWithinHorizon( . , 0).charAt(0); } while (reply! = y && reply != Y && reply != n && reply!= N ); if (reply == y || reply == Y )
Would you like to be a member of headache free web site owner’s community. Now you can. We focus in IX Web Hosting, go go go!

Web hosting unlimited bandwidth - 132 Part II: Writing Your Own Java Programs

Friday, January 11th, 2008

132 Part II: Writing Your Own Java Programs enters a whileloop, the computer checks to make sure that the loop s condition is true. If the condition isn t true, the statements inside the loop are never executed not even once. In fact, you can easily cook up a while loop whose statements are never executed (although I can t think of a reason why you would ever want to do it). int twoPlusTwo = 2 + 2; while (twoPlusTwo == 5) { out.println( Are you kidding? ); out.println( 2 + 2 doesn t equal 5 ); out.print( Everyone knows that ); out.println( 2 + 2 equals 3 ); } In spite of this silly twoPlusTwoexample, the whilestatement turns out to be the most versatile of Java s looping constructs. In particular, the while loop is good for situations in which you must look before you leap. For example: While money is in my account, write a mortgage check every month. When you first encounter this statement, if your account has a zero balance, you don t want to write a mortgage check not even one check. But at times (not many), you want to leap before you look. Take, for instance, the situation in which you re asking the user for a response. Maybe the user s response makes sense, but maybe it doesn t. If it doesn t, you want to ask again. Maybe the user s finger slipped, or perhaps the user didn t understand the question. Figure 6-5 shows some runs of a program to delete a file. Before deleting the file, the program asks the user whether making the deletion is okay. If the user answers y or n, the program proceeds according to the user s wishes. But if the user enters any other character (any digit, uppercase letter, punctuation symbol, or whatever), the program asks the user for another response. Figure 6-5: Checking before you delete a file. To write this program, you need a loop a loop that repeatedly asks the user whether the file should be deleted. The loop keeps asking until the user gives a meaningful response. Now, the thing to notice is that the loop doesn t need to check anything before asking the user the first time. Indeed, before
The UK has been a member of the European Union since 1973. The attitude of the present government towards further integration is conservative, with the official opposition favoring a return of some powers and competencies to the UK.From our experience, we can recommend Cheap UK Web Hosting services.