Re: Need basic help....
It doesn't seem to want to save my char to a file. Can anyone see what
is wrong? Ive spent a lot of time trying to figure it out and just
cant seem to work it out.
I know I have a lot of altering to do yet before I can even think im
finished. I know this doesn't answer question 4 the way it should be
done but will be altering after aswell.
Thanks again.
----------------------
import java.io.*;
class q4 {
private char a;
public q4() {
}
public q4(char setNewChar) {
this.a = setNewChar;
}
public static void main(String[] args) {
q4 blah = new q4();
blah.startCommandLine();
}
public void startCommandLine()
{
boolean finished;
finished = false;
BufferedReader keyboardInput = new BufferedReader(new
InputStreamReader(System.in));
String temp;
try {
while (finished == false) {
System.out.println("Type in your option:\n1.Set Char (e.g. 1.G or
1.r)\n2.Show and Save\n3.Compare with? (e.g. 3.r)\n4.Exit");
temp = keyboardInput.readLine();
if(temp.charAt(0) == '1')
{
this.newa(temp.charAt(2));
}
else if(temp.equals("2"))
{
System.out.println("You char value is: " + (int)this.returna() +
".\n");
}
else if(temp.charAt(0) == '3')
{
this.comparea(temp.charAt(2));
}
else if(temp.equals("4"))
{
finished = true;
}
}
}
catch(IOException e) {
}
}
public void newa(char a) {
this.a = a;
}
public char returna() {
return a;
}
public void savea() {
FileOutputStream fileOutput;
PrintStream printCommandThing;
try
{
fileOutput = new FileOutputStream("theChar.txt");
printCommandThing = new PrintStream( fileOutput );
printCommandThing.println ((int)this.a);
printCommandThing.close();
}
catch (Exception e)
{
System.err.println ("You boo-booed!");
}
}
public void comparea(char comparee)
{
if((int)this.a < (int)comparee)
{
System.out.println(a + " is less than " + comparee + ".");
}
else if((int)this.a == (int)comparee)
{
System.out.println(a + " is the same as " + comparee + ".");
}
else if((int)this.a > (int)comparee)
{
System.out.println(a + " is more than " + comparee + ".");
}
}
}