Beginning Java - Part II
Creating and Running Programs, Simple I/O, Program 1, Program 2, Javadoc
| inside file: XXXX.java | |
|
/* declare needed library routines here */ |
|
| /** javadoc documentation goes here */ | |
|
|
|
|
|
|
|
} // end class XXXX |
In order to use the package, we must import it into our program like this:
// put this at the beginning of the file
// outside of the class definition
import tio.*;
'tio' is the name of the package and we are saying we want access to all of it. If we have the package locally in our working directory, that is all we need to do. The same holds true for any standard java packages as well since the system has a set of rules for how to find these things. To make this work, what you need is a local copy of the directory called "tio" which contains all the .class files for that package.
Roughly speaking, Console.in corresponds to standard input and Console.out corresponds to standard output. Both exist throughout the life of our program and once we import TIO, we don't need to declare them explicitly. When we say import tio.*;, all of the 'componenets' of TIO come along for the ride.
Let's look at the functions we can use from this package. In ReadInput, we have:
| return type | |||
|
boolean |
hasMoreElements() |
|
|
|
int |
readChar() |
Read the next character. |
|
| NOTE: the following routines don't skip white space. They assume we are at the start of the entity we want to read. (they choke if they are currently pointing to whitespace). They assume they are at the end of the thing they are trying to read when they reach whitespace. | |||
|
double |
|
|
|
|
float |
|
|
|
|
int |
|
|
|
|
String |
|
|
|
|
long |
|
|
|
|
String |
|
Read the next white-space delimited string. |
|
| printf(String s) | Print a string in a field of the current width using the current padding character and justification. |
| The next set of methods convert their parameter to a string and then pass that to printf(String s) | |
|
printf(boolean value) |
|
|
printf(char value) |
|
| printf(char[] value) | |
| printf(double value) | Print a Double in a field of the current width, with the current number of digits to the right of the decimal point and using the current padding character and justification. |
| printf(float value) |
|
| printf(int value) | |
| printf(long value) | |
| printf(Object value) | |
| The next set of methods use printf() followed by a call to println() to add the newline to the formatted output from printf(). |
|
| printfln(boolean value) | |
| printfln(char value) | |
| printfln(char[] value) | |
| printfln(double value) | |
| printfln(float value) | |
| printfln(int value) | |
| printfln(long value) | |
| printfln(Object value) | |
| printfln(String s) |
|
| setDigits(int places) | Set the number of digits to be printed to the right of the decimal point in floating point values. |
| Set the justification to be LEFT or RIGHT. | |
| setPadChar(char pad) | Set the character to be used in padding. |
| setWidth(int width) | Set the ouput field width. |
|
|
Cpsc 235 - Copyright (C) 2003 Katrin
Becker Last Modified