Ugh. One day I will be good at this Java stuff! I swear it! When I pass in the variables obtained and print out c, the circle object, it is missing the last variable. It's supposed to have: 50 150 20, but it only has 50 150.

          int circX, circY, circSize;
          String circName, currentInput, line;
          InputStream is;
          BufferedReader br;

            ArrayList<Shape> shapes= new ArrayList<Shape>();            
            Picture<Shape> pics = new Picture<Shape>("Pics With Different Shapes");

is = new FileInputStream("C:\\Users\\Mint\\Documents\\NetBeansProjects\\LearnGraphics\\src\\learngraphics\\myHwk1InputTestFile.txt");
br = new BufferedReader(new InputStreamReader(is, Charset.forName("UTF-8")));
    try {
        while ((line = br.readLine()) != null) 
        {
            // Deal with the line
            System.out.println(line);
            if(line.startsWith("circle"))
            {
                String[] details = line.split(" ");
                 int inX = Integer.parseInt(details[1]);
                 int inY = Integer.parseInt(details[2]);
                 int size = Integer.parseInt(details[3]);          
                 Circle c = new Circle("circ", inX, inY, size);
                 pics.add(c);
                 System.out.println(c);
            }   
        }
        } catch (IOException ex) 
        {
        Logger.getLogger(TestCircle.class.getName()).log(Level.SEVERE, null, ex);
        }

// Done with the file
br.close();
br = null;
is = null;

When I tried to implement the switch version, simply just because I want to, it doesn't print out the variables x,y, or k. Not sure what's going on there. I can certainly just go with the previous code though.

          while (input.hasNext())
            {

                String line = input.nextLine();
                String[] array = new String[0];
                //String[] array = str.split(" ");
                 for ( int i = 0; i < array.length; i++)
                 {
                       System.out.println(array[i]);
                   switch (array[0])
                 {
                    case "circle":
                    System.out.println("It will be a circle");
                    String[] parts = line.split(" ");
                    int x = Integer.parseInt(parts[1]);
                    int y = Integer.parseInt(parts[2]);
                    int k  =Integer.parseInt(parts[3]);    
                    System.out.println("x =" + x + "y ="+y+"k="+k);
                    break;
                    default:
                     System.out.println("It's not working");
                        break;
                }
                 }

            }

I think I have done it:

String line;
is = new FileInputStream("C:\\Users\\Mint\\Documents\\NetBeansProjects\\LearnGraphics\\src\\learngraphics\\myHwk1InputTestFile.txt");
br = new BufferedReader(new InputStreamReader(is, Charset.forName("UTF-8")));
    try {
        while ((line = br.readLine()) != null) 
        {
            // Deal with the line
            System.out.println(line);
            if(line.startsWith("circle"))
            {
                String[] parts = line.split(" ");
                 int x = Integer.parseInt(parts[1]);
                 int y = Integer.parseInt(parts[2]);
                 int k  =Integer.parseInt(parts[3]);

            }   
        }
        } catch (IOException ex) 
        {
        Logger.getLogger(TestCircle.class.getName()).log(Level.SEVERE, null, ex);
        }

// Done with the file
br.close();
br = null;
is = null;

Of course, that only works for circle, but pipes and the other shapes in the line.startsWith() should do the trick, I think.

The draw tag will always be followed by picture details. How do I know to only pull the rest of the line that has draw in it though? Just trying to pull the correct info out of the file is the proverbial monkey wrench. I believe I just came to the realization that anything I don't want will be a default case. Interesting; so like, if the case were "circle" for example, take in the rest of the the line into a call to the circle drawing class/method. Then everything else will fit into the default until it gets to the draw line. It will default on "picture" and "A", take in the remainder of the line, and pass those into the method too. Would you perhaps know of a tutorial/documentation/tips that would be good to look at?

Thank you for the tips : ) Rather than using a scanner, would a bufferreader be appropriate to read in the lines? like so:

          BufferedReader in = new BufferedReader(new FileReader("C:\\Users\\Mint\\Documents\\NetBeansProjects\\LearnGraphics\\src\\learngraphics\\myHwk1InputTestFile.txt"));
            String line;
            try{
            while ((line = in.readLine()) != null)
            {

                line.split(" ");
                System.out.println(line);
            }
            in.close();
            }
            catch (Exception e)
            {
                System.err.println(e.getMessage());
            }

I have also come up with an alternative here:

          while (input.hasNext())
            {
                String str = input.nextLine();
                String[] array = str.split(" ");
                 for ( int i = 0; i < array.length; i++)
                 {
                       System.out.println(array[i]);
                 }

            } 

If I'm not mistaken, or at least in my head, wouldn't a series of if/else if statements be a lot of code? Hence the mention of the switch. I tried implementing the switch, but I'm not exactly where to insert the switch at. I was using str in the switch, which is the string I put everything into as it went into the array. I found I had to put my switch inside the while loop, but it didn't print anything except that it wasn't working(my default case). What I have so far for the switch:

                switch (str)
                 {
                    case "start": 
                    System.out.println("this is the start of the process!");
                    break;
                    case "picture":
                    System.out.println("we'll be taking variables to make a picture!");
                    break;
                    case "A":
                    System.out.println("Starting shape 'A'");
                    break;
                    case "circle":
                    System.out.println("It will be a circle");
                    break;
                default:
                 System.out.println("It's not working");
                    break;                       
                }

What I'm attempting to do is read a text document to pass in variables into an arraylist of shape objects that I will use to create shapes. I don't need any help with the actual drawing of the shapes, working with the arraylist, or the initial scanning setup. I thought about doing a while loop to read each word/int using the single whitespace in between as the delimiter. Where I get stuck is what exactly I should do with information I don't need. For example, I would test the line to see if it said start via an if statement. I don't need the word "picture", but I do need the character "A". It's also throwing me because I have only worked with formatted files before where each line had the same data in the same way.

I've watched a bunch of videos and looked into tutorials on parsing information in a text file, but I found they were working with a formatted file. I've worked with that before, and that makes sense to me. I feel like the right steps are to create a while loop that uses the .hasNext() to go through the file, and to use nested if statements to parse the lines. If someone wouldn't mind pointing me to a tutorial or documentation that would assist me in this, I'd be grateful. Perhaps a switch would work better to avoid a crazy amount of code, but maybe I'm thinking about this in a lame way. I ...

Haha, I figured it out. I guess I just needed to sleep on the subject.

Okay, I feel like I busted something in my head because I can't figure out anything in Java anymore! I just confused the crap out of myself, and I can't seem to get back on the horse. What I'm trying to do is read from a text file to create a picture. Each picture has shapes, and it makes them dance. I'm using the DrawingPanel class to help create the circle. My driver class reads commands to create the pictures from the text document; I had my shape working just fine, but I messed with it and confused myself all day. Now I can't undo all the different changes I've made : ( So yes, the driver reads info and will put into an arraylist I will make. Circle is the shape I am trying out, and it seems easy enough, yet I'm getting thrown somehow. Below is the class that confirms my circle flipping works, then my circle class, then my class I created to work the file. I'm not necessarily looking for you guys to come in and save the day with all the code; I'm certainly fine with ideas that point me in the right direction. Thank you for the help; I really do appreciate it.

import java.io.*;
import java.util.*;
import java.awt.*;
import learngraphics.Circle;
import learngraphics.DrawingPanel;
import learngraphics.Hwk1Useful;

public class TCircle {

public static void main ( String[] args) 
        {
        //Create the panel
        DrawingPanel panel = new DrawingPanel(600, 600);
        Graphics g = panel.getGraphics();

        //set the color
        g.setColor(Color.BLUE); ...

I want to have a running total in my net profit column. The formula is Amount paid - paypal fees - write fees. Can I do this with out using a query? Here is a screen shot of my table. [ATTACH]18861[/ATTACH]

First off, I know this is homework, and I don't expect anyone to do everything for me. Just a simple explanation is more than enough. The first project I am taking in a number in seconds that the user enters and converting it to hours, minutes, and seconds, but I get a scalar error. I get the expecting scalar type at line 38- if x >= 3600 and line 51 if x < 3600. Additionally, at line 45 - if ah < 60
I get illegal use of register; how would I put the remainder from ah and not get that error?
In the second project, I am not getting any errors or anything, but when I run the program, I get a bunch of random characters.
[CODE]COMMENT †
Part A) Takes in seconds from sdin and computes hours, minutes, and seconds from that

.MODEL SMALL
.STACK 100

CR EQU 13 ;symbolic constant
LF EQU 10 ;symbolic constant

.DATA
x db ?
hours db ?
minutes db ?
seconds db ?
prompt1 db 'Enter an amount in seconds in which to compute hours, minutes, and seconds from.', CR, LF, '$'
hlabel db 'Hours: ', CR, LF, '$'
mlabel db 'Minutes: ',CR, LF, '$'
slabel db 'Seconds: ', CR, LF, '$'

.CODE
Main PROC
lea dx, prompt1 ;prompt that gives instructions to user
mov ah, 9h
int 21h

mov ah, 01h ;get # from user from sdin
int 12h

mov x, ah ;put that # into x
Main ENDP

Worker ...

[QUOTE=Salem;1153568]> ;determine the size of binary value
In a loop, you

  • divide the number by 10
  • increment a count

When you reach zero, your count is how many digits the number needs to be printed.

IIRC, the div instruction stores the division result in one register, and the modulus result in another. You'll need that for step 2.[/QUOTE]

Ah cool, thank you very much.

I have been working on a project in Intel assembly until I hit a bump and I can't seem to get myself out of a hole. I realize that this is homework, and I don't expect anyone to do my work for me. However, a little help would definitely be nice. I think I will be able to figure out the last procedure if PrintNumber gets figured out. However, I don't understand what to do for these:
;determine the size of binary value
;set index to size
;move '$' to storage array offset index
;append ascii bits to remainder

Thanks for the help.

Pseudocode
Main procedure that will use three procedures to get any two integer values, find their greatest common divisor, and display the two integers and their GCD to display screen. It should allow the user to run the program for any number of pairs of integers until the user indicates that they do not have any more data to process.

GetNumber (ASCII to Binary) procedure

set character count to zero
get a character from the keyboard
while character is not the carriage return
store character in input array
increment character count
get a character from the keyboard
set multiplier to 1
set index to character count minus 1
loop character count times
get character at offset index
remove ASCII bits (using and mask)
multiply by multiplier
add to binary value
multiply the multiplier by 10
decrement the index

PrintNumber (Binary to ASCII) procedure

determine the size of ...

[B]EDIT:[/B] I am having issues with a for loop. 46-52. I took out the for loop work I had because it was giving me all kinds of errors.
[B]UPDATED CODE:[/B]
[CODE]COMMENT †
Douglas Martin
MCMPSC-241 2483
2/24/2010
This program was created by converting C++ code into assembly.

.MODEL SMALL
.STACK 100

CR EQU 13 ;symbolic constant
LF EQU 10 ;symbolic constant

.DATA
name1 db 'CMPSC 241 Class'
numbers dw 5 DUP (0)
ch1 db 'A', CR, LF, '$'
ch2 db 'Z', CR, LF, '$'
ch3 db ?
num1 dw 10
num2 dw 20
num3 dw ?
largest dw ?

.CODE
Main PROC

mov ax, @data
mov ds, ax ;set DS to point to the data segment

lea dx, name1
mov ah, 9h
int 21h

mov bx, num1
cmp bx, num2
jg else1 ; conditional jump
mov cx, largest
mov cx, num1
mov largest, cx

else1:
mov cx, num2
mov largest, cx

mov cx, 0
again:
mov si, num1 ;fixed duration loop
mov numbers[si], dx
mov dx, num2
inc dx
loop again

mov num1, 0
mov num2, 10
mov num3, 0 ;variable duration loop
mov cx, num1
cmp cx, num2
jle while1 ;conditional jump instruction

while1:
inc num3
inc num1

RET 0 ;normal program termination
Main ENDP
END Main ;end program[/CODE]

I have been working on converting this C/C++ Program as an assignment for my x86 assembly class, and for the love of anything good I can't figure out what is wrong. It doesn't have a problem when assembling or linking, but when I run it, it gives me: CS:0576 IP: Of19 OP:65 63 69 66 79. I would appreciate any and all help. Thank you very much for your time.

C/C++ Program:
[CODE]
int main ()
{
// DATA SEGMENT
char ch1 = 'A', ch2 = 'Z', ch3;
int num1 = 10, num2 = 20, num3, largest;
char name1[10] = "CMPSC 241 Class";
int numbers[5] = {0};
// CODE SEGMENT
cout << name1 << ‘\n’;
if ( num1 > num2 ) // Conditional Jump Instruction
largest = num1;
else
largest = num2;
for ( num1 = 0; num1 < 5; num1++ ) { // Fixed Duration Loop
numbers[num1] = num2 + 1;
num2--;
}
num1 = 0;
num2 = 10;
num3 = 0; // Variable Duration Loop
while ( num1 <= num2 ) { // Conditional Jump Instruction
num3++;
num1++;
} // Unconditional Jump Instruction
return 0; // Normal Program Termination
}[/CODE]
My assembly code:
[CODE]COMMENT †
Douglas Martin
MCMPSC-241 2483
2/24/2010
This program was created by converting C++ code into assembly.

.MODEL SMALL
.STACK 100

CR EQU 13 ;symbolic constant
LF EQU 10 ;symbolic constant

.DATA
name1 db 'CMPSC 241 Class'
numbers dw 5 DUP (0)
ch1 db 'A', CR, LF, '$'
ch2 db 'Z', CR, LF, '$' ...

Never mind. I got into a panic and gave up too soon. Sorry to bother you guys! After redoing some stuff and a little more reading, I fixed all of my issues.

I just started assembly programming, x86, and I am kind of getting the hang of it, but I am still far from becoming great at it. It's interesting to see what I do in Java from a different view. Anyways, for the life of me, I can't figure out what I am doing wrong. This is an assignment, and I don't expect to be handed my entire assignment, but I am running into all kinds of errors and would appreciate any help. I commented out a lot of it and am taking smaller steps. There is an example in the book that has some similarities in what I have done that's not commented out, but I was given an error. The book's example includes Irvinge32.inc, but I have no idea what that is. The thing is that "The NTVDM CPU has encountered an illegal instruction. CS:0594 IP:0037 OP:ff ff 75 03 e9" error. I have no idea why this is happening. Thank you for your time and effort.

[CODE]
.MODEL SMALL
.386p ;Needed for 32-bit instructions(movsx and movzx)
.STACK 512

word1 EQU 10000000b ;set word1 to -128 in binary

.DATA

;bytes db 10 DUP (0) ;using DUP, creates a ten zeroes in memory
dec_byte1 db 25d ;decimal byte, symbol is d or t
dec_byte2 db 2d ;decimal byte
dec_byte3 db 10d ;decimal byte
; bin_byte db 00011001b ;binary byte
; oct_byte db 031q ;octal byte, symbol is q or o
; hex_byte db 19h ;hexadecimal byte
; str1 db 'String' ...

I made a program that stores a collection of CDs. This collection is entered in a BinarySearchTree and contains the Artist, Album, favorite song, track numbers, and cost of cd. The inorder traversal works to print everything in the tree, and the cdPrintGroup method prints all the Artists(aka groups), but when I try and insert or delete, I get nothing. Inserting doesn't work, and when I do the delete method from the BinarySearchTree class, it states I can't delete an empty tree. How can that be if the inorderTraversal method works?

Thanks for your time.

Driver:
[CODE]import java.io.;
import java.util.
;

public class Lab9{

static Scanner console = new Scanner(System.in);

public static void main(String[] args){

    //call CDBinaryTree class
    CDBinaryTree cdList = new CDBinaryTree();
    BinarySearchTree bst = new BinarySearchTree();

    //declare variables
    int choice;
    String group;
    String newCD;
    try{

        Scanner inFile =
           new Scanner(new FileReader("c:\\CDDat.txt"));

        createCdList(inFile, cdList);

        displayMenu();
        System.out.print("Enter your choice: ");
        choice = console.nextInt();
        console.nextLine();
        System.out.println();

        while (choice != 9){

            switch (choice){

            case 1: System.out.print("Enter the CD information: ");
                    newCD = console.nextLine();
                    bst.insert(newCD);//something to insert an object
                    break;
            case 2: System.out.print("Enter the group to delete: ");
                    group = console.nextLine();
                    bst.search(group);//something to search to delete
                    bst.deleteNode(group);
                    //something to delete that object
                    System.out.println("Group deleted.");
                    break;
            case 3: cdList.cdPrintGroup();
                    break;
            case 4: cdList.inorderTraversal();
                    break;
            default: System.out.println("Please enter another number.");
            }//end switch

            //call method
            displayMenu();
            System.out.print("Enter your choice: ");
            //take in choice
            choice = console.nextInt();
            console.nextLine();
            System.out.println();

        }//end while
    }//end try
    catch (FileNotFoundException fnfe){

        System.out.println(fnfe.toString());
    }//end catch
    catch (IOException ioe){

        System.out.println(ioe.toString());
    }//end catch
}//end main method ...

[QUOTE=masijade;1073361]You don't have to.

Simply do readLine until it returns null as shown in the second example in the [url=http://java.sun.com/docs/books/tutorial/essential/io/charstreams.html]Tutorial[/url].[/QUOTE]

Thanks : D, I got it to work. Marked thread as [B]Solved[/B].

[QUOTE=masijade;1072324]Rather than Scanner use a BufferedReader, its readLine method, and String's split method.[/QUOTE]

But, In my MainProgVideoStore class, I use hasNext in my while loop. I am unsure of how to do that with bufferedreader. The rest of it, the split, and readLine isn't a problem.

I have been working on this for a bit, and I have made some great strides. However, there are just a few things bugging me that I can't seem to figure out. This is an assignment, and I don't expect anyone to toss out an entire program for me. However, help would be greatly appreciate it. If you stopped by and helped, thank you for checking the post out and helping. If not, thanks for checking out the post; maybe it helped you.

I am using a binary tree to sort through a file that has an artist, cd title, favorite track, number of tracks, and cd cost. A sample from the file is :
Cage the Elephant, Cage the Elephant, Aint No Rest for the Wicked, 11, 9.99,

  1. I used a comma delimiter to read in from my file into a binary tree.
    It works, but I had to put a comma at the end of the lines, which is not allowed.

what I mean is this:
it is supposed to be like this:
Cage the Elephant, Cage the Elephant, Aint No Rest for the Wicked, 11, 9.99

I changed it like this:
Cage the Elephant, Cage the Elephant, Aint No Rest for the Wicked, 11, 9.99,

  1. The output puts an extra space in front of the next set of outputs.

what I mean is this:

Artist: Cage the Elephant
CD Title: Cage the Elephant
Favourite Track: Aint No Rest for the Wicked
Numbers Of Tracks: 11 ...

O.K. I have stumbled upon another problem. I couldn't use the buffer reader to iterate. I have to read from a file that has a series of the expressions.

    • A B / C D
  • A + B / C D
    • A + B / C D E
    • A B - C D
      Since the buffer reader doesn't have an iterator, it can only do the first expression. I tried converting to buffer reader into a file reader, but it prints out the third in the series.
      Updated Code:
      [CODE] import java.io.;
      import java.util.
      ;

      public class lab8
      {
      public static String LEFT_DONE="LEFT_DONE";
      public static void main(String[] args)
      {

      String strPrefix="";
      String strPostfix="";

      //declare the operators stack
      Stack<String> operatorStack = new Stack<String>();

      //error handling try
      try
      {

      //File operations

      Scanner inFile = new Scanner(new FileReader("c:\Prefix.txt"));
      PrintWriter pw = new PrintWriter("c:\Postfix.txt");

      //read a line containing the prefix string from the file
      String strLine="";

      //Set up console for prefix expressions
      System.out.println("Set of Prefix expressions: ");
      //Set up file for prefix expressions
      pw.write("Set of Prefix expressions: " + System.getProperty("line.separator"));

      //While loop to build the prefix expressions and print to console
      while (inFile.hasNext())
      {
      if(strLine != null)
      strPrefix = strLine;
      strLine = inFile.nextLine();
      System.out.println("Prefix expression : " + strLine);
      pw.write("Prefix expression: " + strPrefix + System.getProperty("line.separator"));

      }

      //Set up organization of the console
      System.out.println();
      System.out.println("The Converted set of Postfix expressions: ");
      //Setup the organization of output file
      pw.write("" + System.getProperty("line.separator"));
      pw.write("The Converted set of Postfix expressions: " + System.getProperty("line.separator")); ...

Thank you both for your help! It was very helpful, and I tried not to use the code you gave me as it was a homework assignment. I modeled my version on yours though, so it is somewhat the same. However, I have to use both stacks and queues. Incidentally, I really don't care for the problem statement anymore. In the workplace, all it would need to be workable, which it is. Flagging this thread as solved.

I searched for this topic first, because it is pretty popular, but I didn't find much to help. What I was instructed to do was convert a prefix expression to a postfix expression. I have to use a stack and a queue, which is different than many other threads about this topic. Another thing that is different is that my expressions are purely variables(ie +*A B / C D). I made a little progress on my own, and I don't want everyone to solve it for me, but help would be extremely appreciated.
I am reading the expressions from a file. I also put the postfix operands in the queue, and the operators in the stack. I get stuck when it is time to use the information. This is what I planned to do next:
if an operator is followed by 2 items that are operands, pop them and then pop the operator, else push into stack.
However, I have no clue as to do that; even if I am going in the correct direction.

If you stopped by, thanks, if you helped, thanks, if not, thanks anyway.

What I have so far:
[CODE]import java.io.;
import java.util.
;
public class lab8
{

//Nodes
static String strToken;
static boolean expressionOk;

public static void main(String[] args)
        //throws FileNotFoundException
{
    //declare the operators stack
    StackClass<String> postfixStack =
                        new StackClass<String>(100);

    //declare the expression queue
    QueueClass<String> postfixQueue =
                        new QueueClass<String>(100);
    //Try for error handling
     try
        {
         //File operations
            Scanner inputStream = new
                      Scanner(new FileReader("c:\\Prefix.txt"));
            PrintWriter outfile ...

defaults as in in my switch statement?

Ok, before everyone gets mad at me for not looking around the board for these topics, I have, but they weren't my problem. My problem I am having is calling the Polynomial class. I know how to call classes in a different class, but this is a bit different. I also realize that this is a homework assignment, and I don't want anyone to do my assignment for me. This is just a step that I am confused about. In addition, I can't just call the Polynomial class because I need to add two polynomials, then in another case subtract, and the other math-type stuff.
Thank you for looking at my thread, if you helped, thanks a lot, if not, thank you for your time to look.

This is my driver class, which all it does so far is basically the menu system.
[CODE]//Driver
import java.io.;
import java.util.
;
public class Project6
{
private static Scanner console = new Scanner(System.in);
public static void main(String[] args)

{
    //3 instances of the class Polynomial
    Polynomial polyAdd = new Polynomial();
    Polynomial polySub = new Polynomial();
    Polynomial polyMul = new Polynomial();

    //Call to menu
    menu();
}
public static void menu()

{
    //Decalre Variable to record the user's number entered to navigate menu
    int choice;
    String polynomial1;
    String polynomial2;

    //Menu print
    System.out.println("1. Create a Polynomial from the keyboard.");
    System.out.println("2. Add two Polynomials and Display Result.");
    System.out.println("3. Subtract two Polynomials and Display Result.");
    System.out.println("4. Multiply two Polynomials and Display Result.");
    System.out.println("5. Terminate the program");
    System.out.println("");

    //Take in ...

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.
[CODE]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: ...
commented: One of the best first posts I've ever seen +12