Sei sulla pagina 1di 3

Learning Java

This is the order in which scripts were written:


1. MyFirstApp.java
2. UseArgument.java (the use of argument, args[0])
3. UseThree.java (use of 3 arguments, args[0], args[1], args[2])
4. Loopy.java (simple while loop)
5. IfTest.java (simple if and if-else condition tests)
This includes everything learned so far: int, String, while and if loop.
6. BeerSong.java
Building a phrase by a random combination of 3 sets of words.
7. PhraseOMatic.java
First exposure to OOP
8. GameLauncher.java
9. GuessGame.java
10. Player.java
The above 3 files are one single application. Run the game as under:
javac GameLauncher.java
java GameLauncher
I'm thinking of a number between 0 and 9...
Number to guess is 8
I'm guessing 0
I'm guessing 6
I'm guessing 8
Player 1 guessed 0
Player 2 guessed 6
Player 3 guessed 8
We have a winner!
Player 1 got it right? false
Player 2 got it right? false
Player 3 got it right? true
Game is over.

There is no need to compile and run files 9 and 10.


First program to get input from the user, and print it to the screen
11. Echo.java (for a line of text)
12. Echo2.java (for many methods of Scanner class), Listing 2.11, Savitch, p91. See p91 for
explanation.
13. MyFirstProgram.java (Savitch, p23 for explanation)
See also Listing 2.9, Lewis and Lofton, p89.

Example of use of a delimiter


14. DelimitersDemo.java
Result:
$ java DelimitersDemo
Enter a line of text with two words:
mahesh is
The two words are "mahesh" and "is"
Enter a line of text with two words delimited by ##:
mahesh##is##
The two words are "mahesh" and "is"

Note:
for the delimiter, use it after typing each word! If you type mahesh##is, instead of
mahesh##is##, then the program will wait for your input.
Comments, Indenting, Naming a Constant and Calculating
15. CircleCalculation.java
16. CircleCalculation2.java
The constant named is pi.
For calculation, see also Listing 2.9, Lewis and Lofton, p89.
Variables
17. EggBasket.java (no user input)
18. EggBasket2.java (user inputs the numbers)
First exposure to algorithms
19. ChangeMaker.java
See java_algorithms_ChangeMaker.odt for explanation.
Demonstration of the String class methods
20. StringDemo.java
Doing selections: if-else branching, and projects in NetBeans IDE
21. BankBalance (Savitch, p131)
22. StringEqualityDemo (Savitch, p138) - shows if two user input strings are equal as they stand, or
equal if we ignore the case.
1. Includes 3 if-else statements, one after the other
2. Methods: equals(), equalsIgnoreCase()

23. StringOrderDemo (Savitch, p139-140) shows how to determine lexicographic and


alphabetical order of strings
1. Includes if-else if-else statements
2. Methods: compareTo(), toUpperCase()

Multi-way branching with switch-break statements


24. MultipleBirths (Savitch, p150)
Doing repetitions: while, do-while, for, break and exit statements
25. WhileDemo
26. DoWhileDemo
27. BugTrouble extended example of while loop
28. ForDemo
29. ForDemo2
1. Initialize more than one variable
2. Calculates factorial

A combination of while, if-else if-else


30. InvoiceApp1

Simple, straightforward Invoice calculator


while loop contains if-else if -else selection
while loop is based on string variable, choice (y or Y)
It is used at the end to ask the user to continue or not. If the user says "y" or "Y", the while loop
is run again.
But, when running this script for the first time, the loop is run without user choice "y" or "Y" that
is, the choice is assumed to be y.

31. InvoiceApp2 following added.

32.

Sales tax (as a constant), and adjusting calculations accordingly


NumberFormat class
Debugging statements

Potrebbero piacerti anche