KaptainCavy's Profile User Rating: -----

Reputation: 0 Apprentice
Group:
New Members
Active Posts:
13 (0.02 per day)
Joined:
25-June 12
Profile Views:
229
Last Active:
User is offline Sep 18 2012 09:51 AM
Currently:
Offline

Previous Fields

Country:
US
OS Preference:
Windows
Favorite Browser:
Chrome
Favorite Processor:
Intel
Favorite Gaming Platform:
PC
Your Car:
BMW
Dream Kudos:
0
Icon   KaptainCavy has not set their status

Posts I've Made

  1. In Topic: Stack as an array

    Posted 10 Sep 2012

    I am getting the following errors after making the changes sepp2k recommended:

    P2Cavallaro.java:43: error: a generic class may not extend java.lang.Throwable
    public class StackException extends RuntimeException {
    ^
    P2Cavallaro.java:54: error: non-static variable this cannot be referenced from a static context
    Stack<Character> openDelimiterStack = new Stack<Character>();
    ^
    P2Cavallaro.java:56: error: non-static variable expression cannot be referenced from a static context
    int characterCount = expression.length();
    ^
    P2Cavallaro.java:63: error: non-static variable expression cannot be referenced from a static context
    nextCharacter = expression.charAt(index);
    ^
    P2Cavallaro.java:74: error: incompatible types
    char openDelimiter = openDelimiterStack.pop();
    ^
    required: char
    found: void

    P2Cavallaro.java:84: error: cannot return a value from method whose result type is void
    return isBalanced;


    // program 
    public final class P2Cavallaro
    {
    
    	// stack and stack methods 	
    	final String expression = "({[]})";
    	
    	public class Stack<T>{
          private int top;
          private int[] storage;
     
          Stack(int capacity) {
                if (capacity <= 0)
                      throw new IllegalArgumentException(
                                 "Stack's capacity must be positive");
                storage = new int[capacity];
                top = -1;
          }
     
          void push(int value) {
                if (top == storage.length)
                      throw new StackException("Stack's underlying storage is overflow");
                top++;
                storage[top] = value;
          }
     
          int peek() {
                if (top == -1)
                      throw new StackException("Stack is empty");
                return storage[top];
          }
     
          void pop() {
                if (top == -1)
                      throw new StackException("Stack is empty");
                top--;
          }
     
          boolean isEmpty() {
                return (top == -1);
          }
     
          public class StackException extends RuntimeException {
                public StackException(String message) {
                      super(message);
                }
          }
    	}
    	
    	// main
    	public static void main(String[] args)
       {
    		
    	   Stack<Character> openDelimiterStack = new Stack<Character>();
             
          int characterCount = expression.length();
          boolean isBalanced = true;
          int index = 0;
          char nextCharacter = ' ';
             
          for (; isBalanced && (index < characterCount); index++)
          {
             nextCharacter = expression.charAt(index);
             switch (nextCharacter)
             {
                case '(': case '[': case '{':
                   openDelimiterStack.push(nextCharacter);
                   break;
                case ')': case ']': case '}':
                   if (openDelimiterStack.isEmpty())
                      isBalanced = false;
                   else
                   {
                      char openDelimiter = openDelimiterStack.pop();
                      isBalanced = isPaired(openDelimiter, nextCharacter);
                   }
                   break;
                default: break;
             } 
          }
             
          if (!openDelimiterStack.isEmpty())
             isBalanced = false;
          return isBalanced;
       }
             
       // Returns true if the given characters, open and close, form a pair
       // of parentheses, brackets, or braces.
       private static boolean isPaired(char open, char close)
       {
          return (open == '(' && close == ')') ||
                 (open == '[' && close == ']') ||
                 (open == '{' && close == '}');
       } 
    }
    
    
  2. In Topic: Computer Organization or Set Theory?

    Posted 2 Aug 2012

    View PostDarenR, on 02 August 2012 - 09:37 AM, said:

    Yeah I never heard of any of those classes or what they do. I went for BS in Software Engineering. So to sum up what your saying is that you are unsure as to how much work you can handle while taking college courses. Well talk to others who have taken the courses and ask them how much work is really involved and thus you will have your answer. Just remeber over taxing yourself never does anyoen any good.


    Exactly! Which is why I am in a bind right now.

    Set Theory -
    Propositional and predicate logic; mathematical induction. Logic and structure of sets as related to mathematical proof. Relations, and cardinality.

    Computer Organization -
    An overview of computer organization and design including Boolean algebra, combinational and sequential circuits, data
    representation, register transfer and microoperations, CPU organization, microprogrammed control, and machine language programming.

    Discrete Structures -
    Propositional and predicate logic, mathematical induction, and recursion. Sets, relations, functions. Graphs and trees. Boolean algebra and computer logic. Finite state machines and computability.

    Data Structures -
    Trees, graphs, and other forms of data structures and their implementations. Emphasizing abstract data types; static memory allocation vs. dynamic storage allocation; searching, hashing, and sorting methods; algorithm analysis.
  3. In Topic: framework inquiry

    Posted 18 Jul 2012

    Okay, well I solved that issue and currently have the following code:

    Now all I need to do is make sure that words are counted in case-insensitive fashion and that words that begin with a number are not counted.


    import java.io.*;
    import java.util.*;
    
    public class MyProgramP6 {
        public static void main(String[] args) throws IOException {
    
            Scanner s = null;
    		  int count =  0;
    
            try {
                s = new Scanner(new BufferedReader(new FileReader(args[0])));
    				s.useDelimiter("[ ,:.:?'\"()]");
    
                while (s.hasNext()) {
    					 count++;	
                    System.out.print(s.next());
                }
    					System.out.print(count);
            } finally {
                if (s != null) {
                    s.close();
                }
            }
        }
    }
    
  4. In Topic: framework inquiry

    Posted 18 Jul 2012

    alright well I followed this tutorial 'http://docs.oracle.com/javase/tutorial/essential/io/scanning.html'

    And when I ran my program I was given this run-time error.

    Exception in thread "main" java.util.regex.PatternSyntaxException: Unmatched closing ')' near index 5
     ,;.:?)"(
         ^
    	at java.util.regex.Pattern.error(Pattern.java:1924)
    	at java.util.regex.Pattern.compile(Pattern.java:1669)
    	at java.util.regex.Pattern.<init>(Pattern.java:1337)
    	at java.util.regex.Pattern.compile(Pattern.java:1022)
    	at java.util.Scanner$1.create(Scanner.java:411)
    	at java.util.Scanner$1.create(Scanner.java:409)
    	at sun.misc.LRUCache.forName(LRUCache.java:70)
    	at java.util.Scanner.useDelimiter(Scanner.java:1195)
    	at MyProgramP6.main(MyProgramP6.java:27) 
    
    
  5. In Topic: framework inquiry

    Posted 18 Jul 2012

    View PostRyano121, on 18 July 2012 - 08:01 AM, said:

    Look at some of the methods in the String class. (probably along the lines of .split and .toLowerCase).


    So, something like the following?

    import java.io.FileReader;
    import java.io.FileWriter;
    import java.io.IOException;
    import java.util.Scanner;
    
    public class MainClass {
      public static void main(String args[]) throws IOException {
    
        FileWriter fout = new FileWriter("test.txt");
        fout.write("2, 3.4,    5,6, 7.4, 9.1, 10.5, done");
        fout.close();
    
        FileReader fin = new FileReader("Test.txt");
        Scanner src = new Scanner(fin);
        // Set delimiters to space and comma.
        // ", *" tells Scanner to match a comma and zero or more spaces as
        // delimiters.
    
        src.useDelimiter(", *");
    
        // Read and sum numbers.
        while (src.hasNext()) {
          if (src.hasNextDouble()) {
            System.out.println(src.nextDouble());
          } else {
            break;
          }
        }
        fin.close();
      }
    }
    
    

My Information

Member Title:
New D.I.C Head
Age:
Age Unknown
Birthday:
Birthday Unknown
Gender:

Contact Information

E-mail:
Private

Friends

KaptainCavy hasn't added any friends yet.

Comments

KaptainCavy has no profile comments yet. Why not say hello?