I was going to make two classes and a few methods, maybe about 6, and in order to break it up into classes, I went with a driver and a worker class. Upon doing it it came up with errors when compiling, however, if I run it it will work fine. I get 15 errors in total:
.\converter.java:3: cannot find symbol
symbol : class Scanner
location: class converter
static Scanner console = new Scanner(System.in);
^
.\converter.java:3: cannot find symbol
symbol : class Scanner
location: class converter
static Scanner console = new Scanner(System.in);
^
.\converter.java:14: cannot find symbol
symbol : class Scanner
location: class converter
Scanner inFile = new Scanner(new FileReader(infile));
^
.\converter.java:14: cannot find symbol
symbol : class Scanner
location: class converter
Scanner inFile = new Scanner(new FileReader(infile));
^
.\converter.java:14: cannot find symbol
symbol : class FileReader
location: class converter
Scanner inFile = new Scanner(new FileReader(infile));
^
.\converter.java:15: cannot find symbol
symbol : class PrintWriter
location: class converter
PrintWriter outFile = new PrintWriter(outfile);
^
.\converter.java:15: cannot find symbol
symbol : class PrintWriter
location: class converter
PrintWriter outFile = new PrintWriter(outfile);
^
.\converter.java:25: cannot find symbol
symbol : class List
location: class converter
List<Integer> ls = new ArrayList<Integer>();
^
.\converter.java:25: cannot find symbol
symbol : class ArrayList
location: class converter
List<Integer> ls = new ArrayList<Integer>();
^
.\converter.java:32: cannot find symbol
symbol : variable Convert
location: class converter
switch(Convert.valueOf(str.substring(4,7)))
^
.\converter.java:34: cannot find symbol
symbol : variable bin
location: class converter
case bin:
^
.\converter.java:39: cannot find symbol
symbol : variable oct
location: class converter
case oct:
^
.\converter.java:44: cannot find symbol
symbol : variable hex
location: class converter
case hex:
^
.\converter.java:49: cannot find symbol
symbol : variable dec
location: class converter
case dec:
^
.\converter.java:71: cannot find symbol
symbol : variable Collections
location: class converter
Collections.sort(ls);
My driver method:
import java.io.*;
import java.util.*;
public class project2
{
public static void main(String[] args)
throws IOException {
converter convertObject = new converter();
convertObject.converting();
}
}
And my worker:
public class converter
{
static Scanner console = new Scanner(System.in);
public void converting()
{
//Declare variables
String str;
String infile;
String outfile;
//Get file locations
System.out.println("Enter location of the input file.");
System.out.println("An example of this is C:");
infile = console.next();
System.out.println("Enter location of the input file.");
outfile = console.next();
Scanner inFile = new Scanner(new FileReader(infile));
PrintWriter outFile = new PrintWriter(outfile);
//Create list
List<Integer> ls = new ArrayList<Integer>();
//Switch that will convert numbers
while (inFile.hasNext())
{
str = inFile.next();
switch(Convert.valueOf(str.substring(4,7)))
{
case bin:
int binary= Integer.parseInt(str.substring(0,4),2);
ls.add(binary);
break;
case oct:
int octal= Integer.parseInt(str.substring(0,4),8);
ls.add(octal);
break;
case hex:
int hexi= Integer.parseInt(str.substring(0,4),16);
ls.add(hexi);
break;
case dec:
int deci= Integer.parseInt(str.substring(0,4),10);
ls.add(deci);
break;
default: System.out.println("One of the numbers in the input file is incorrect. Ex. input 1010bin");
}
}
//Output unsorted
System.out.println("Unsorted");
System.out.println(ls);
//Output unsorted to file
outFile.println("Unsorted");
outFile.print(ls);
outFile.println("");
outFile.println("Sorted");
//Sort
Collections.sort(ls);
//Output sorted
System.out.println("Sorted");
System.out.println(ls);
//Output sorted to file
outFile.print(ls);
//Close files
inFile.close();
outFile.close();
}
}