Hi, I used TextPad about 5 years ago when teaching Java and I will be teaching again soon. I recall doing something in Textpad and I am trying to remember how to do it now again.
I have a java file (MyInput.java) and corresponding MyInput.class file. The purpose of this file is to retrieve input of any basic type from the users. And, instead of copying MyInput.java and MyInput.class into every project folder, someone showed me how to get TextPad to check some default directory IF the compiler could not find the file inside the working directory. Unfortunately, I forget how to do that.
In all honesty, I don't remember if this is a TextPad setting or a setting I have to make in a DOS window (like, setting environmental variables).
A sample of the code is below. I got the code from a book authored by Savitch.
I would appreciate any help,
Michael Carney
//MyInput.java file
import java.io.*;
import java.util.*;
/**************************************************************
*Class for simple console input.
*A class designed primarily for simple keyboard input of the form
*one input value per line. If the user enters an improper input,
*i.e., an input of the wrong type or a blank line, then the user
*is prompted to reenter the input and given a brief explanation
*of what is required. Also includes some additional methods to
*input single numbers, words, and characters, without going to
*the next line.
*************************************************************/
public class MyInput
{
/**********************************************************
*Reads a line of text and returns that line as a String value.
*The end of a line must be indicated either by a new-line
*character '\n' or by a carriage return '\r' followed by a
*new-line character '\n'. (Almost all systems do this
*automatically. So, you need not worry about this detail.)
*Neither the '\n', nor the '\r' if present, are part of the
*string returned. This will read the rest of a line if the
*line is already partially read.
*********************************************************/
public static String readLine()
{
char nextChar;
String result = "";
boolean done = false;
while (!done)
{
nextChar = readChar();
if (nextChar == '\n')
done = true;
else if (nextChar == '\r')
{
//Do nothing.
//Next loop iteration will detect '\n'
}
else
result = result + nextChar;
}
return result;
}
/**********************************************************
*Reads the first string of nonwhite characters and returns
*that string. Discards the first whitespace character after
*the string read. The next read takes place immediately after
*the discarded whitespace. In particular, if the string
*read is at the end of a line, the next reading will take
*place starting on the next line. Note, that if it receives
*blank lines, it will wait until it gets a nonwhitespace
*character.
*********************************************************/
public static String readWord()
{
String result = "";
char next;
next = readChar();
while (Character.isWhitespace(next))
next = readChar();
while (!(Character.isWhitespace(next)))
{
result = result + next;
next = readChar();
}
if (next == '\r')
{
next = readChar();
if (next != '\n')
{
System.out.println(
"Fatal Error in method readWord of class MyInput.");
System.exit(1);
}
}
return result;
}
/********************************************************
*Reads the next input character and returns that character. The
*next read takes place on the same line where this one left off.
********************************************************/
public static char readChar()
{
int charAsInt = -1; //To keep the compiler happy
try
{
charAsInt = System.in.read();
}
catch(IOException e)
{
System.out.println(e.getMessage());
System.out.println("Fatal error. Ending Program.");
System.exit(0);
}
return (char)charAsInt;
}
/**********************************************************
*Precondition: The next input in the stream consists of an
*int value, possibly preceded by white space, but definitely
*followed by white space.
*Action: Reads the first string of nonwhite characters
*and returns the int value it represents. Discards the first
*whitespace character after the word. The next read takes
*place immediately after the discarded whitespace.
*In particular, if the word is at the end of a line, the
*next reading will take place starting on the next line.
*If the next word does not represent an int value,
*a NumberFormatException is thrown.
*********************************************************/
public static int readInt() throws NumberFormatException
{
String inputString = null;
inputString = readWord();
return Integer.parseInt(inputString);
}
default path for packages and commonly used java files
Moderators: AmigoJack, bbadmin, helios, MudGuard