First, I want to thank you for helping if you did, if not, thanks for checking it anyway. Second, I have been working on this for awhile, but I only am getting baby steps towards my goal. I get this far and I get compile correctly, but when I run it I get:
Exception in thread "main" java.lang.IllegalArgumentException: No enum const class project 2$Convert.bi
at java.lang.Enum.valueOf<Enum.java:196>
at project2$Convert.valueOf<project2.java:5>
at project2.main<project2.java:49>
Essentially, what I am trying to do is this: I have an input file has numbers like FFFFhex, 1010bin, 0013dec, 7777oct, and I want to convert it to decimal. I have to read these numbers one at a time and store them in a list. Then after they are all read and converted, I have to sort, print, and write the list into a new file.
import java.io.*;
import java.util.*;
public class project2
{
public enum Convert { bin, oct, hex, dec}
public static void main(String[] args)
throws IOException
{
//Declare variables
String bin;
String oct;
String dec;
String hex;
String input;
String output;
String str;
Scanner inFile = new Scanner(new FileReader("E:\\LIFE.txt"));
PrintWriter outFile = new PrintWriter("E:\\REPORT.txt");
//Prompt
System.out.println();
System.out.println("Please be sure that the file LIFE is located in the root folder.");
System.out.println("An example of this is C:");
System.out.println("The REPORT file will be in the same location.");
//Switch that will convert numbers
while (inFile.hasNext())
{
str = inFile.next();
switch(Convert.valueOf(str.substring(4,6)))
{
case bin:
int binary= Integer.parseInt(str,2);
break;
case oct:
int octal= Integer.parseInt(str,8);
break;
case hex:
int hexi= Integer.parseInt(str,16);
break;
case dec:
str = str.substring(0,4);
break;
default: System.out.println("default");
}
}
}
}